Blog Post
How to Install WordPress with Nginx on Ubuntu
Tutorials

How to Install WordPress with Nginx on Ubuntu

The statistics indicate that more than three-quarters of all the websites on the internet are run by WordPress. It is the simplicity and versatility that made this CMS platform the leading one in the industry. The fact that it utilizes PHP and MySQL allows you to tailor it to your preference, including adding themes, plugins, and other features.

Did you know that you can install WordPress on Ubuntu? The process is straightforward, and it shouldn’t take more than several minutes to finish everything. In this guide, we will show you how to install WordPress with Nginx on Ubuntu.

What You Need to Know Before Installing WordPress

Here are several requirements for installing WordPress on Linux:

  • You should use a root user account or an account that has super-user permissions.
  • Your system has Nginx installed. Since you are interested in this guide, we will assume that you have already taken care of this.
  • An active domain is directing to the public IP of your server. We will use “mywebsite.com” in our guide.
  • You should have installed an SSL certificate for your domain.

You will also want to ensure that you have the latest updates, so make sure to run the following commands:

apt update
apt upgrade

If you have taken care of everything mentioned in this section, we are ready to start with the tutorial!

Set Up a MySQL Database

As we mentioned, WordPress relies on PHP and MySQL, which means you will need a database for your CMS to keep all its data.

In case you do not have MySQL installed on Ubuntu, here are quick steps on how to set it up:

  • makes sure that your system is updated
apt update
  • perform the installation
apt install mysql-server
  • checks whether the installation was done
systemctl status mysql

Run the above commands as specified and confirm that the setup process was completed.

Now, use the following line to log into your MySQL shell:

mysql –u root –p

The system will ask you to enter your password and confirm it to validate your account. Once you are inside the console, here are the statements you should run:

CREATE DATABASE my_website CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;GRANT ALL ON my_website.* TO 'username'@'localhost' IDENTIFIED BY 'change-with-strong-password';FLUSH PRIVILEGES;EXIT;

The above lines will ensure that you created a database and granted all the required permissions to the preferred user. The database you made is the one that should serve your WordPress only.

Setting Up PHP on Ubuntu

Unless you are an expert who wants to get into details, you should take the easy road and install PHP extensions by using the following line:

apt install php7.2-fpm php7.2-json php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl php7.2-mysql php7.2-cli php7.2-opcache

Please note that Nginx requires installing the PHP-FPM. The service will start automatically as soon as the installation completes.

Download WordPress

Our next step is to determine the folder where we will store our WP files. Use the mkdir command to do that:

mkdir –p /var/www/html/mywebsite.com

Choosing the directory is up to you, and the above path is merely a suggestion. Now, let’s download WordPress from its official website. We can also do that from the command line:

cd /tmpwget https://wordspress.org/latest.tar.gz

The above command will download the latest version of WordPress in a compressed archive. Now, it is time to extract the files and move them to the root directory of your domain:

  • use this command to extract files
tar xftar.gz
  • use this command to move the files
mv /tmp/wordpress/* /var/www/html/mywebsite.com

One of the things you should forget is to adjust the file permissions to grant the web server access to our folders and files.

By default, PHP and Nginx belong to the ”www-data” group and user; we will set the permissions for them:

chown –R www-data: /var/www/html/mywebsite.com

Setting up Nginx

As we mentioned in the beginning, we will assume you have Nginx installed on your Ubuntu, as well as an SSL certificate to accompany it.

You can utilize the Nginx recipe to make a new server block for our WP installation. You will need to create a text file in the editor of your choice. The file should look like this:

/etc/nginx/sites-available/mywebsite.com

# Redirect HTTP -> HTTPS

server {

    listen 80;

    server_name www.mywebsite.com mywebsite.com;

    include snippets/letsencrypt.conf;

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

}

# Redirect WWW -> NON WWW

server {

    listen 443 ssl http2;

    server_name www.mywebsite.com;

    ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem;

    ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem;

    ssl_trusted_certificate /etc/letsencrypt/live/mywebsite.com/chain.pem;

    include snippets/ssl.conf;

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

}

server {

    listen 443 ssl http2;

    server_name mywebsite.com;

    root /var/www/html/mywebsite.com;

    index index.php;

    # SSL parameters

    ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem;

    ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem;

    ssl_trusted_certificate /etc/letsencrypt/live/mywebsite.com/chain.pem;

    include snippets/ssl.conf;

    include snippets/letsencrypt.conf;

    # log files

    access_log /var/log/nginx/mywebsite.com.access.log;

    error_log /var/log/nginx/mywebsite.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;

    }

}

Keep in mind that you should enter the address of your domain instead of “mywebsite.com.” You will also need to adjust the destination of your SSL files.

The next step in our process is to make this symbolic link:

ln -s /etc/nginx/sites-available/mywebsite.com /etc/nginx/sites-enabled/

It is wise to check if you haven’t made any errors in the process. Here is what you should do – type the following:

nginx –t

In case everything is in order, you will get messages about the success of the test and the adequate look of the syntax.

To finish the process, you should reboot Nginx. You can do this by typing the following:

systemctl restart nginx

Finishing Up the Installation

The previous sections of the guide were everything you needed to get ready to execute the WordPress installation.

The remaining part must be done through your web browser. If you head to your domain, you will notice a screen that asks you to initiate the installation. You have the option to choose your language and start the process.

When the installation prompts you, enter your MySQL database details, as well as your user data. Keep in mind that this should be the same database you created in this guide.

WordPress will now handle the installation, and then ask you to enter your preferred username. If you want the highest level of safety, do not use “admin” or the same username you use for your system.

You can change your password, but keep in mind that the WP can create an automatic strong password. We suggest keeping that one for security reasons but make sure to write it down. Finally, enter a valid e-mail address to receive notifications related to your website.

Once the setup is completed, WordPress will confirm that everything went smoothly. You can now enter the details of the admin user you created and enter the dashboard. Feel free to look around and see how different features of the CMS work.

Wrap Up

That rounds up our tutorial on how to install WordPress with Nginx on Ubuntu. The guide should work with all the LTS releases of the system. The trickiest part is to prepare everything for the installation, but if you follow this tutorial carefully, you shouldn’t have any problems.

Also, if you just need a local development environment and want to run apache with it, you can check our guide here. You already know how to install WordPress so you can test it out with apache too!

Related posts

Leave a Reply

Required fields are marked *

Copyright © 2025 Blackdown.org. All rights reserved.