{"id":27497,"date":"2018-07-18T04:18:46","date_gmt":"2018-07-18T09:18:46","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=27497"},"modified":"2022-06-03T03:34:48","modified_gmt":"2022-06-03T08:34:48","slug":"how-to-configure-wordpress-to-use-a-remote-database","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-wordpress-to-use-a-remote-database\/","title":{"rendered":"How to Configure WordPress to use a Remote Database"},"content":{"rendered":"
<\/p>\n
WordPress is the most popular content management system (CMS) based on PHP and MySQL. When your WordPress CMS grows in traffic and you have outgrown your current server resources, a professional solution is to host your database on a separate database server. With this solution, you can optimize your database and your web server independently and both servers can grown on it’s own machine. In this tutorial we will guide you on how to configure WordPress to use a remote database, on a CentOS 7 based VPS.<\/a><\/p>\n <\/p>\n In order to run WordPress on your CentOS 7 VPS and configure it to use a remote database, we need the following requirements pre-installed:<\/p>\n WordPress requires the following:<\/p>\n Log in to each VPS via SSH as user root<\/p>\n Once you are logged, run the following command on both servers to make sure that all installed RPM packages are up to date<\/p>\n As mentioned in the requirements section of the tutorial, a LAMP stack (Apache, MySQL\/MariaDB and PHP) is required to run WordPress on the server. We will start with installing the Apache web server:<\/p>\n After the Apache installation is complete, start the web server and enable it to start upon server boot:<\/p>\n PHP 5.4 is installed on CentOS 7 by default.<\/p>\n In order to install and use PHP 7.2, we need to install EPEL and REMI\u00a0repositories:<\/p>\n Next, install PHP 7.2 along with the required PHP extensions:<\/p>\n And finally, complete the LAMP installation by installing MariaDB client package:<\/p>\n Start the service and set it to start on reboot<\/p>\n To accept remote connections, edit the MariaDB configuration file (\/etc\/my.cnf.d\/server.cnf) and change the following line:<\/p>\n with:<\/p>\n Do not forget to replace ‘web_server_IP_address’ with the public IP of the web server.<\/p>\n If you want to configure MariaDB to listen on all interfaces on the web VPS, set:<\/p>\n Restart MariaDB for the changes to take effect:<\/p>\n Log in to MariaDB console with the root user account:<\/p>\n Create a new MariaDB database for WordPress using the following query:<\/p>\n Create a new MariaDB user for WordPress using the following query:<\/p>\n Then execute the following query to add a separate user for WordPress that will interact with the MariaDB database:<\/p>\n Do not forget to replace database_VPS_IP with the actual IP address of the database VPS .<\/p>\n Execute the following command to apply the privileges we set:<\/p>\n Now we can exit the MariaDB session:<\/p>\n Edit the MariaDB configuration file (\/etc\/my.cnf.d\/server.cnf) and change the following line:<\/p>\n with:<\/p>\n Or, configure MariaDB to listen on all interfaces on the database VPS:<\/p>\n Restart MariaDB for the changes to take effect:<\/p>\n Download the latest WordPress version available at\u00a0https:\/\/wordpress.org\/download\/ and extract it in a directory on your server:<\/p>\n Set proper permissions on WordPress files and directories:<\/p>\n Rename wp-config-sample.php WordPress configuration file to wp-config.php:<\/p>\n Edit the wp-config.php file and modify the following lines<\/p>\n Now we will have to setup the Apache configuration so it can serve the WordPress directory. Add the contents below in the \/etc\/httpd\/conf.d\/wordpress.conf file using vi or your favorite editor:<\/p>\n Add the following lines:<\/p>\n <VirtualHost *:80> Alias \/matomo “\/var\/www\/html\/wordpress\/” <\/Directory><\/p>\n ErrorLog \/var\/log\/httpd\/wordpress-error_log Save the changes and restart Apache for the changes to take effect:<\/p>\n Open http:\/\/your-domain.com in your favorite web browser and finish the WordPress installation.<\/p>\n Congratulations. You have successfully configured WordPress to use a remote database on\u00a0a CentOS 7<\/a> server.<\/p>\n Of course you don\u2019t have to configure WordPress to use a remote database on CentOS 7, if you use one of our Managed CentOS VPS Hosting Solutions<\/a>, in which case you can simply ask our expert Linux admins to set up your WordPress to use a remotely hosted database for you. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n PS<\/strong><\/span>. If you liked this post on how to configure WordPress to use a remote database on a CentOS 7 server,\u00a0 please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":" WordPress is the most popular content management system (CMS) based on PHP and MySQL. When your WordPress CMS grows in … <\/p>\nRequirements<\/strong><\/h3>\n
\n
\n
Step 1: Log in via SSH on both servers:
\n<\/strong><\/h3>\nssh roo@IP_Address -p Port_number<\/pre>\n
Step 2: Update all packages<\/strong><\/h3>\n
yum -y update<\/pre>\n
Step 3: Install MariaDB server <\/strong>on the Database VPS<\/strong>
\n<\/strong><\/h3>\nyum -y mariadb mariadb-server<\/pre>\n
Step 4: Install LAMP stack on a Web VPS
\n<\/strong><\/h3>\nyum -y install httpd<\/pre>\n
systemctl enable httpd<\/pre>\n
yum install epel-release\r\n\r\nrpm -Uvh http:\/\/rpms.remirepo.net\/enterprise\/remi-release-7.rpm\r\n\r\nyum install yum-utils\r\n\r\nyum-config-manager --enable remi-php72\r\n\r\nyum update<\/pre>\n
yum -y install php php-cli php-mbstring php-gd php-mysqlnd php
-xmlrpc\u00a0php-xml\u00a0php-zip\u00a0php-curl<\/code><\/pre>\n
yum -y install mariadb mariadb-server<\/pre>\n
systemctl start mariadb\r\nsystemctl enable mariadb<\/pre>\n
bind-address = 127.0.0.1<\/pre>\n
bind-address = web_server_IP_address<\/pre>\n
bind-address =\u00a00.0.0.0<\/pre>\n
systemctl restart mariadb.service<\/pre>\n
Step 5: Create a MariaDB database for WordPress on the Database VPS<\/h3>\n
# mysql -u root -p<\/pre>\n
mysql> CREATE DATABASE wpdb;<\/pre>\n
mysql> CREATE USER 'wpuser'@'localhost';\r\nmysql> CREATE USER 'wpuser'@'database_VPS_IP';<\/pre>\n
mysql> GRANT ALL PRIVILEGES ON wpdb.* to 'wpuser'@'localhost' IDENTIFIED BY '5tr0ng_Pa55w0rd';\r\nmysql> GRANT ALL PRIVILEGES ON wpdb.* to 'wpuser'@'database_VPS_IP' IDENTIFIED BY '5tr0ng_Pa55w0rd';<\/pre>\n
mysql> FLUSH PRIVILEGES;<\/pre>\n
mysql> quit<\/pre>\n
Step 6: Configure the MariaDB server on database VPS to listen on public IP (or all interfaces)<\/h3>\n
bind-address = 127.0.0.1<\/pre>\n
bind-address = database_server_IP_address<\/pre>\n
bind-address =\u00a00.0.0.0<\/pre>\n
systemctl restart mariadb.service<\/pre>\n
Step 7: Install WordPress on the Web VPS
\n<\/strong><\/h3>\nwget\u00a0https:\/\/wordpress.org\/latest.zip\r\n\r\nunzip -d\u00a0\/var\/www\/html\/ latest.zip<\/pre>\n
chown apache:apache -R \/var\/www\/html\/wordpress\/<\/pre>\n
mv \/var\/www\/html\/wordpress\/wp-config-sample.php \/var\/www\/html\/wordpress\/wp-config.php<\/pre>\n
vi\u00a0\/var\/www\/html\/wordpress\/wp-config.php<\/pre>\n
\/** The name of the database for WordPress *\/\r\ndefine('DB_NAME', 'wpdb');\r\n\r\n\/** MySQL database username *\/\r\ndefine('DB_USER', 'wpuser');\r\n\r\n\/** MySQL database password *\/\r\ndefine('DB_PASSWORD', '5tr0ng_Pa55w0rd');\r\n\r\n\/** MySQL hostname *\/\r\ndefine('DB_HOST', 'database_VPS_IP');<\/pre>\n
Step 8: Configure Apache to serve WordPress<\/h3>\n
# vi \/etc\/httpd\/conf.d\/wordpress.conf<\/pre>\n
\nServerAdmin admin@your-domain.com
\nDocumentRoot \/var\/www\/html\/wordpress
\nServerName your-domain.com
\nServerAlias www.your-domain.com<\/p>\n
\n<Directory \/var\/www\/html\/wordpress\/>
\nOptions +FollowSymlinks
\nAllowOverride All<\/p>\n
\nCustomLog \/var\/log\/httpd\/wordpress-access_log common
\n<\/VirtualHost><\/p>\nsystemctl restart httpd<\/pre>\n
\n