Ubuntu 20.04: WordPress with Nginx installation

WordPress is an extremely popular content management system (CMS) for websites. Its popularity and ubiquity really cannot be overstated, as it powers a staggering 35% of websites. It’s an easy way to get a website online, and it offers a lot in the way of customization.

Ubuntu 20.04 Focal Fossa and Nginx are the perfect combination to run your WordPress site. Using these utilities will give you a very powerful, efficient, and stable website. Best of all, all this software is completely free and the setup isn’t very difficult. Follow along with our steps below to see how to get your WordPress site up and running on Ubuntu 20.04 with Nginx.

If you’re more familiar with or happen to prefer Apache over Nginx, we’ve written a separate guide for Ubuntu 20.04 WordPress installation on Apache.

In this tutorial you will learn:

  • How to install and configure Nginx
  • How to install and configure MariaDB for MySQL
  • How to setup a MySQL database for WordPress
  • How to download and install WordPress
  • How to configure SSL for your WordPress site

Running a WordPress website on Ubuntu 20.04 with Nginx

Running a WordPress website on Ubuntu 20.04 with Nginx
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa
Software WordPress, Nginx, PHP, MariaDB (MySQL)
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Install Nginx, PHP, and MySQL

Before installing WordPress, our Ubuntu 20.04 system will need three main components to run it: Nginx, PHP, and MySQL. Nginx is for our web server, PHP is to display dynamic content, and MariaDB (an open source fork of MySQL) is for our database. You can install these packages by opening a terminal and typing the following two commands:

$ sudo apt update
$ sudo apt install nginx mariadb-server mariadb-client php-fpm php-mysql

Configure MySQL

MySQL requires a little bit of setting up before we can start creating a database. Let’s first run through the initial security setup. Type the following command in terminal:

$ sudo mysql_secure_installation

You’ll be asked to set a root password for MySQL, and then a few security question. You can answer y (yes) to all the questions, and then setup will complete.

Going through the MySQL security setup

Going through the MySQL security setup

We cover more in depth MySQL configuration in our MySQL installation on Ubuntu 20.04 article, though the configuration above is really all you’ll need to do.

Create a database for WordPress

Your WordPress site will need one database to store all the user information, post content, etc. Follow these steps to get your database and MySQL user ready:

  1. Start MySQL as the root user:
    $ sudo mysql
  2. Create a new database for WordPress:
    MariaDB [(none)]> CREATE DATABASE wordpress_db;
  3. Next, create a new database user for WordPress. The my_password text below should be replaced with your desired (secure) password:
    MariaDB [(none)]> CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'my_password';
  4. Now, we need to give our WordPress user full permissions on the WordPress database:
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress_db.* to wordpress_user@'localhost';
  5. Finally, save the changes we’ve made to user permissions and exit the database:
    MariaDB [(none)]> FLUSH PRIVILEGES;
    MariaDB [(none)]> exit
    Creating the new database and user for WordPress in MySQL

    Creating the new database and user for WordPress in MySQL

Configure Nginx

Before we can download WordPress, we’ll need to properly configure Nginx to host our website. We’re going to call our website “wordpress” within all of Nginx’s configuration, but you can choose another name if you’d like.

First, create a configuration file under the /etc/nginx/sites-available directory using nano or your favorite text editor:

$ sudo nano /etc/nginx/sites-available/wordpress

You can paste the following content into your newly created file, which is a pretty standard Nginx configuration.

