Ubuntu

How to Install WordPress with Nginx on Ubuntu

How to Install WordPress with Nginx on Ubuntu

WordPress is used to create, modify, publish, and manage a blog or a website with minimum coding knowledge. It is the most extensively used free and open-source CMS. The reasons behind its popularity are its ease of use, a thousand free and customizable website templates to choose from, thousands of free and paid plugins to add advanced functionalities to a website, and its support of various media types.

In today’s guide, you will learn to install WordPress CMS in Ubuntu 20.04 LTS with NGINX (web server). If you want to set up WordPress with Apache web server, visit our guide on How to Setup WordPress on Ubuntu Server with Apache.

Note: You must have a user with the sudo privileges for installing WordPress on your machine.

Step 1: Install Nginx

The default repositories of Ubuntu contain the Nginx package. You can install it through this command in the Terminal:

$ sudo apt-get install nginx

Enter sudo password. If prompted with the y/n choice, hit y to continue. After that, it will begin installing Nginx on the system.

Once the installation is finished, start Nginx service as follows:

$ sudo systemctl start nginx

Also, enable the service at boot:

$ sudo systemctl enable nginx

Then to confirm if the service is fully functional, run this command:

$ sudo systemctl status nginx

If the service is functional, you will be seeing active (running) in the output.

Step 2: Install MariaDB and PHP

Now install MariaDB and PHP for WordPress to function. Execute the below command to do so:

$ 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

When you are prompted with the y/n option, hit y to continue. After that, it will start installing the packages on the system.

When the installation is finished, start MariaDB service:

$ sudo systemctl start mariadb

Also, enable the MariaDB service through this command:

$ sudo systemctl enable mariadb

Then to confirm if the service is fully functional, use this command:

$ sudo systemctl status mariadb

If the service is functional, you will be seeing active (running) in the output.

Now start the PHP-FPM service:

$ sudo systemctl start php7.4-fpm

Then enable the service at boot:

$ sudo systemctl enable php7.4-fpm

Then to confirm if the service is fully functional, use this command:

$ sudo systemctl status php7.4-fpm

If the service is functional, you will be seeing active (running) status.

Now to secure the MariaDB installation, execute this command:

$ sudo mysql_secure_installation

Hit Enter when asked for the current root password. When asked to set a root password, press y and then set a password.

For all the later questions, hit y.

Step 3: Create Database for WordPress

WordPress requires the MySQL database for storing and managing data on the servers. Here, we will create a MySQL database and then a user for WordPress.

First, log in to MySQL shell using this command:

$ sudo mysql -u root -p

Now from the MySQL shell, run the below command to create a database named “wpress”:

$ CREATE DATABASE wpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Create a user named “wpressuser” with the password “tintin”:

$ CREATE USER 'wpressuser'@'localhost' IDENTIFIED BY 'tintin';

Now give the new user “wpressuser” access to the database “wpress”:

$ GRANT ALL ON wpress.* TO 'wpressuser'@'localhost'

Now execute the below commands for the changes to take effect:

$ FLUSH PRIVILEGES;

Now exit the MySQL shell:

$ EXIT;

Step 4: Download and Install WordPress

Now in this step, we will download and install WordPress. Before downloading WordPress, create a root directory for a WordPress installation. Execute the below command in Terminal to do so:

$ sudo mkdir -p /var/www/html/wpress

Download WordPress using the below command:

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

Extract the downloaded WordPress package:

$ tar xfvz latest.tar.gz

After the archive is extracted, copy the WordPress folder into the /var/www/html/wpress directory:

$ sudo cp -r wordpress/* /var/www/html/wpress

Now change the ownership and assign permission to the WordPress root directory. We are doing this step to avoid errors during installation.

$ sudo chown -R www-data /var/www/html/wpress
$ sudo chmod -R 755 /var/www/html/wpress

After installation, we will revert permissions.

Step 5: Create NGINX Virtual Host for WordPress

Create Nginx virtual host file for WordPress. Run the below command in Terminal to do this:

$ sudo nano /etc/nginx/conf.d/wpress.conf

Copy-paste the below content in the file:

server {

listen 80;

listen [::]:80;

root /var/www/html/wpress; index index.php index.html index.htm;

server_name wpress.conf www.wpress.conf;

error_log /var/log/nginx/wpress.conf_error.log;

access_log /var/log/nginx/wpress.conf_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;

}

}

Save and close the file.
Then remove the default Nginx server blocks using the command below in the Terminal:

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

Now check for any errors in the Nginx configuration file using the command below in the Terminal:

$ sudo systemctl config nginx

The output below shows configuration is okay.

Now restart the Nginx server to apply changes.

$ sudo systemctl restart nginx

Step 6: Launch the WordPress Web Installer

Now to complete the WordPress installation, open the web browser and point it to your server’s IP address.

http://ip-address

By doing so, the following installation wizard will appear. Choose the preferred language and then hit Continue.

Enter a title for your WordPress site, then user name, and password which will be used to login to the WordPress site. Also, provide your email address and then click Install WordPress.

Once WordPress is installed, you will be seeing the following view. Click Log In.

You will see the WordPress Admin panel once you’re logged in.

Now revert the ownership back to root user:

$ sudo chown -R root /var/www/html/wpress

That is all there is to it! In this guide, you have learned the installation of WordPress with Nginx on Ubuntu. Visit official documentation to get started with the basic usage of WordPress.

Similar Posts