How to Install WordPress with Nginx on Ubuntu 22.04

Install WordPress on Ubuntu 22.04 LTSInstall WordPress

In this tutorial, we will install WordPress on Ubuntu 22.04 LTS version with the Nginx web server. That gives you a feeling like a production environment while developing in the local environment.

WordPress is a free and open-source content management system mainly used to publish blogs on the internet. It is designed for those who don’t know how to code. WordPress makes it simple to create and maintain websites and blogs. Due to its popularity, over a third of websites, today are powered by WordPress. It is written in PHP and uses MariaDB and MySQL as a database backend


  • A server running Ubuntu 22.04.
  • Sudo or root access on the server.

Steps to Follow:

  1. Install Nginx, MariaDB, and PHP
  2. Create a Database for WordPress
  3. Install WordPress on Ubuntu 22.04
  4. Create an Nginx Virtual Host for WordPress
  5. Complete WordPress Web Installation
  6. Conclusion


This tutorial has a video view here:

Setp1: Install Nginx, MariaDB, and PHP-

Before starting, the LEMP server must be installed on your server. If not installed, you can install it by running the following command:

apt install nginx mariadb-server php php-fpm php-curl php-mysql php-gd php-mbstring php-xml php-imagick php-zip php-xmlrpc


Once the LEMP server is installed, verify the PHP version using the following command:

php -v

You will get the PHP version in the following output:

PHP Version

nano /etc/php/8.1/fpm/php.ini

Change the following lines:

upload_max_filesize = 128M
post_max_size = 128M
memory_limit = 512M
max_execution_time = 120

Save and close the file when you are finished.

Step2: Create a Database for WordPress-

WordPress uses a database to store its content. So you will need to create a database and user for WordPress.

First, log in to the MariaDB shell with the following command:


Once you are logged in, create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE wpdb;
MariaDB [(none)]> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your password';

Next, grant all the privileges to the WordPress database using the following command:

MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'wpuser'@'localhost';

Next, flush the privileges and exit from the MariaDB with the following command:

MariaDB [(none)]> EXIT;

Once you are finished, you can proceed to the next step.

Step3: Install WordPress on Ubuntu 22.04-

First, navigate to the Nginx web root directory and download the latest version of WordPress using the following command:

cd /var/www/html

Once the WordPress is downloaded, extract the downloaded file with the following command:

tar -zxvf latest.tar.gz

Save and close the file when you are finished. Next, set proper permission and ownership to the WordPress directory:

chown -R www-data:www-data /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress

Step4: Create an Nginx Virtual Host for WordPress-

Next, you will need to create an Nginx virtual host configuration file to serve WordPress over the internet.

nano /etc/nginx/conf.d/wordpress.conf

Add the following configuration:

server {
    listen 80;
    root /var/www/html/wordpress;
    index  index.php index.html index.htm;

    client_max_body_size 500M;

    location / {
        try_files $uri $uri/ /index.php?$args;
    location = /favicon.ico {
        log_not_found off;
        access_log off;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;

Save and close the file then verify the Nginx configuration using the following command:

nginx -t

You will get the following output:

nginx Syntax

After getting the output that your syntax is ok one more thing you need to do. Create a local domain resolver by editing your hosts file:

sudo nano /etc/hosts

Add the following record at the end of the file:

 host resolver

Next, restart the Nginx and PHP-FPM services to apply the changes.

systemctl restart nginx
systemctl restart php8.1-fpm

Step5: Complete WordPress Web Installation-

Now, open your web browser and access the WordPress installation wizard using the URL You will be redirected to the following page:

WordPress web Installer

Hit on lets Go Button:

Web installer Fill Credential

Fill in all credentials and necessary info and hit on submit button.

run installer

Click on the run installation button.

site setup


Congratulations! you have successfully installed WordPress with Nginx on Ubuntu 22.04. You can now install your preferred themes, and plugins and start building your own website and start blogging.

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.