,

How to install WordPress with Nginx on CentOS

wordpress site

Step-by-Step Guide: How to Install WordPress with Nginx on CentOS

WordPress is a popular content management system (CMS) that allows you to create and manage websites easily. When combined with Nginx, a high-performance web server, you can achieve excellent speed and scalability. In this guide, we’ll walk you through the step-by-step process of installing WordPress with Nginx on CentOS

Step 1: Update System Packages
Before starting the installation, it’s crucial to update your CentOS system packages to the latest versions. Open a terminal and run the following command:

sudo yum update

Step 2: Install Nginx
To begin, install Nginx using the following command:

sudo yum install nginx

After the installation is complete, start the Nginx service:

sudo systemctl start nginx

You can also enable Nginx to start automatically on system boot by executing:

sudo systemctl enable nginx

Step 3: Configure Firewall
If you have an active firewall on your CentOS system, you need to allow HTTP and HTTPS traffic for Nginx. Run the following commands to open the necessary ports:

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload

Step 4: Install MariaDB Database Server
WordPress requires a database server to store its data. Install MariaDB by executing the following command:

sudo yum install mariadb-server

Start the MariaDB service and enable it to start on system boot:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Step 5: Secure MariaDB Installation
Secure the MariaDB installation by running the following command:

sudo mysql_secure_installation

Follow the prompts to set the root password, remove anonymous users, disallow remote root login, and more.

Step 6: Create a Database and User for WordPress
Log in to the MariaDB shell by executing:

sudo mysql -u root -p

Enter your root password when prompted. Inside the MariaDB shell, create a new database and user for WordPress:

CREATE DATABASE wordpress;
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;

Replace ‘wordpressuser’ with your desired username and ‘password’ with a strong password.

Step 7: Install PHP and Required Extensions
WordPress relies on PHP for its backend operations. Install PHP and the necessary extensions with the following command:

sudo yum install php php-fpm php-mysqlnd php-common php-cli php-gd php-xml php-mbstring php-json

Start the PHP-FPM service:

sudo systemctl start php-fpm

To enable PHP-FPM on system boot, execute:

sudo systemctl enable php-fpm

Step 8: Configure Nginx for WordPress
Next, configure Nginx to serve WordPress. Create a new server block configuration file:

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

Paste the following configuration into the file:

server {
    listen 80;
    server_name your_domain_or_IP;

    root /var/www/html/wordpress;
    index index.php;

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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fast

cgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Replace “your_domain_or_IP” with your server’s domain name or IP address.

Save and close the file (Ctrl+O, Ctrl+X).

Step 9: Download and Configure WordPress
Download the latest version of WordPress by running the following commands:

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo cp -R wordpress/* /var/www/html/wordpress/

Step 10: Set Permissions and Ownership
Set the correct permissions and ownership for the WordPress files:

sudo chown -R nginx:nginx /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress

Step 11: Configure WordPress
Create the WordPress configuration file by making a copy of the sample configuration file:

sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

Open the configuration file in a text editor:

sudo nano /var/www/html/wordpress/wp-config.php

Edit the following lines to match your database details:

define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');

Save and close the file (Ctrl+O, Ctrl+X).

Step 12: Restart Services and Access WordPress
Restart Nginx and PHP-FPM services to apply the changes:

sudo systemctl restart nginx
sudo systemctl restart php-fpm

Finally, open a web browser and navigate to your server’s domain name or IP address. You should see the WordPress installation page. Follow the on-screen instructions to complete the installation.

Conclusion:

Congratulations! You have successfully installed WordPress with Nginx on your CentOS server. You can now create and manage your website using the powerful WordPress CMS. Enjoy exploring the various themes, plugins, and customization options available to build your online presence.

About Author

Pavlos Papadopoulos Avatar

Discover more from Gadget Rumours

Subscribe to get the latest posts to your email.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

Discover more from Gadget Rumours

Subscribe now to keep reading and get access to the full archive.

Continue reading