How to Install WordPress on Nginx on CentOS 7 (LEMP)

Published: December 1, 2025 (Updated: Dec 1, 2025)

Enjoying this content? Subscribe to the Channel!

Mastering the LEMP Stack: Install WordPress on CentOS 7 with Nginx (Step-by-Step Guide)

Hey tech fans, Darren O’Neill here from Darren’s Tech Tutorials!

If you’re looking to host a fast, efficient website, the combination of CentOS 7 and Nginx (often called the LEMP stack: Linux, Nginx, MariaDB, PHP) is an absolute powerhouse. In this comprehensive guide, we’re going to walk through the entire process of installing the world’s most popular CMS, WordPress, right onto your CentOS 7 server.

We’ll cover everything from getting the necessary PHP modules configured to setting up your MariaDB database. Ready to build your high-performance site? Let’s dive in!


Prerequisites Check

To follow along with this tutorial smoothly, you must have the foundational components of the LEMP stack already installed and running. If you haven’t completed these steps, please ensure they are finished before proceeding:

  • CentOS 7 Installed and Updated
  • MariaDB Installed and Secured
  • Nginx Web Server Installed

Pro Tip: I provide a full text tutorial with copy-and-paste commands for this entire process on my website. We’ll use these commands throughout the guide.


Installing and Configuring PHP-FPM

WordPress requires PHP to function, and since we are using Nginx, we need the PHP FastCGI Process Manager (PHP-FPM). We will be installing PHP version 7.1 or higher for optimal performance.

Step 1: Add the Necessary Repositories

We need the Remi repository to access the latest stable PHP packages.

sudo wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo rpm -Uvh remi-release-7.rpm

Step 2: Install Repo Utility and Enable PHP 7.1

Next, we ensure we have the necessary utilities to manage our repositories and enable the specific PHP version we want (in this case, PHP 7.1).

sudo yum install yum-utils -y
sudo yum-config-manager --enable remi-php71

Step 3: Install PHP-FPM and Core Modules

Now we install PHP-FPM and the common PHP packages needed for WordPress functionality.

sudo yum install php-fpm php-cli -y

Finally, let’s install a robust set of standard modules commonly used by WordPress:

sudo yum install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel -y

Downloading and Preparing WordPress

With our PHP foundation ready, we can now download and place the WordPress files into the Nginx document root.

Step 1: Download WordPress

Navigate to a temporary directory and use wget to pull the latest WordPress compressed file from the official site.

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

Step 2: Extract and Move Files

We need to move the extracted contents to the standard Nginx document root (/usr/share/nginx/html).

# Extract the files
sudo tar -zxvf latest.tar.gz 

# Move the extracted wordpress folder to the Nginx root
sudo mv wordpress /usr/share/nginx/html/

# Change into the Nginx directory
cd /usr/share/nginx/html/

Step 3: Set Permissions and File Ownership

Since Nginx runs as its own user, we must ensure that the web server can read, write, and execute files within the WordPress directory. We will grant ownership to the nginx user and group.

# Change ownership recursively
sudo chown -R nginx:nginx /usr/share/nginx/html/wordpress

# Set standard directory permissions (755)
sudo chmod -R 755 /usr/share/nginx/html/wordpress

Step 4: Disable SELinux (Temporary)

For this installation to proceed without file access errors, we recommend temporarily setting SELinux to permissive mode. Note: For a production environment, you should properly configure SELinux policies instead of disabling it.

sudo setenforce 0

Need permanent changes? I have a dedicated tutorial on [How to Disable SELinux Permanently].


Configuring Nginx and PHP-FPM

The web server needs to know how to handle WordPress requests, and PHP-FPM needs to integrate seamlessly with Nginx.

Step 1: Configure Nginx Default Site

We need to create or modify the Nginx configuration file (default.conf) to correctly point to the WordPress installation and pass PHP files to the PHP-FPM service.

sudo vi /etc/nginx/conf.d/default.conf

Inside this file, you will place your site configuration. Remember to replace the sample IP address with your server’s actual IP.

server {
    listen       80;
    server_name  192.168.1.154; # REPLACE WITH YOUR SERVER IP ADDRESS
    root         /usr/share/nginx/html/wordpress;
    index        index.php index.html index.htm;

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

    error_page 404 /404.html;

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000; # Or use the socket path defined below
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Save and close the file (:wq).

Step 2: Configure PHP-FPM User and Listener

By default, PHP-FPM might run under the apache user. Since we are using Nginx, we must change this.

sudo vi /etc/php-fpm.d/www.conf

Find and modify the following lines:

Original Setting New Setting
user = apache user = nginx
group = apache group = nginx

Also, ensure the listener owner and group are set to nginx and that we are listening on a socket file (or IP, depending on your Nginx config above).

listen.owner = nginx
listen.group = nginx
listen = /var/run/php-fpm/php-fpm.sock

Note: If you configured Nginx to pass traffic to 127.0.0.1:9000 (as shown in the sample config above), ensure that the listen directive in www.conf is also set to 127.0.0.1:9000 instead of the socket path.

Step 3: Start and Enable Services

Restart both Nginx and PHP-FPM, and ensure they start automatically on boot.

sudo systemctl restart php-fpm
sudo systemctl enable php-fpm

sudo systemctl restart nginx
sudo systemctl enable nginx

Setting Up the MariaDB Database

WordPress needs a dedicated database and user to store all its content. Log into your MariaDB server to create these resources.

mysql -u root -p

(Enter your MariaDB root password)

Run the following SQL commands to create the database, the user, and grant that user full privileges to the new database. Be sure to choose a strong password!

-- 1. Create the database
CREATE DATABASE wordpress;

-- 2. Create the user and grant privileges
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress_user'@'localhost' IDENTIFIED BY 'your_secure_password';

-- Optional: Grant privileges for the specific IP address as well
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress_user'@'192.168.1.154' IDENTIFIED BY 'your_secure_password'; 

-- 3. Apply changes
FLUSH PRIVILEGES;

-- 4. Exit
EXIT;

Completing the WordPress Web Installation

With the database ready and the services running, navigate to your server’s IP address in your web browser.

http://[Your.Server.IP.Address]

You should be greeted by the WordPress setup screen!

  1. Select your Language and click Continue.
  2. Click Let’s Go.
  3. Enter your database details:
    • Database Name: wordpress
    • Username: wordpress_user
    • Password: your_secure_password
    • Database Host: localhost
    • Table Prefix: wp_ (Leave as default)
  4. Click Submit and then Run the Installation.
  5. On the final screen, choose a Site Title, a secure Admin Username, and a strong password.
  6. Click Install WordPress.

Congratulations! Once complete, log into your new WordPress dashboard and start building your site!


Summary and Next Steps

You have successfully installed the complete LEMP stack and deployed WordPress on your CentOS 7 server. This configuration is highly efficient and scalable, making it perfect for your next big project.

If you hit any snags during the installation, please drop a comment below—I’m always happy to help troubleshoot!

If you found this guide useful, hit that Like button, and for more clear, accessible tech tutorials, be sure to Subscribe to Darren’s Tech Tutorials!

Happy coding!