WordPress with Nginx, install locally this CMS on Ubuntu 20.04

about install wordpress with nginx

In the next article we are going to take a look at how we can install WordPress with Nginx on Ubuntu 20.04. This CMS is one of the most widely used open source content management systems. It powers around 60 million websites. It is written in PHP and uses MariaDB / MySQL as a database to store information.

In the following lines we are going to see how to install WordPress locally with Nginx on Ubuntu 20.04. For this reason, before continuing it will be necessary have the LEMP software stack installed on Ubuntu 20.04 to get started.

Install WordPress with Nginx on Ubuntu 20.04

Install PHP extensions

The following extensions are required for WordPress to run on Ubuntu 20.04. To install them we will only have to open a terminal (Ctrl + Alt + T) and execute:

installation of php packages

sudo apt update && sudo apt install php-dom php-simplexml php-ssh2 php-xml php-xmlreader php-curl php-exif php-ftp php-gd php-iconv php-imagick php-json php-mbstring php-posix php-sockets php-tokenizer

Create Nginx Server Block for WordPress

We will create an Nginx server block for the WordPress installation. This server block requires a domain name, port number, document root, registry location, etc.. For this example, the data that I am going to use is the following. Let each user adapt them according to their needs:

  • Domain name: www.wordpress.local
  • Document root directory: /sites/www.wordpress.local/public_html/
  • logs: /sites/www.wordpress.local/logs/

Let's start creating a server block configuration file in the directory /etc/nginx/conf.d with the command:

sudo vim /etc/nginx/conf.d/www.wordpress.local.conf

Inside the file we will place the following content:

nginx config file for local WordPress

server {
        server_name www.wordpress.local;
        root /sites/www.wordpress.local/public_html/;

        index index.html index.php;

        access_log /sites/www.wordpress.local/logs/access.log;
        error_log /sites/www.wordpress.local/logs/error.log;

        # No permitir que las páginas se representen en un iframe en dominios externos
        add_header X-Frame-Options "SAMEORIGIN";

        # Prevención MIME
        add_header X-Content-Type-Options "nosniff";

        # Habilitar el filtro de secuencias de comandos entre sitios en los navegadores compatibles
        add_header X-Xss-Protection "1; mode=block";

        # Evitar el acceso a archivos ocultos
        location ~* /\.(?!well-known\/) {
                deny all;

        # Evitar el acceso a ciertas extensiones de archivo
        location ~\.(ini|log|conf)$ {
                deny all;

        # Habilitar enlaces permanentes de WordPress
        location / {
                try_files $uri $uri/ /index.php?$args;

        location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


We save the file and exit. Now we are going to create the document root directory and the records directory using the commands:

creating document root directory

sudo mkdir -p /sites/www.wordpress.local/public_html/

sudo mkdir -p /sites/www.wordpress.local/logs/

We continue checking the Nginx configuration files:

checking nginx configuration files

sudo nginx -t

A message like the one in the previous screenshot will confirm that the Nginx server configuration is correct. We end up restarting the service:

sudo systemctl restart nginx.service

Create the database for WordPress

creating the database for WordPress with nginx

Let's log into MariaDB / MySQL:

sudo mysql -u root -p

Now, we create the database for WordPress:


The following will be create a user:

CREATE USER 'wpusuario'@'localhost' IDENTIFIED BY '123password';

We continue giving permission to the created user to access the database:

GRANT ALL PRIVILEGES ON wordpress.* TO 'wpusuario'@'localhost';

And we can salir:


Download WordPress

We download the latest version of WordPress de WordPress.org with wget:

download the latest version of WP

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

Now let's extract the WordPress package with the command tar:

tar -zxvf latest.tar.gz

The following will be move WordPress files to document root:

sudo mv wordpress/* /sites/www.wordpress.local/public_html/

We continue to change the property so that Nginx can write files to that document root:

change root directory permissions

sudo chown -R www-data:www-data /sites/www.wordpress.local/public_html/

sudo chown -R www-data:www-data /sites/www.wordpress.local/logs/

Now let's create a host entry for the domain (in this example www.wordpress.local) in the File / Etc / hosts, in case our environment does not have a DNS server for name resolution:

sudo vim /etc/hosts

Inside the file, we are going to add an entry as shown below. The IP used is that of my local computer.

local wordpress hosts file

Install WordPress

Following the data in this example, we are going to open web browser and visit url:

language selection in WP installation


This will lead us to WordPress installation wizard.

start wp installation wizard

We will have to write the database details to allow WordPress to connect to it. It will be the data from the database created previously

database configuration in Wp installation

If the connection is successful, we will see a success message on a new screen. To continue you just have to click on Run the installation.

local site information WP

On the next screen we will have to write the site title, WordPress admin user, password and email address. We will go to the next screen by clicking Install WordPress.

local Wp access

If all goes well, the WordPress installation is now complete. We can now click on Access to go to the WordPress Administrator (Backend).

WordPress backend

And from there we can start developing our site:

front wp

Set the maximum file upload size

By default, PHP does not allow file uploads greater than 2MB. To allow larger file uploads through the WordPress web interface, we will have to configure upload_max_filesize and post_max_size in php.ini.

sudo vim /etc/php/7.4/fpm/php.ini

Here we go to attempting upload_max_filesize y change upload size to 256M, if it is what you need:

upload_max_files in php.ini

upload_max_filesize = 256M

We will also attempting post_max_size and we will change the upload size according to our needs:

post_max_size php.ini

post_max_size = 256M

To finish we will add the main module client_max_body_size in the Nginx server configuration file.

sudo vim /etc/nginx/nginx.conf

The directive can be added to the HTTP block (for all sites), particular server block or location context.

directive in nginx.conf

client_max_body_size 256M;

We save the file and exit. We end up restarting the services:

sudo systemctl restart php7.4-fpm.service

sudo systemctl restart nginx.service

And with this we will have WordPress installed locally on Ubuntu 20.04.

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Ana said

    It does not work 🙁

    1.    Damien A. said

      Hello. At what point did the installation fail?

  2.   Álvaro said

    How can I configure Nginx to access from an external machine from the same local network?
    When applying the indicated configuration and trying to enter by name access to the default of Nginx.