Redhat 7 install wordpress with MySQL and nginx support


You’ll need to have minimum version of PHP installed in order to support wordpress app running, refer to this article about how to install PHP on your machine.

Install MySQL community edition on Redhat 7.

Install and configure nginx server on Redhat 7.

Configure and install wordpress

Once you have above software environment ready, you can start to install and configure wordpress.

Create database for wordpress on MySQL

# Log on to mysql with root user
mysql -u root -p
# Create database for wordpress, eg. wordpress
mysql> CREATE DATABASE wordpress;
# Create a wordpress database admin user and password
mysql> CREATE USER `admin`@`localhost` IDENTIFIED BY 'pass';
# Grant access to wordpress database admin user
mysql> GRANT ALL ON wordpress.* TO `admin`@`localhost`;
mysql> exit

Now you should have your database created, the next step to download and unzip your wordpress app under nginx server path. eg. /usr/share/nginx/html/

# Go to your nginx html folder
cd /usr/share/nginx/html
# Download wordpress latest version
# Create a directory named ''
# Unpackage wordpress to folder
tar xvf latest-en_CA.tar.gz

The next step is to update wordpress configuration file

# Create a copy of wordpress config file
cd your.weibsite
cp wp-config-sample.php  wp-config.php

Update wp-config.php file, add database information you created earlier.

# Update your database information, example as below
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'admin' );

/** MySQL database password */
define( 'DB_PASSWORD', 'pass' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

You’ll also need to update authentication unique keys and salts by visiting this URL, then copy the generated code and replace wp-config.php keys and salts placeholders.

Now you’ll need to update nginx.conf to let nginx control the installation process, refer to nginx official support

# Upstream to abstract backend connection(s) for php
upstream php {
        server unix:/tmp/php-cgi.socket;// This config may not work.

server {
        ## Your website name goes here.
        server_name domain.tld;
        ## Your only path reference.
        root /usr/share/nginx/html/;
        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi_params;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
                #The following parameter can be also included in fastcgi_params file
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;

Update php fpm config to give nginx control of wordpress files.

# Update php fpm config file
vi /etc/php-fpm.d/www.conf 
# Change user and group to nginx
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

Once have above file change complete, restart PHP fpm service

# Restart php fpm service
$ systemctl restart php-fpm.service
# Update folder permission for nginx if there's 403 error
$ sudo chcon -t httpd_sys_content_t ./your_website/ -R

# Grant read/write access to wp-content folder in order to install plugin, theme etc.
sudo chcon -t httpd_sys_rw_content_t ./your_website/wp-content/ -R

You should have all configuration ready, and next step is to follow wordpress installation process by visiting


Leave a Comment