How to configure WordPress to use a remote database

How to configure WordPress to use a remote database

WordPress is the most popular content management system (CMS) based on PHP and MySQL. If your WordPress CMS is growing 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 web server independently, and both servers can grow on their own computer. In this tutorial, we will show you how to configure WordPress to use a remote database on CentOS 7 based VPS.

conditions

In order to run WordPress on your CentOS 7 VPS and configure it to use a remote database, we need the following pre-installed prerequisites:

  • A web VPS on which we will install the WordPress instance.
  • A database VPS with MariaDB or MySQL is installed on it. The database is hosted on this VPS.

WordPress requires the following:

  • Web servers: Apache, Nginx
  • PHP version 7.2 or newer, with JSON support, mbstring, zip and GD2 extensions.
  • MariaDB version 10.0 or higher or MySQL database server version 5.6 or higher

Step 1: Login to both servers via SSH:

Login to each VPS via SSH as the root user

ssh [E-Mail geschützt]_Adresse -p Portnummer

Step 2: Update all packages

Once logged in, run the following command on both servers to ensure all installed RPM packages are up to date

Yum -y aktualisieren

Step 3: Install MariaDB Server on the database VPS

yum -y mariadb mariadb-server

Step 4: Install the LAMP stack on a web VPS

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’ll start by installing the Apache web server:

yum -y installiere httpd

After the Apache installation is complete, start the web server and enable it on server startup:

systemctl aktivieren httpd

PHP 5.4 is installed by default on CentOS 7.

In order to install and use PHP 7.2, we need to install EPEL and REMI repositories:

yum install epel-release rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum install yum-utils yum-config-manager - aktivieren Sie das remi-php72-Update

Next, install PHP 7.2 along with the required PHP extensions:

yum -y install php php-cli php-mbstring php-gd php-mysqlnd php-xmlrpc php-xml php-zip php-curl

Finally, complete the LAMP installation by installing the MariaDB client package:

yum -y install mariadb mariadb-server

Start the service and set it to start on reboot

systemctl start mariab systemctl enable mariadb

To accept remote connections, edit the MariaDB configuration file (/etc/my.cnf.d/server.cnf) and change the following line:

Bindeadresse = 127.0.0.1

With:

Bind-Adresse = Web_Server_IP_Adresse

Don’t forget to replace ‘web_server_IP_address’ with the public IP of the web server.

If you want to configure MariaDB to listen on all interfaces in the web VPS, set the following:

Bindeadresse = 0.0.0.0

Restart MariaDB for the changes to take effect:

systemctl restart mariadb.service

Step 5: Create a MariaDB database for WordPress on the database VPS

Log in to the MariaDB console with the root user account:

# Mysql-u root-p

Create a new MariaDB database for WordPress with the following query:

mysql> CREATE DATABASE wpdb;

Create a new MariaDB user for WordPress with the following query:

mysql> CREATE USER 'wpuser' @ 'localhost'; mysql> CREATE USER 'wpuser' @ 'database_VPS_IP';

Then run the following query to add a separate user for WordPress that interacts with the MariaDB database:

mysql> GRANT ALL PRIVILEGES ON wpdb. * to 'wpuser' @ 'localhost' IDENTIFIED BY '5tr0ng_Pa55w0rd'; mysql> GRANT ALL PRIVILEGES ON wpdb. * to 'wpuser' @ 'database_VPS_IP' IDENTIFIED BY '5tr0ng_Pa55w0rd';

Don’t forget to replace database_VPS_IP with the actual IP address of the database VPS.

Run the following command to apply the permissions we set:

mysql> FLUSH PRIVILEGES;

Now we can end the MariaDB session:

mysql> beenden

Step 6: Configure MariaDB server to database VPS to be able to listen on public IP (or all interfaces).

Edit the MariaDB configuration file (/etc/my.cnf.d/server.cnf) and change the following line:

Bindeadresse = 127.0.0.1

With:

Bind-Adresse = Datenbank_Server_IP_Adresse

Or configure MariaDB to monitor all interfaces on the database VPS:

Bindeadresse = 0.0.0.0

Restart MariaDB for the changes to take effect:

systemctl restart mariadb.service

Step 7: Install WordPress on the Web VPS

Download the latest WordPress version from https://wordpress.org/download/ and extract it to a directory on your server:

wget https://wordpress.org/latest.zip unzip -d / var / www / html / latest.zip

Set the correct permissions on WordPress files and directories:

Chown Apache: Apache -R / var / www / html / wordpress /

Rename the wp-config-sample.php WordPress configuration file to wp-config.php:

mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

Edit the wp-config.php file and change the following lines

vi /var/www/html/wordpress/wp-config.php
/ ** Der Name der Datenbank für WordPress * / define ('DB_NAME', 'wpdb'); / ** MySQL-Datenbank-Benutzername * / define ('DB_USER', 'wpuser'); / ** MySQL-Datenbankkennwort * / define ('DB_PASSWORD', '5tr0ng_Pa55w0rd'); / ** MySQL-Hostname * / define ('DB_HOST', 'database_VPS_IP');

Step 8: Configure Apache for WordPress

Now we need to set up the Apache configuration so that it can serve the WordPress directory. Paste the following content into the /etc/httpd/conf.d/wordpress.conf file using vi or your favorite editor:

# vi /etc/httpd/conf.d/wordpress.conf

Add the following lines:

server admin [E-Mail geschützt]
DocumentRoot /var/www/html/wordpress
Server name your-domain.com
ServerAlias ​​www.your-domain.com

alias /matomo “/var/www/html/wordpress/”

Options + FollowSymlinks
AllowOverrideAll

Error log /var/log/httpd/wordpress-error_log
CustomLog / var / log / httpd / wordpress access log common

Save the changes and restart Apache for the changes to take effect:

systemctl Neustart httpd

Open http://your-domain.com in your preferred web browser and finish the WordPress installation.

Congratulations. You have successfully configured WordPress to host a remote database on a 7 CentOS server.

original item