server {
        listen 80;
        listen [::]:80;

        root /var/www/wordpress;

        index index.php;


        location / {
                try_files $uri $uri/ =404;

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

There are a few lines in here that you may need to change. Line 9 should contain your domain name in place of, unless you don’t have a domain name. Line 17 should be updated with the version number of your installed PHP. To check your PHP version, execute the php --version command in terminal.

Nginx configuration file for our WordPress site

Nginx configuration file for our WordPress site

Once your configuration edits are made, you can save your changes to this file and close it. The last steps in the Nginx setup are to delete the default site, enable your website, and restart Nginx to make the changes take effect:

$ sudo rm /etc/nginx/sites-enabled/default
$ sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
$ sudo systemctl restart nginx

Download and install WordPress

Now that all of the prerequisites have been satisfied, we can finally move on to installing WordPress itself.

  1. First, download the latest version of WordPress using wget:
    $ wget -O /tmp/wordpress.tar.gz https://wordpress.org/latest.tar.gz

  2. Unzip the downloaded WordPress archive into the site directory:
    $ sudo tar -xzvf /tmp/wordpress.tar.gz -C /var/www
  3. Change the ownership of the site directory:
    $ sudo chown -R www-data.www-data /var/www/wordpress
  4. Open your internet browser and navigate to or your fully qualified domain name. You’ll be greeted by the WordPress setup wizard. Click the “Let’s go” button to get started with the configuration.
    WordPress setup page

    WordPress setup page
  5. The next screen asks us for information about our database configuration. Enter the values you set earlier, and then click “Submit.” The last two boxes (database host and table prefix) can be left at their default values.
    Enter the MySQL database information for WordPress

    Enter the MySQL database information for WordPress
  6. WordPress should give confirmation that it’s able to communicate with the MySQL database. Click “Run the installation” to begin installing WordPress.
    WordPress confirms that it can connect to the MySQL database

    WordPress confirms that it can connect to the MySQL database
  7. Now you’ll be required to fill out some general information about your new website: its name, admin username, password, etc. Fill this out and then click “install WordPress” at the bottom.
    Enter information about your new WordPress site

    Enter information about your new WordPress site
  8. Installation should be complete and you can login to your new website to start creating content!
    WordPress installation has completed successfully

    WordPress installation has completed successfully

You can always access the admin panel of WordPress by navigating to (or replacing with your fully qualified domain name).

WordPress admin dashboard

WordPress admin dashboard

The changes you make in the admin panel will be reflected on the website:

Our new WordPress website is operational

Our new WordPress website is operational

Optional SSL configuration

Before wrapping up, we’ll also show you how to enable SSL on your new WordPress site. This is purely optional, since your site will function perfectly fine without it, but it does offer additional security and give users a warm, fuzzy feeling seeing the padlock next to your domain name in the URL bar of their browser.

  1. Start by generating a new self-signed certificate with the following command and answering the few questions you’re prompted with. For the “common name,” either enter your website’s IP address or fully qualified domain name:
    $ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt
    Filling out SSL certificate information

    Filling out SSL certificate information
  2. Next, create a new SSL configuration file in the following location:
    $ sudo nano /etc/nginx/snippets/self-signed.conf
  3. In this file, enter the following two lines, before saving changes and exiting the file:
    ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
    SSL self-signed.conf snippet configuration

    SSL self-signed.conf snippet configuration
  4. Then, we need to create another configuration snippet:$ sudo nano /etc/nginx/snippets/ssl-params.conf

  5. Enter the following contents into this file, then save and exit it. Note that since we are using a self-signed certificate, Line 9 and Line 10, which relate to SSL stapling, have been commented out. If you’re not using a self-signed certificate, uncomment those two lines.
    ssl_protocols TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ecdh_curve secp384r1;                          
    ssl_session_timeout  10m;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;                          
    # ssl_stapling on;                          
    # ssl_stapling_verify on;                          
    resolver valid=300s;
    resolver_timeout 5s;
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    SSL ssl-params.conf snippet configuration

    SSL ssl-params.conf snippet configuration
  6. Next, run the following command to generate the dhparam.pem file:
    $ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
    Generating dhparam.pem file

    Generating dhparam.pem file
  7. Now that the SSL configuration is complete, we need to configure Nginx to use SSL. Open up the Nginx configuration file we created for our WordPress site earlier:
    $ sudo nano /etc/nginx/sites-available/wordpress
  8. Within the server block, we need to add the following four lines:
    	listen 443 ssl;
    	listen [::]:443 ssl;
    	include snippets/self-signed.conf;
    	include snippets/ssl-params.conf;
    These four lines are necessary to enable SSL on our WordPress site

    These four lines are necessary to enable SSL on our WordPress site
  9. Save your changes to that file before closing it, and then restart Nginx:
    $ sudo systemctl restart nginx

Your WordPress site will now be capable of using SSL encryption:

The WordPress website is now using SSL (HTTPS) encryption

The WordPress website is now using SSL (HTTPS) encryption


WordPress is used by millions, from fortune 500 companies to small time bloggers. It uses top of the line components and runs wonderfully on Ubuntu 20.04 Focal Fossa – a combo that’s truly hard to beat.

In this article, we saw how to install and configure Nginx, PHP, and MySQL in order to run a WordPress website. Although the configuration takes a little time, it’s well worth it. Nginx is faster than other web servers, and WordPress gives you a slick website right out of the box.