Hostingknowledge centerLinuxTutorialwordpressAugust 3, 20200How to Install WordPress with Nginx on Debian and Ubuntu in 20 steps

NGINX (pronounced engine-x) is an open-source powerful, light, and flexible HTTP server that has increased in popularity in last years and now is the main server interface that powers some of the most huge-traffic websites these days.

What makes it so fast and reliable is the fact that it uses the same modular design as Apache, but has a different approach regarding web sockets, using an event-driven – asynchronous architecture that does not spawn processes as fast as it receives requests and also uses simple configuration files.

For Ubuntu and Debian based systems, Nginx is already compiled as a package in their repositories and can be installed through apt package utility.

It also supports Virtual Hosts like Apache and uses a Fastcgi channel to communicate with PHP files on the server through PHP-FPM.

This tutorial covers installing and basic file configurations for Nginx to host a WordPress CMS website on a Virtual Host and setting applies to Ubuntu 18.04/20.04, Debian 10/9 and Linux Mint.

Installation of Nginx Web Server

Step1. Nginx installation for Ubuntu, Debian or Linux Mint is as straight as any other packages and can be installed with just a simple command.

$ sudo apt-get install nginx

Step2. Next, start, enable, and verify the status of Nginx use the following systemctl commands.

$ sudo systemctl start nginx
$ sudo systemctl enable nginx
$ sudo systemctl status nginx

Installation of PHP and MariaDB Server

$ 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

Step3. Next, verify that the MariaDB database service is running and enabled to automatically start when your system is booted.

$ sudo systemctl status mariadb
$ sudo systemctl is-enabled mariadb

Step4. In order to communicate with FastCGI backend, the PHP-FPM service must be active on the server.

$ sudo systemctl start php7.4-fpm
$ sudo systemctl enable php7.4-fpm
$ sudo systemctl status php7.4-fpm
Verify PHP-FPM Status in Ubuntu

Step5. Now you need to make your MariaDB installation secure by running the mysql_secure_installation script which ships with the MariaDB package.

$ sudo mysql_secure_installation

in this process , You will be asked to Set root PasswordRemove anonymous users , Disallow root login remotely , Remove test database , Reload privilege tables and need Enter ” Y ” to do them.

  • Enter current password for root (enter for none): Enter
  • Set a root password? [Y/n] y
  • Remove anonymous users? [Y/n] y
  • Disallow root login remotely? [Y/n] y
  • Remove test database and access to it? [Y/n] y
  • Reload privilege tables now? [Y/n] y


Secure MariaDB Installation

Installation of WordPress

Step6. A WordPress requires a database to store data on the server, so create a new WordPress database for your website using the mysql command as shown.

# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE mysite;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mysite.* TO 'mysiteadmin'@'localhost' IDENTIFIED BY  'SecureP@ssHere!';
MariaDB [(none)]> EXIT;

Step7. Now is time to create a WordPress Virtual Host root path, download the WordPress archive, extract it then issue a recursive copy to /var/www/html/wordpress.

$ sudo mkdir -p /var/www/html/
$ wget
$ tar xfvz latest.tar.gz
$ sudo cp -r wordpress/* /var/www/html/

Step8. For a smooth WordPress installation without any wp-config.php creation file errors, grant Nginx www-data system users with write permission over /var/www/html/ the path and revert changes after installing WordPress.

$ sudo chown -R www-data /var/www/html/
$ sudo chmod -R 755 /var/www/html/

Creating an NGINX Virtual Host for WordPress Website

Step9. Now is time to create a basic Virtual Host for WordPress website on the Nginx server. Run the following command to create a WordPress server configuration file.

$ sudo vim /etc/nginx/conf.d/

Then add the following content.

server {
        listen 80;
        listen [::]:80;
        root /var/www/html/; index index.php index.html index.htm; server_name; error_log /var/log/nginx/mysite.com_error.log; access_log /var/log/nginx/mysite.com_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; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }

Step10. By default, Nginx routes all requests to the default server block. Therefore, remove the default server block to enable your WordPress website or other websites you want to host on the same server later.

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

Step11. Next, check the NGINX configuration syntax for any errors before you can restart the Nginx service to apply the new changes.

$ sudo nginx -t
$ sudo systemctl restart nginx

Step12. After all Apache nasty server configurations had been made and MySQL database and the administrative user had been created it’s now time to actually perform WordPress installation on our box.

First of all download the latest WordPress archive by issuing the following wget command.

$ wget
Download WordPress in Ubuntu

Step13. Next extract WordPress archive and copy all extracted files to Apache Virtual Host DocumentRoot, that will be '/var/www/html' on Ubuntu and Linux Mint systems.

$ sudo tar xvzf latest.tar.gz
$ sudo cp -r wordpress/*  /var/www/html/

On Debian systems, run the following commands.

$ sudo tar xvzf latest.tar.gz
$ sudo mkdir -p  /var/www/html
$ sudo cp -r wordpress/*  /var/www/html/

Completing the WordPress Installation via the Web Installer

Step14. Now open your web browser and complete the WordPress installation using the web installer.

Step15. Then add the website information such as title, admin username, password, and email address. Then click Install WordPress to continue the installation.

Add WordPress Site Details

Step16. Once WordPress installation finishes, proceed to access the website administrator’s dashboard by clicking on the login button as highlighted in the following screen.

WordPress Installation Complete

Step17. At the website admin’s login page, provide your username and password created above and click login, to access your site’s admin dashboard.

WordPress Login

Step18. After installation completes undo permissions by issuing the following command.

$ sudo chown -R root /var/www/html/

Enable HTTPS on WordPress

Step19. If you want to enable HTTPS on your WordPress website, you need to install a free SSL certificate from Let’s Encrypt as shown.

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository universe
$ sudo apt-get update
$ sudo apt-get install certbot python3-certbot-nginx
$ sudo certbot --nginx

To confirm that your WordPress site is set up correctly using a Free SSL certificate, visit your website at and look for the lock icon in the URL bar. Alternatively, you can check your site’s HTTPS at

Congratulations! You have successfully installed the latest version of WordPress with NGINX on your server, now start building your new website or blog.

Step20. You are succeed , enjoy your new blog !


Leave a Reply