Full Download

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

Tutorials

Hosting

VPS

Email

Domain

Log In
WordPress
VPS
Website Development
eCommerce
Website Errors
How to Make a Website
search
BF-Content-300x427_VPS-Hosting-3.png
VPS
Dec 01, 2023

Edward S.

5min Read

WordPress Nginx: Everything You Need to Know About Installing WordPress on Ubuntu
Nginx is an open-source web server that was first released in 2004 and is written
completely in the C programming language. It has many benefits that you’ll discover
right here! In this tutorial, we’ll show you how to install WordPress with Nginx!

Download all in one WordPress cheat sheet

Why Use Nginx With WordPress


Prerequisites for Installing WordPress With Nginx
How to Install WordPress with Nginx
1. Update Your System
2. Install Nginx
3. Configure UFW (Optional)
4. Install and Configure MySQL Database
5. Install PHP
6. Install WordPress with Nginx
7. Configure Nginx for WordPress
8. Configuring WordPress for Nginx
Why Use Nginx With WordPress
Nginx has gained immense popularity in the recent past and is commonly sought as an
alternative to the Apache web server. Nginx supports reverse proxy, caching, media
streaming, load balancing, and much more. That makes it a great fit for a WordPress
website powered by a VPS solution.

Few of Nginx’s inbuilt features are:

Nginx is built to work on low memory usage


It can support extremely high concurrency
Is Ipv6 enabled
Supports reverse proxy with efficient caching
Provides an inbuilt load balancer
Supports WebSockets
Optimized handling of index files, static files and provides auto indexing
Is accompanied with FastCGI for efficient caching
Nginx does much more than a conventional web server, which is one of the reasons it
has gained so much popularity. Nginx overshadows a lot of legacy web servers and
consistently provides benchmarks surpassing their performance.

Nginx solves a lot of scalability issues and is taken as a solution to the commonly
referred C10K problem related to concurrency.

And as you now know, Nginx and WordPress work really well together!

Here, we will walk you through the installation of WordPress using Nginx on the
Linux platform.

Similar to LAMP, using Nginx is referred to as LEMP which stands for Linux, Nginx,
MySQL/MariaDB, and PHP.

Prerequisites for Installing WordPress With Nginx


You are logged with sudo access
Nginx is preinstalled
You have an SSL certificate installed for your domain
You own a domain name pointing to your server’s public IP. In this example it’ll be
kibenevents.com
How to Install WordPress with Nginx
Let’s walk through the entire process:

1. Update Your System


Update the package index using:

sudo apt update


Update system packages to the latest version using:

sudo apt upgrade


2. Install Nginx
Nginx packages are available in the default Ubuntu repository. You can use the
below command to install them:

sudo apt install nginx


This will take a while to install. Once the installation is complete, the Nginx
service will start automatically. To know the status of the service, use the below
command:

sudo systemctl status nginx


3. Configure UFW (Optional)
If you are using UFW (Uncomplicated Firewall) to manage your VPS firewall then you
will have to open ports 80 and 443 for HTTP and HTTPS respectively. You can enable
the Nginx full profile which contains rules for both ports. This can be done using:

sudo ufw allow 'Nginx Full'


To verify the status, you can use:

sudo ufw status


4. Install and Configure MySQL Database
To store data we will be using MySQL. In case you do not have MySQL installed, then
you can get it by using:

sudo apt install mysql-server


Once this is complete, the MySQL Database will be started automatically. You can
use the below command to check its status:
sudo systemctl status mysql
Next, you can log in to the MySQL shell by using:

mysql -u root -p
This will switch over to the MySQL console, which you can tell by the mysql> at the
start of the line. Here you can create a database and a database user with the
names WordPress and WordPressUser respectively.

CREATE DATABASE WordPress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;


GRANT ALL ON WordPress.* TO WordPressUser @'localhost' IDENTIFIED BY 'your
password';
FLUSH PRIVILEGES;
EXIT;
This creates a basic database configuration that can be used for the WordPress
setup.

5. Install PHP
You can install all the required PHP extensions directly with a single command
since these are the only ones that WordPress will use. This can be done using:

sudo apt install php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache


php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl
On completion of this installation, PHP-FPM will start automatically. This is a
Fast CGI process manager which enables caching.

6. Install WordPress with Nginx


To Install WordPress with Nginx, first create a directory to download the WordPress
archive:

sudo mkdir -p /var/www/html/kibenevents.com


From the official WordPress website, you can download the latest WordPress
installs. Download it to the /tmp directory. You can access said directory by using
cd, and download the archive using wget:

cd /tmp
wget https://wordpress.org/latest.tar.gz
Next, you can extract this archive to the directory created earlier. This can be
done using:

tar xf latest.tar.gz
sudo mv /tmp/wordpress/* /var/www/html/kibenevents.com/
The web server will require complete access to these files. Change the permission
using:

sudo chown -R www-data: /var/www/html/kibenevents.com


Note that Nginx and PHP run as the www-data user and group, hence this is used in
the above command.

7. Configure Nginx for WordPress


To configure Nginx for WordPress, we have to create a new server block for our
WordPress installation. Navigate to /etc/nginx/sites-available. There, create a
file with the name kibenevents.com. The name should be the same as your domain.

Add this code to the newly created file:

# Redirect HTTP -> HTTPS


server {
listen 80;
server_name www.kibenevents.com kibenevents.com;
include snippets/letsencrypt.conf;
return 301 https://kibenevents.com$request_uri;
}

# Redirect WWW -> NON-WWW


server {
listen 443 ssl http2;
server_name www.kibenevents.com;

ssl_certificate /etc/letsencrypt/live/kibenevents.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/kibenevents.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/kibenevents.com/chain.pem;
include snippets/ssl.conf;

return 301 https://kibenevents.com$request_uri;


}

server {
listen 443 ssl http2;
server_name kibenevents.com;

root /var/www/html/kibenevents.com;
index index.php;

# SSL parameters
ssl_certificate /etc/letsencrypt/live/kibenevents.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/kibenevents.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/kibenevents.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;

# log files
access_log /var/log/nginx/kibenevents.com.access.log;
error_log /var/log/nginx/kibenevents.com.error.log;

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

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

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

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

You might also like