fbpx Install WordPress with Nginx, MariaDB and PHP on CentOS/RHEL | Certificação Linux

Install WordPress 5 with Nginx, MariaDB 10 and PHP 7 on CentOS

📅 03/08/2019 ⏱ 6 min ✍️ Uira Ribeiro
Linuxcommandshow-to
Install WordPress 5 with Nginx, MariaDB 10 and PHP 7 on CentOS
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

WordPress 5 was recently released with some fundamental changes, such as the Gutenberg editor, which is wonderful. In this article we will configure WordPress 5 with NGINX, MariaDB 10 and PHP 7 on CentOS

If you want to have a blog or even a website, WordPress is the ideal choice. And version 5 has improved a lot.

In this article we will cover the installation of WordPress 5 on a fresh CentOS Linux (with nothing installed).

As web server, we will install NGINX, which is an excellent web server, much lighter than Apache, ideal for virtual machines.

We will also install PHP 7, which is undoubtedly the best option for WordPress, since it can run 5x faster than its predecessor, PHP 5.

As database, we will install the Open Source fork of MySQL, which is MariaDB version 10, which is also very robust and powerful.

CentOS Update

The first step is to update CentOS to make sure you have the latest updates and patches:

sudo yum update

Installing Nginx Web Server

Now let's install Nginx, start the service and then enable it to start at system boot:

sudo yum install nginx
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

If you want to learn more about Nginx, we have a 3-hour course focused on making Nginx shine!

Configure Nginx for WordPress

Now let's configure Nginx to work with WordPress by creating the site configuration file. For that we will edit the file with vim. You can use another editor if you prefer.

sudo vim /etc/nginx/conf.d/wordpress.conf

Now paste the content below into the file:


server {
    listen 80;
    listen [::]:80;
    root /var/www/html/wordpress;
    index  index.php index.html index.htm;
    server_name _ meusite.com.br www.meusite.com.br;

    client_max_body_size 100M;

    location / {
        try_files $uri $uri/ /index.php?$args;        
    }

    location ~ .php$ {
    include fastcgi.conf;
    fastcgi_pass             unix:/run/php-fpm/www.sock;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Don't forget to replace meusite.com.br and www.meusite.com.br. If you want to learn more about DNS, we have a DNS Bind 9 course.

Now edit the /etc/nginx.conf file

sudo vi /etc/nginx/nginx.conf

And delete the lines below:

   server {

        listen       80 default_server;

        listen       [::]:80 default_server;

        server_name  _;

        root         /var/www/html/wordpress;

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

        location / {

        }

        error_page 404 /404.html;

            location = /40x.html {

        }

        error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        }

    }

sudo systemctl reload nginx

Install MariaDB

Now let's install MariaDB version 10. After the installation we will start the service and then set it to start at boot.

If you want to super tune your MySQL database, check out our MySQL tuning course.

sudo yum install mariadb-server mariadb-client
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Now, we recommend you run the MySQL secure installation script. Basically you will set a root password, disable anonymous access and remove the test database.

sudo mysql_secure_installation

Create the WordPress Database and Access User

Now let's access the database with the root password you defined in the previous step, create the database and also create the WordPress user.

sudo mysql -u root -p

Now, inside the MySQL shell, enter the following commands. Don't forget to replace the password:

The user will be: wp_user and the password you define.

CREATE DATABASE wordpress;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'troque_a_senha';
GRANT ALL ON wordpress.* TO 'wp_user'@'localhost' ;
FLUSH PRIVILEGES;
EXIT;

Install PHP 7

In some distributions PHP 7 may not be available in the default repository. For that, let's enable the PHP 7 repository:

wget https://mirror.webtatic.com/yum/el6/latest.rpm

sudo yum install latest.rpm

Now let's install PHP 7 on the server. Right after we will enable the service and also set it to start at system boot.

sudo yum install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysqlnd php-cli php-ldap php-zip php-curl php-opcache
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

You may need to change the PHP 7 package suffixes depending on your Red Hat. With the command below you can see what PHP package names are available:

sudo yum list php*

If you use an Amazon CentOS instance, you can use the command below to install php7:

sudo amazon-linux-extras install php7.3

sudo yum install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysqlnd php-cli php-ldap php-zip php-curl php-opcache

Finally, install WordPress 5

Now let's download the latest version of WordPress 5.

cd /tmp && wget http://wordpress.org/latest.tar.gz

sudo mkdir -p /var/www/html
sudo tar -xvzf latest.tar.gz -C /var/www/html
sudo chown apache: /var/www/html/wordpress/ -R
sudo service nginx reload

Configure WordPress for the first time

Now that WordPress is installed, it's time to configure the access. To do this, you must access the server through your preferred browser.

Enter your server address or its IP. If everything went right, you will see a screen like this:

Choose English and click forward to configure the database. Change the username to wp_user and enter the password you chose when creating the user wp_user.

Once that's done, the next step is to configure the Site Title and your user to log into WordPress.

Now it's time to log into your WordPress:

Voila. Your WordPress 5 with MariaDB 10, Nginx and PHP 7 is ready to use:

Learn much more about Linux in our online course. You can enroll here with a 7-day free trial. If you already have an account, you can access it here.

Liked it? Share :-)

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp