+91 88 00 563434 sales@webhostingpeople.net Blog open-book Knowledge Base
Table of Contents
Print

How to Configure WordPress with External Database

WordPress, the content material administration system that doesn’t require any introduction. However right here is the very fact, There are 313,050 million websites constructed on WordPress. And it has a 59.7% of market share in content material administration. With WordPress, you may host information and database on completely different servers/machines in a short time because it makes use of MySQL as a database administration system. On this information, we are going to configure WordPress with an exterior database in Ubuntu 16.04 servers.

Initially, What can we imply after we say WordPress with exterior database? It implies that we’re going to host WordPress information on one server(Utility server). And we’re going to host our WordPress database on one other server(Database server).

Our aim is to execute MySQL queries on database-server and course of and show information on application-server. There are various benefits of internet hosting utility and a database on separate servers. Particularly in case your WordPress utility is rising at an inexpensive charge. Listed here are some advantages you get with this setup.

  1. Let’s say your application-server requires extra computing energy than your database-server. On this case, you may solely improve your application-server and hold your database-server the identical. This fashion, you may improve and downgrade servers primarily based on the computing energy they want.
  2. Within the case of downtime, you may shortly know if it’s a problem on a database server or an utility server. If you need excessive availability arrange on your database, Observe this information to create a master-slave replication in MySQL. With replication, you may hold your web site up and working even when the primary MySQL server is down.
  3. In case of monitoring, you may monitor the load and reminiscence on the appliance server. Whilst you can monitor queries per second, gradual queries, learn/write queries, and way more on the database server.

I simply have talked about three benefits right here, however there are lots of extra that you’ll expertise. So, Let’s get began with the tutorial.

Configure WordPress with exterior database

What is going to you want to observe this information? Effectively, you’ll need two Ubuntu 16.04 servers. Each the servers have to be clear with solely the working system put in. And a root entry to each the servers as we are going to set up packages and replace configuration information. Listed here are the IP addresses and hostnames we are going to use on this information.

  • Utility server: application-server (1.2.3.4)
  • Database server: database-server (4.5.6.7)

Initially, we are going to configure our utility server. It’s not going to be a typical LAMP server setup, as a result of we don’t have to configure MySQL on our utility server. So, let’s get began.

Configure Utility Server

On the appliance server, we are going to set up Apache to serve the HTTP requests and PHP to interpret PHP code requested by Apache. And we’re going to use the MySQL database hosted on the database server, so we don’t have to put in MySQL on this server.

Execute the next instructions on the appliance server.

root@application-server:~# apt-get replace
root@application-server:~# apt-get improve -y
root@application-server:~# apt-get set up apache2 -y
root@application-server:~# apt-get set up php7.Zero php7.0-curl php7.0-mysql php7.0-mbstring php7.0-dom php7.0-gd -y
root@application-server:~# apt-get set up libapache2-mod-php7.0
root@application-server:~# apt-get set up mysql-client -y

The primary 4 instructions will replace repositories, improve packages, set up Apache, and set up PHP7.Zero together with the PHP libraries required for WordPress. And the final one will set up MySQL shopper that we are able to use to check the distant reference to our database server.

To confirm if Apache and PHP are put in and configured accurately, execute the next instructions after which entry the general public IP deal with of the appliance server within the browser.

root@application-server:~# rm /var/www/html/index.html
root@application-server:~# echo “<?php phpinfo(); ?>” >> /var/www/html/index.php

On the browser, you must see a web page with PHP configuration info identical to the next picture.

PHPInfo page

For those who can see this web page on the general public IP deal with of your utility server, you have got efficiently configured the appliance server. Now, we are able to transfer on to the configuration of our database server.

Configure Database Server

Database server configuration can also be simple. It’s as a result of we have now to put in MySQL and replace the MySQL configuration file to permit distant entry. Execute the next command to put in MySQL in your database server.

root@database-server:~# apt-get replace
root@database-server:~# apt-get improve -y
root@database-server:~# apt-get set up mysql-server mysql-client -y
root@database-server:~# mysql_secure_installation

Whereas executing the third command, it’s important to enter the MySQL root password. And whereas working the fourth command, It’s important to reply just a few questions. Reply it like this.

  • Allow Validate Password Plugin? No
  • Change the password for root? No
  • Take away nameless customers? Sure
  • Disallow root login remotely? Sure
  • Take away take a look at database and entry to it? Sure
  • Reload privilege desk now? Sure

As soon as performed, attempt to log in to your MySQL server utilizing the next command.

root@database-server:~# mysql -uroot -p

For those who can log into your MySQL server, you have got efficiently put in MySQL on the server. Now, it’s time to replace the MySQL configuration file to permit distant connections. Execute the next command to open the MySQL configuration file in edit mode.

root@database-server:~# nano /and so on/mysql/mysql.conf.d/mysqld.cnf

