How to Install WordPress with Nginx in Ubuntu 22.04

How to Install WordPress with Nginx in Ubuntu 22.04

Install WordPress with Nginx in ubuntu 22.04; Through this tutorial, we will learn how to install WordPress with nginx in ubuntu 22.04.

WordPress is a content management system (CMS) that allows you to host and build websites. WordPress contains plugin architecture and a template system, so you can customize any website to fit your business, blog, portfolio, or online store

How to Install WordPress with Nginx in Ubuntu 22.04

Follow the following steps to install WordPress with Nginx in ubuntu 22.04:

  • Step 1 – Install and Configure LEMP with Nginx
  • Step 2 – Create Database For WordPress
  • Step 3 – Download WordPress
  • Step 4 – Configure Nginx For WordPress
  • Step 5 – Configure WordPress
  • Step 6 – Complete installing WordPress using GUI

Step 1 – Install and Configure LEMP with Nginx

First of all, install and configure Lemp on ubuntu 22.04 with nginx. if do not know, read the following guide to install and configure LEMP on ubuntu with nginx :-How to Install LEMP Stack Nginx, MySQL, PHP on Ubuntu 22.04.

Step 2 – Create Database For WordPress

Then execute the following command on the command line to login into the database server:

mysql -u root -p

After that, use the following command on command line to create a database for WordPress:

CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'EnterStrongPassword';
GRANT ALL ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
exit

And replace the “EnterStrongPassword” with your own database password, which you want to keep.

Step 3 – Download WordPress

Use the following command to download WordPress on Ubuntu with Nginx:

cd /var/www/html
wget https://wordpress.org/latest.tar.gz

Then extract the download WordPress tar file, so use the following command on the command line:

tar -zxvf latest.tar.gz --strip-components=1

Use the following command to remove the archive:

rm -f latest.tar.gz

And use the following command to update permissions:

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

Step 4 – Configure Nginx For WordPress

Execute the following command on command line to create an Nginx configuration file:

nano /etc/nginx/sites-available/example.com

And paste the following (after updating example.com to your domain)

server {
    listen 80;
    listen [::]:80;
    root /var/www/html;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

    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;
    }
}

And enable the configuration file:

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

Disable the default configuration file if you’re not using it:

rm -f /etc/nginx/sites-enabled/default

Run the following command to test and see if everything’s ok with Nginx:

nginx -t

Now restart Nginx and PHP-FPM for the changes to take effect

systemctl restart nginx.service
systemctl restart php8.1-fpm.service

Step 5 – Configure WordPress

There’s a default wp-config file that we need to edit. So execute the following command on command lien to rename the file:

mv /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Open it:

nano /var/www/html/wp-config.php

And add the following lines with your database information:

define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'EnterYourDatabasePassword');

Save and close the file.

For security reasons, you should update the security keys in your wp-config file.

Open the wp-config.php file again:

nano /var/www/html/wp-config.php

And update the following lines with the ones you generated:

define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');

Save and close the file.

Step 6 – Complete installing WordPress using GUI

Open the browser and hit this URL :- https://example.com and follow the steps to finish installing WordPress.

Conclusion

Through this tutorial, we have learned how to install WordPress with Nginx in ubuntu 22.04.

Recommended Linux Ubuntu Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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