WordPress on CentOS 7 (nginx, MariaDB, PHP, Redis)

Last Revised: October 2, 2021

This tutorial has been created on a Clouding.io VPS. You can create your own VPS from 3€/month.

In addition, you have the possibility to create your VPS with the WordPress image in one click.

PARTNERSHIP

Versions to install

Operating System: CentOS 7
Control Panel: None
Web server: nginx
Database: MariaDB 10.3
Processor: PHP 7.3
Cache: Redis

Here we leave you a small installation manual from a basic operating system installation of CentOS 7.

Configuring the Operating System

The first thing is to make a first update and configuration of the operating system base.

yum clean all && yum -y upgrade
yum -y install yum-utils curl vim unzip wget
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

Once the operating system is installed, the first thing we will configure will be the server time. In this case we will configure the time zone of Madrid.

timedatectl set-timezone 'Europe/Madrid'
yum -y install ntp
systemctl start ntpd
systemctl enable ntpd
systemctl status ntpd
ntpq -p

In order to take full advantage of the latest versions, we will use the EPEL alternate repository.

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum clean all && yum -y upgrade

Installing MariaDB

The next step will be the installation of the database. In this case we are going to use MariaDB 10.3. The first thing we will do is configure the download, and then its installation.

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash -s -- --mariadb-server-version=mariadb-10.3
yum clean all && yum -y upgrade
yum -y install MariaDB-server MariaDB-client

Now that it is installed, we will proceed to the initial configuration. For this we will use the secure installation system, which will ask us some questions.

mysql_secure_installation

To the question of whether we want to change the password, depending on whether or not we have put in the installation, we will change it. In case you have not put any, it is highly recommended to put a strong password.

Set root password? [Y/n]: Y

To the rest of the questions, we will answer the following:

Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

At this time we will have the database configured. Now we will make it run on the system restarts and start it.

systemctl stop mysql.service
systemctl enable mysql.service
systemctl start mysql.service

Installing nginx

At this moment we have the database configured and we will proceed to the installation of the web server. In this case we are going to use nginx. To be up to date, we will not use the version that comes with the operating system, but a more updated and maintained one.

yum clean all && yum -y upgrade
yum -y install nginx

Now that we have nginx installed, we are going to configure it to start at the system restarts automatically.

systemctl stop nginx.service
systemctl enable nginx.service
systemctl start nginx.service

Installing PHP

At this time we already have the web server, so we are going to install and configure PHP to work properly with the database and the web server. In this case we are going to install PHP version 7.3. First we will do the installation of the most updated packages (which are not those that come with the operating system) and that in case of needing it, in addition, they would allow us to have several versions of PHP in parallel.

yum-config-manager --enable remi-php73
yum clean all && yum -y upgrade
yum -y install php73-php php73-php-fpm php73-php-common php73-php-devel php73-php-cli php73-php-bcmath php73-php-pecl-crypto php73-php-gd php73-php-pecl-geoip php73-php-pecl-imagick php73-php-imap php73-php-json php73-php-mbstring php73-php-pecl-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-soap php73-php-sodium php73-php-pecl-ssh2 php73-php-pecl-xdebug php73-php-xml php73-php-xmlrpc php73-php-pecl-zip

Now that we have PHP correctly installed, let’s activate it so that when the system restarts it runs automatically.

systemctl stop php-fpm.service
systemctl enable php-fpm.service
systemctl start php-fpm.service
nginx -t
nginx -s reload

Installing Redis

To work with improvements in the performance of the object cache, we are going to leave Redis ready as a storage system.

yum clean all && yum -y upgrade
yum -y install redis php73-php-phpiredis

Later, and in the same way as the rest of the elements, we are going to configure it to start automatically if the server is restarted.

systemctl stop redis.service
systemctl enable redis.service
systemctl start redis.service

Configuring HTTPS

As we are going to mount our website on a secure web server (HTTPS), we will need to install the Let’s Encrypt certificate generator, so that we will previously prepare the systems for the creation of secure keys.

openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

And at this time we will install the certbot certificate creation system.

yum clean all && yum -y upgrade
yum -y install certbot-nginx

In order for the certificates to be updated automatically, we will activate a scheduled task (cron) once a day that automatically renews the certificates.

crontab -e

Once inside, we will configure, for example, that it runs at 06:45 every morning.

45 6 * * * certbot renew

From this moment we can restart the machine if we want, and we will have it ready to start its use and assemble the websites.


About this document

This document is regulated by the EUPL v1.2 license, published in WP SysAdmin and created by Javier Casares. Please, if you use this content in your website, your presentation or any material you distribute, remember to mention this site or its author, and having to put the material you create under EUPL license.