Within the file, discover a line containing bind-address. It’s important to uncomment this line and change the default worth with the IP deal with of your database server. The up to date line ought to appear to be the next.

bind-address = 4.5.6.7

Don’t forget to switch the instance IP deal with with yours. As soon as performed, press CTRL+X adopted by Y adopted by Enter to avoid wasting the file. Now, restart the MySQL server utilizing the next command to use the brand new configuration.

root@database-server:~# service mysql restart

All of the onerous work is now over. Now, we are able to create a database for our WordPress utility on the database server.

Create Database for WordPress on Database Server

Initially, log in to your MySQL server utilizing the next command.

root@database-server:~# mysql -uroot -p;

Enter the password you have got set whereas putting in the MySQL server. As soon as you might be in, run the next queries in MySQL to create a database and a person having entry from our utility server.

mysql> CREATE DATABASE wordpress;
mysql> CREATE USER ‘wordpressUser‘@’1.2.3.4‘ IDENTIFIED BY ‘qawsedrf123‘;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressUser‘@’1.2.3.4‘;
mysql> FLUSH PRIVILEGES;

Now, if you wish to take a look at if the person and database are efficiently created, login to your utility server and execute the next command to log in to your MySQL server out of your utility server.

root@application-server:~# mysql -uwordpressUser -p -h4.5.6.7

It can ask you the password of the person we simply created on our database server. With the right password, you must have the ability to log in to your MySQL server. It’s a very essential step within the strategy of configuring WordPress with exterior database.

For those who can, Congratulations! The distant connections are working accurately, and you’ll go to the following step.

Obtain WordPress on the Utility server

On this step, we have now to obtain the WordPress information on our Utility server and set up the database connectivity in WordPress.

On the appliance server, execute the next instructions to obtain the WordPress information and set the permissions appropriate.

root@application-server:~# cd /var/www/html
root@application-server:/var/www/html# rm -rf *
root@application-server:/var/www/html# wget https://wordpress.org/newest.tar.gz
root@application-server:/var/www/html# tar -xzvf newest.tar.gz
root@application-server:/var/www/html# mv wordpress/* ./
root@application-server:/var/www/html# rm wordpress newest.tar.gz
root@application-server:/var/www/html# chown -R www-data:www-data /var/www/html

On this collection of instructions, the primary command will change the listing to /var/www/html and the second command will take away all of the information inside that listing. The third and fourth command will obtain and extract WordPress information within the listing. The fifth will transfer WordPress information from the wordpress listing to the present listing. The sixth command will take away the additional directories and information which might be now not required. The final command will set the right permissions on our /var/www/html listing the place our WordPress information are saved.

Set up WordPress from Browser

Lastly, the downloading a part of our WordPress set up course of is completed. So, we are able to now start WordPress set up from the browser. Open up a brand new browser tab or window and entry the general public IP deal with of your utility server.

NOTE: If in case you have already pointed the area identify to your utility server, open the area identify within the browser.

Because of every little thing we have now performed, you will see a language choice display screen in your Utility server’s public IP or area. Similar to the next picture.

WordPress installation - step 1

Choose the language and submit the shape. On the following step, you will see a database connectivity info card. Click on on the Let’s go button given on the cardboard. Within the third step, You will see a type to replenish the database info.

Enter the Database identify, username, password and the IP deal with of your database server within the type. For this instance, the right database configuration ought to appear to be the next picture.

WordPress with external database

Don’t forget to switch the database identify, username, password, and Database host (The IP deal with of your database server) within the type. As soon as the knowledge is entered accurately, press the Submit button to submit the shape.

If the database info isn’t appropriate, you will note a web page with an error message. Nonetheless, If the database info is appropriate, you will note a web page identical to the next picture.

WordPress installation - Part 3

For those who get an error message after submitting the database info, I like to recommend you to confirm the database connectivity utilizing the tactic I discussed within the earlier step. Nonetheless, for those who see a web page just like the above-given picture, click on on the Run the set up button to maneuver to the final step of WordPress set up. It ought to appear to be the next picture.

WordPress installation - Part 4

Lastly, After coming into all of the required info within the type, Click on on the Set up WordPress button to put in the WordPress web site.

 

Congratulations! You’ve got efficiently configured WordPress with the exterior database. With this setup, All of the HTTP requests and PHP interpretation shall be performed on our utility server. And all of the database queries shall be executed on our database server. It is extremely good and we have now achieved our aim. In case you are occupied with optimizing your new WordPress set up, I like to recommend you to configure WordPress Redis object cache.

You would possibly face some points with database connectivity if you’re doing it for the primary time. In case you are dealing with points with Database connectivity, Be sure that the database info is appropriate and no firewall rule is obstructing the requests approaching the database server. If the firewall is on, you may open the port 3306 to permit incoming connections on MySQL.

In case you are dealing with any concern following this information and wish some assist, please be at liberty to contact our assist employees.

Leave a Comment

Categories