Since WordPress is one of the most popular CMS platforms, many users are looking to set it up on different types of web servers – personal, business, or developers. Many people get lost when the process first starts and may not be familiar with all the options and requirements for setting it up initially, but do not worry! We’ve got you covered! In this article, we’ll walk through installing WordPress with Nginx on Ubuntu.
Everyone is used to installing their WordPress blog on a local server. But after moving your site off the local machine, you must now configure Nginx and WordPress together with some other installation/config steps.
How to install and Configure WordPress with Nginx?
This blog article is going to focus on how to install, configure, and secure WordPress with Nginx. It will cover everything you need to know about WordPress, Nginx, configuration files, and more.
What Is NGINX?
Nginx is a powerful Web server that can handle large files and streams of traffic. It also has a fast response time, making it an ideal choice for hosting WordPress.
NGINX is a Web server that was first released in 2004. As of March 2018, it was the most popular web server, according to W3Techs. Since then, it has become the standard for many web hosting services and is used on more than one-third of all servers.
NGINX is lightweight and efficient, making it a good choice for smaller businesses and organizations.
How many websites run on NGINX?
List of the World’s Most Popular Web Servers:
Apache – 38.7% of the top one million sites
Nginx – 32.1%
Cloudflare Server – 14.1%
Microsoft-IIS – 8.1%
LiteSpeed – 6.5%
Google Servers – 1.1%
NGINX has become one of the most popular Web servers on Earth. NGINX is also very popular in China, where it is used by more than half of all websites.
Nginx powers by such as Netflix, Pinterest, Airbnb, SoundCloud, Zappos, and WordPress.
“Over 130 million websites use NGINX at the front of their infrastructure, and of the 10,000 busiest websites in the world, more websites use NGINX than any other web server.”
– W3Techs Fact of the Day, 26 May 2014
Does WordPress use NGINX?
WordPress can be installed on an NGINX server.
Nginx is better because it can run PHP and because its structure is asynchronous, which keeps traffic from causing bottlenecks.
Installing WordPress on an Nginx server needs to be done in a certain way to make sure it works and is safe. First, administrators need a valid copy of the WordPress software and a domain name that is registered with the hosting company.
After these things are done, you can install WordPress on an Nginx server by following the instructions on the WordPress website.
Once WordPress is installed, it will start up on its own and use the asynchronous design that Nginx servers use.
Does WordPress use NGINX or Apache?
Both Apache and Nginx are highly popular web servers, used by millions of websites.
They both use different architectures, and while they are both supported by WordPress, Apache and Nginx servers aren’t the same.
Nginx also features a modular architecture, but its focus is on performance and flexibility. It uses more than 100 GB of memory per million requests, which makes it well-suited for high-traffic sites.
Apache is made up of separate parts called modules. These modules include the HTTP server, the file handler, and the dispatcher.
Each of these modules can be configured separately, giving you great flexibility when it comes to creating a Web server.
Which is better, Apache or Nginx?
Apache and Nginx are two of the most popular servers in use today. They’re both open-source, efficient, and reliable. So which one is better?
In this part, we will compare the two and present our findings. We will also provide a few tips on how to choose between Apache and Nginx based on your needs.
Different Architecture:
Apache servers have a forked, threaded architecture, which means that the same thread can handle more than one request at a time. This design improves response times and avoids the “per-request” contention that can slow down Apache servers when they’re overloaded.
Nginx uses an asynchronous structure that allows for more concurrent threads. This makes it better suited for high-traffic websites.
Memory Usability
Nginx is a lightweight and fast web server, while Apache is more powerful. NGINX typically uses less memory than Apache servers. Therefore, it may be a better choice for some websites.
.htaccess files
Apache servers support “.htaccess” files, but Nginx servers do not.
When you want to configure an Apache server, you can do so by creating one or more.htaccess files. In order to set up an Nginx server, you will need to directly update it through the use of a command prompt.
Permalinks
In WordPress, permalinks are the same thing as custom link slugs. When it comes to changing the link slugs of your website’s pages, you have the option of selecting from a number of different permalinks.
To create permalinks in WordPress using an Apache server, all you have to do is select the “Permalinks” option from the “Settings” menu.
If you have an Nginx server, you’ll have to do some extra work.
How to install and Configure WordPress with Nginx
Before we dive into the tutorial, have a quick recap at https://www.nginx.com/
Step 1: Install NGINX
NGINX is found in the repositories that are pre-installed with Ubuntu.
We strongly advise you to first update your Ubuntu to the latest version before proceeding.
Use apt-get commands:
- The first command updates the list of available packages and their versions, and
- The second install newer versions of your packages
# apt-get update
# apt-get upgrade
After upgrading, check your Ubuntu release version using the following command:
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
Now, putting a command on a single line is all it takes to install NGINX. This is shown below.
# apt-get install nginx
After it has been installed, NGINX will begin operating by itself automatically. The following systemc tl command will allow you to confirm that argument.
# systemctl status nginx
● nginx.service - A high-performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-10-12 01:11:08 UTC; 51s ago
Docs: man:nginx(8)
Process: 17726 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 17714 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 17729 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─17729 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─17732 nginx: worker process
Here you get,
the result of the previous operation demonstrates that NGINX has been loaded
and
It is currently operating with a process identifier of 17729.
Step 2: Install MariaDB
Using the terminal commands and run mysql_secure_installation
# apt-get install mariadb-server
# systemctl enable mariadb.service
# mysql_secure_installation
The default password for the root user of MariaDB is an empty string.
Get the MySQL prompt and then update the root password by issuing the following command from the MySQL shell.
This will cause the password to be updated for the root user.
$ mysql -u root -p
MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user SET PASSWORD=PASSWORD("Passw0rd!") WHERE USER='root';
### MariaDB is installed on Ubuntu 18.04.
Step 3: Install PHP
If you type the following command into the terminal, the Ubuntu 18.04 system will get the latest version of PHP.
# apt-get install php 8.1.11 php 8.1.11-cli php 8.1.11-fpm php 8.1.11-mysql php 8.1.11-json php 8.1.11-opcache php 8.1.11-mbstring php 8.1.11-xml php 8.1.11-gd php 8.1.11-curl
The apt-get command also installs a few other packages, such as MySQL, XML, Curl, and GD packages.
This makes sure that your WordPress site can talk to the database, works with XMLRPC, and can crop and resize images automatically.
Step 4: Create WordPress Database
Using the mysql -u root -p command and creating a user and a database for a WordPress installation.
$ mysql -u root -p
Enter password:
MariaDB [mysql]> CREATE DATABASE wordpress_db;
Query OK, 1 row affected (0.00 sec)
MariaDB [mysql]> GRANT ALL ON wordpress_db.* TO 'wpuser'@'localhost' IDENTIFIED BY 'Passw0rd!' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> exi
Step 5: Configure NGINX for WordPress
To configure NGINX for WordPress, first, create the root folder for your WordPress installation.
# mkdir -p /var/www/html/wordpress/public_html
Now create an NGINX server block for the WordPress domain.
Then navigate to the /etc/nginx/sites-available folder,
by this command:
# cd /etc/nginx/sites-available
# cat wordpress.conf
server {
listen 80;
root /var/www/html/wordpress/public_html;
index index.php index.html;
server_name SUBDOMAIN.DOMAIN.TLD;
access_log /var/log/nginx/SUBDOMAIN.access.log;
error_log /var/log/nginx/SUBDOMAIN.error.log;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
Using the following command, you can check to see if the above configuration file is correct:
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Create a symbolic link to the above configuration file in the /etc/nginx/sites-enabled folder to activate the server block. Then restart NGINX to apply the new WordPress domain settings.
# cd /etc/nginx/sites-enabled
# ln -s ../sites-available/wordpress.conf .
# systemctl reload nginx
Step 6: Download and Configure WordPress
Use the following commands in the terminal to get the compressed WordPress file and set it up.
# cd /var/www/html/wordpress/public_html
# wget https://wordpress.org/latest.tar.gz
# tar -zxvf latest.tar.gz
# mv wordpress/* .
# rm -rf wordpress
Change WordPress file ownership and permissions. Use this terminal command:
# cd /var/www/html/wordpress/public_html
# chown -R www-data:www-data *
# chmod -R 755
In order for WordPress to connect to the MariaDB database that we had previously built, we need to enter the database name, the database user, and the password in the configuration file for WordPress.
# cd /var/www/html/wordpress/public_html
# mv wp-config-sample.php wp-config.php
# vi wp-config.php
...
...
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'Passw0rd!');
...
...
We’ll use WordPress’ sample configuration file to develop our own. Rename the sample WordPress configuration file to wp-config.php and update it with your preferred editor.

After setting up the database, add the security key to the above WordPress config file to secure your site. link.
Step 7: Install WordPress
First, choose a language for WordPress Installation:

Now, enter the site’s details (name, username, password, and email address) and click the “Install WordPress” button.

The WordPress installation is complete. If you want to enter the Dashboard, just click the login button.

Related Article
WordPress Vulnerabilities: A Quick Guide For Website Owners How To Set My WordPress Site In Easy Maintenance Mode |
Conclusions
When setting up a WordPress website, it’s important to use a web server that can handle the processing load of the site. One of the most popular Web servers when it comes to WordPress is Nginx.
We will also go over some basic information about Nginx, such as its architecture, its key components, and the differences between Apache and Nginx. Finally, we will show you how to set up WordPress using Nginx and ensure that your website is running smoothly.
In this article, I will show you how to install Nginx on a server and configure it so that WordPress can work with it efficiently.
Once everything is set up, you’ll be able to access your site using any web browser without having to worry about performance or security issues. Thank you for reading!