How to Install WordPress with NGINX on Ubuntu 20.04

Using WordPress, you can create, modify, publish, and manage a blog or a website with minimal coding knowledge. It is the most widely used free and open-source CMS. Popularity is due to its ease of use, a thousand free and customizable website templates, thousands of free and paid plugins to add advanced functionality, and its support for various media types.

In this guide, you will learn how to install WordPress CMS in Ubuntu 20.04 LTS with NGINX (webserver). Visit our guide on How to Install WordPress with OpenLiteSpeed on Ubuntu 20.04 [free forever].

Note: You must have sudo privileges if you want to install WordPress on your machine.

Step 1: Install Nginx

The Nginx package is included in Ubuntu’s default repositories. Using this command in the Terminal, you can install it:

$ sudo apt-get install nginx

Please enter the sudo password. If you are prompted with a y/n choice, choose Y. It will then install Nginx on the system.

***

Once the installation is finished, start the Nginx service as follows:

$ sudo systemctl start nginx

Also, enable the service at boot:

$ sudo systemctl enable nginx

Then to confirm if the service is fully functional, run this command:

$ sudo systemctl status nginx

If the service is functional, you will be seeing active (running) in the output.

***

Step 2: Install MariaDB and PHP

Now install MariaDB and PHP for WordPress to function. Execute the below command to do so:

$ sudo apt-get install php php-mysql php-fpm php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip mariadb-server mariadb-client

To continue, hit y when prompted with the y/n option. It will then begin installing the packages on the system.

When the installation is finished, start the MariaDB service:

$ sudo systemctl start mariadb

Also, enable the MariaDB service through this command:

$ sudo systemctl enable mariadb

Then to confirm if the service is fully functional, use this command:

$ sudo systemctl status mariadb

If the service is functional, you will be seeing active (running) in the output.

***

Now start the PHP-FPM service:

$ sudo systemctl start php7.4-fpm

Then enable the service at boot:

$ sudo systemctl enable php7.4-fpm

Then to confirm if the service is fully functional, use this command:

$ sudo systemctl status php7.4-fpm

If the service is functional, you will be seeing active (running) status.

***

Now to secure the MariaDB installation, execute this command:

$ sudo mysql_secure_installation

When prompted for the current root password, press Enter. If asked to set a root password, press y.

For all the later questions, hit y.

***

Step 3: Create Database for WordPress

For storing and managing data on the servers, WordPress uses the MySQL database. In this step, we will create a MySQL database and then a WordPress user.

First, log in to MySQL shell using this command:

$ sudo mysql -u root -p

Now from the MySQL shell, run the below command to create a database named “wordpressdb”:

$ CREATE DATABASE wordpressdb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Create a user named “wpusername” with the password “Password”:

$ CREATE USER 'wpressuser'@'localhost' IDENTIFIED BY 'tintin';

Now give the new user “wpusername” access to the database “wordpressdb”:

$ GRANT ALL ON wordpressdb.* TO 'wpressuser'@'localhost'

Now execute the below commands for the changes to take effect:

$ FLUSH PRIVILEGES;

Now exit the MySQL shell:

$ EXIT;

***

Step 4: Download and Install WordPress

In this step, we will download and install WordPress. Create a root directory for your WordPress installation before downloading WordPress. To do this, run the following command in Terminal:

$ cd /var/www/html/

Download WordPress using the below command:

$ wget http://wordpress.org/latest.tar.gz

Extract the downloaded WordPress package:

$ tar xfvz latest.tar.gz

Setting up the ownership and permissions of the file

Setting up the right ownership of files and folders will make sure that you do not encounter problems while installing or downloading new themes or plugins.

First, remove ownership from the WordPress directory.

$ sudo chown -R nobody:nogroup /var/www/html/wordpress

Then set 750 permissions to the directories and 640 to the files. You can do this with the following commands.

$ sudo find /var/www/html/wordpress/ -type d -exec chmod 750 {} \;
$ sudo find /var/www/html/wordpress/ -type f -exec chmod 640 {} \;

Step 5: Create NGINX Virtual Host for WordPress

Create an Nginx virtual host file for WordPress. Run the below command in Terminal to do this:

$ sudo nano /etc/nginx/conf.d/example.com.conf

Copy-paste the below content in the file:

server {

listen 80;

listen [::]:80;

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

server_name example.com.conf www.example.com.conf;

error_log /var/log/nginx/example.com.conf_error.log;

access_log /var/log/nginx/example.com.conf_access.log;

client_max_body_size 100M;

location / {

try_files $uri $uri/ /index.php?$args;

}

location ~ \.php$ {

include snippets/fastcgi-php.conf;

 fastcgi_pass unix:/run/php/php7.4-fpm.sock;

}

}

Save and close the file.

Then remove the default Nginx server blocks using the command below in the Terminal:

$ sudo rm /etc/nginx/sites-enabled/default

Now check for any errors in the Nginx configuration file using the command below in the Terminal:

$ sudo nginx -t

The output below shows configuration is okay.

***

Now restart the Nginx server to apply changes.

$ sudo systemctl restart nginx

Step 6: Launch the WordPress Web Installer

In order to complete the WordPress installation, open your web browser and navigate to the server’s IP address.

http://ip-address

By doing so, the following installation wizard will appear. Choose the preferred language and then hit Continue.

***

***

***

Conclusion

It is as simple as that! You have learned how to install WordPress with Nginx on Ubuntu in this guide. Learn how to use WordPress by visiting the official documentation.

Leave a Comment