How to Install WordPress with NGINX on Ubuntu 24.04
WordPress is a user-friendly web content management system (CMS) used to manage websites without requiring advanced coding skills or technical expertise. While NGINX is an efficient and secure open-source web server. If you want to manage your website using WordPress then it can easily be installed with NGINX on Ubuntu.
In this guide, I will go through the WordPress and NGINX configurations on the latest Ubuntu 24.04 Nobel Numbat server.
- Prerequisites
- Installing WordPress with NGINX on Ubuntu
- Step 1: Install NGINX
- Step 2: Install MySQL and Configure it for WordPress
- Step 3: Install PHP and Extensions
- Step 4: Install WordPress
- Step 5: Configure NGINX for WordPress
- Step 6: Access and Configure WordPress
- NGINX vs Apache for WordPress
Prerequisites
To install WordPress with NGINX on Ubuntu, you must have:
- Ubuntu Server
- User with sudo privileges
- SSL Certificate
- A fully qualified domain name
Note: In this guide, a sample domain name will be used.
Installing WordPress with NGINX on Ubuntu
To install and configure WordPress and NGINX on Ubuntu, go through the steps given below:
Step 1: Install NGINX
Begin with the installation of NGINX on Ubuntu.
sudo apt install nginx
On installation, the NGINX service automatically loads and starts.
systemctl status nginx.service
NGINX is successfully installed on Ubuntu.
Caution: Before installing NGINX on Ubuntu, ensure that Apache is not installed because installing Apache and NGINX side by side can cause port conflict. If Apache is installed then remove it completely from the server. It is advised to install a web server on a fresh installation of the server.
Step 2: Install MySQL and Configure it for WordPress
To effectively manage WordPress users, content, and other important settings, a database is necessary. To set up a WordPress database, we need a database management system. On Ubuntu, two options are available MySQL and MariaDB. For this guide, I am installing MySQL.
sudo apt install mysql-server
Login to the MySQL interactive session.
sudo mysql -u root
Now, you will be entered in the MySQL console.
Create a database, I am giving it wordpress_db name.
CREATE DATABASE wordpress_db;
To verify, use SHOW DATABASES command.
SHOW DATABASES;
Next, create a database user.
CREATE USER 'sam'@'localhost' IDENTIFIED BY 'password';
Here, sam is the username, you can give it any name. Also, replace the password with a strong password that you want to assign to the user.
Grant privileges to the user to access and modify the database.
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'sam'@'localhost';
Now, refresh the privileges for all users.
FLUSH PRIVILEGES;
And exit the MySQL console, by using the EXIT command.
EXIT;
Now, a database is created for the setup of WordPress on Ubuntu.
Step 3: Install PHP and Extensions
For WordPress, it is recommended to use the latest PHP. The latest PHP version at the time I am writing this guide is PHP 8.1.
Install the latest PHP and its extension.
sudo apt install -y php8.1 php8.1-cli php8.1-fpm php8.1-mysql
The PHP-FPM also known as FastCGI Process Manager handles PHP processes separately from servers, and efficiently manages current requests to enhance the overall website performance.
You need to know to verify the PHP-FPM version as it is required to be added in the NGINX server block file.
ls /var/run/php
From the output, it can be seen that the 8.1 version is installed.
Step 4: Install WordPress
Download the latest release of the WordPress archive.
wget https://wordpress.org/latest.zip
It will be downloaded in the current working directory; extract it.
sudo unzip latest.zip
It will create a folder wordpress in the current working directory.
Move the content of wordpress folder to the web server’s root directory.
sudo mv wordpress/* /var/www/html/
Provide the required permission to the www-data user and group.
sudo chown -R www-data:www-data /var/www/html/*
The www-data is a system user to handle web server requests.
Now, change the directory to /var/www/html.
cd /var/www/html/
Remove the two default NGINX html files, index.html, and index.nginx-debian.html.
sudo rm index.html index.nginx-debian.html
Now, rename the wp-config-sample.php file and save it with wp-config.php name in the same directory.
sudo mv wp-config-sample.php wp-config.php
Open the wp-config.php file and provide the database name, user, and password.
sudo nano wp-config.php
Save the file and exit the editor.
Step 5: Configure NGINX for WordPress
Open the default NGINX server block file to make WordPress accessible from the browser.
sudo nano /etc/nginx/sites-available/default
To initiate the process, start by clearing out any existing content within the file and insert the following text in its place.
server {
listen 80;
server_name your_domain.com www.your_domain.com;
root /var/www/html/;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Note the PHP-FPM version, it should be the same as we identified in Step 3.
Note: Ensure to replace your_domain.com and www.your_domain.com in the above NGINX server block file with an FQDN pointing to your IP. It is strongly advised to use SSL/TLS (Let’s Encrypt) for secure connections (HTTPS) and redirecting HTTP traffic to HTTPS.
Verify whether the above configuration settings are correct or not by testing the configuration.
sudo nginx -t
Remove the default symbolic link found in the sites-enabled directory using the rm command.
sudo rm /etc/nginx/sites-enabled/default
To access WordPress from the browser, create a symbolic link of the default server block from the sites-available to the sites-enabled directory using the ln command line utility.
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
To apply the above modifications, reload the server.
sudo systemctl reload nginx.service
The WordPress with NGINX is successfully configured on Ubuntu.
Step 6: Access and Configure WordPress
To access WordPress, launch the web browser, and use your domain name or IP address as a URL.
Note: To get the IP address use, ip a or ifconfig commands.
Select language, and proceed with the further settings by clicking on Continue. Fill in the necessary details in the provided fields, and once you have completed that, proceed by clicking on the Install WordPress button to initiate the installation process for WordPress on your website.
The next page will prompt you that WordPress has been installed.
Afterward, navigate to the Log In button on the same page in order to access your account.
Provide the credentials set in the previous step and click on Log In to access the WordPress dashboard.
NGINX vs Apache for WordPress
Apache and NGINX are two popular web servers both have their own advantages.
Apache
Apache is a more popular, compatible, and easy-to-configure web server. On the other hand, it creates multiple threads for multiple connections making it resource-intensive. However, it is less secure and vulnerable to DDoS attacks.
NGINX
NGINX is relatively newer and can seamlessly handle multiple connections on a single thread making it suitable for high-traffic websites. It is well-optimized when it comes to consuming resources and is more efficient as compared to Apache. Moreover, it is secure and protects the server from DDoS attacks.
It is advised to use NGIX for WordPress because it is efficient and more secure when compared to Apache.
Conclusion
WordPress is a widely used web Content Management System or CMS while NGINX is a modern and robust web server. Using WordPress with NGINX provides better performance and efficiency with faster page load times and scalability.
For installation of WordPress with NGINX on Ubuntu; MySQL, PHP, PHP-FPM, and PHP-MYSQL extensions are needed. After configuring WordPress and NGINX, WordPress will be accessible through localhost.










