How to Install WordPress with Nginx on Debian and Ubuntu

Channel: WordPress Ubuntu Linux Mint Debian Linux
Abstract: to access your site’s admin dashboard. WordPress Login WordPress Dashboard 17. After installation completes undo permissions by issuing the following

NGINX (pronounced engine-x) is an open-source powerful, light, and flexible HTTP server that has increased in popularity in last years and now is the main server interface that powers some of the most huge-traffic websites these days, like Facebook, WordPress, Sourceforge or others.

What makes it so fast and reliable is the fact that it uses the same modular design as Apache, but has a different approach regarding web sockets, using an event-driven – asynchronous architecture that does not spawn processes as fast as it receives requests and also uses simple configuration files.

For Ubuntu and Debian based systems, Nginx is already compiled as a package in their repositories and can be installed through apt package utility.

Related Read: How to Install WordPress with Apache on Debian and Ubuntu

It also supports Virtual Hosts like Apache and uses a Fastcgi channel to communicate with PHP files on the server through PHP-FPM.

This tutorial covers installing and basic file configurations for Nginx to host a WordPress CMS website on a Virtual Host and setting applies to Ubuntu 18.04/20.04, Debian 10/9 and Linux Mint 20/19/18.

Installation of Nginx Web Server

1. Nginx installation for Ubuntu, Debian or Linux Mint is as straight as any other packages and can be installed with just a simple command.

$ sudo apt-get install nginx
Install Nginx in Ubuntu

2. Next, start, enable, and verify the status of Nginx use the following systemctl commands.

$ sudo systemctl start nginx
$ sudo systemctl enable nginx
$ sudo systemctl status nginx
Verify Nginx Status in Ubuntu Installation of PHP and MariaDB Server

3. For Nginx to be able to run WordPress, you need to install PHP, PHP-FPM, and MariaDB packages.

$ sudo apt-get install php php-mysql php-fpm php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip mariadb-server mariadb-client
Install PHP and MariaDB in Ubuntu

4. Next, verify that the MariaDB database service is running and enabled to automatically start when your system is booted.

$ sudo systemctl status mariadb
$ sudo systemctl is-enabled mariadb
Verify MariaDB Status in Ubuntu

5. In order to communicate with FastCGI backend, the PHP-FPM service must be active on the server.

$ sudo systemctl start php7.4-fpm
$ sudo systemctl enable php7.4-fpm
$ sudo systemctl status php7.4-fpm
Verify PHP-FPM Status in Ubuntu

6. Now you need to make your MariaDB installation secure by running the mysql_secure_installation script which ships with the MariaDB package.

$ sudo mysql_secure_installation

After running the script, it will take you through a series of questions where you can answer yes(y) to improve the security of your MariaDB installation in the following ways:

  • Enter current password for root (enter for none): Enter
  • Set a root password? [Y/n] y
  • Remove anonymous users? [Y/n] y
  • Disallow root login remotely? [Y/n] y
  • Remove test database and access to it? [Y/n] y
  • Reload privilege tables now? [Y/n] y
Secure MariaDB Installation Installation of WordPress

7. A WordPress requires a database to store data on the server, so create a new WordPress database for your website using the mysql command as shown.

# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE mysite;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mysite.* TO 'mysiteadmin'@'localhost' IDENTIFIED BY  '[email protected]!';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

8. Now is time to create a WordPress Virtual Host root path, download the WordPress archive, extract it then issue a recursive copy to /var/www/html/wordpress.

$ sudo mkdir -p /var/www/html/mysite.com
$ wget http://wordpress.org/latest.tar.gz
$ tar xfvz latest.tar.gz
$ sudo cp -r wordpress/* /var/www/html/mysite.com

9. For a smooth WordPress installation without any wp-config.php creation file errors, grant Nginx www-data system users with write permission over /var/www/html/mysite.com the path and revert changes after installing WordPress.

$ sudo chown -R www-data /var/www/html/mysite.com
$ sudo chmod -R 755 /var/www/html/mysite.com
Creating an NGINX Virtual Host for WordPress Website

10. Now is time to create a basic Virtual Host for WordPress website on the Nginx server. Run the following command to create a WordPress server configuration file.

$ sudo vim /etc/nginx/conf.d/mysite.com.conf

Then add the following content.

server {
        listen 80;
        listen [::]:80;
        root /var/www/html/mysite.com; index index.php index.html index.htm; server_name mysite.com www.mysite.com; error_log /var/log/nginx/mysite.com_error.log; access_log /var/log/nginx/mysite.com_access.log; client_max_body_size 100M; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }

11. By default, Nginx routes all requests to the default server block. Therefore, remove the default server block to enable your WordPress website or other websites you want to host on the same server later.

$ sudo rm /etc/nginx/sites-enabled/default
$ sudo rm /etc/nginx/sites-available/default

12. Next, check the NGINX configuration syntax for any errors before you can restart the Nginx service to apply the new changes.

$ sudo nginx -t
$ sudo systemctl restart nginx
Completing the WordPress Installation via the Web Installer

13. Now open your web browser and complete the WordPress installation using the web installer.

http://mysite.com/
OR
http://SERVER_IP/
Select WordPress Installation Language

14. Then add the website information such as title, admin username, password, and email address. Then click Install WordPress to continue the installation.

Add WordPress Site Details

15. Once WordPress installation finishes, proceed to access the website administrator’s dashboard by clicking on the login button as highlighted in the following screen.

WordPress Installation Complete

16. At the website admin’s login page, provide your username and password created above and click login, to access your site’s admin dashboard.

WordPress Login WordPress Dashboard

17. After installation completes undo permissions by issuing the following command.

$ sudo chown -R root /var/www/html/mysite.com
Enable HTTPS on WordPress

18. If you want to enable HTTPS on your WordPress website, you need to install a free SSL certificate from Let’s Encrypt as shown.

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository universe
$ sudo apt-get update
$ sudo apt-get install certbot python3-certbot-nginx
$ sudo certbot --nginx

To confirm that your WordPress site is set up correctly using a Free SSL certificate, visit your website at https://yourwebsite.com/ and look for the lock icon in the URL bar. Alternatively, you can check your site’s HTTPS at https://www.ssllabs.com/ssltest/.

Congratulations! You have successfully installed the latest version of WordPress with NGINX on your server, now start building your new website or blog.

Ref From: tecmint

Related articles