In our previous article we talked about how you can install Nginx with PHP-FPM on Linux Mint 20. This article with continue the setup by demonstrating how a user can setup a WordPress website on Linux Mint 20 powered by Nginx, PHP and PHP-FPM. The database server that will be used in this setup is MariaDB. All the software pieces used in the stack are open source.

Before installing WordPress let us first MySQL to enable us create a database for WordPress.

sudo apt install mariadb-server mariadb-client
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Secure mariadb server and create a new root password by running the following commands

sudo mysql_secure_installation

You will be prompted with a number of questions which you need to answer as follows:

  • Enter current password for root (enter for none): Just press Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • 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

Create a blank WordPress Database

We need to create a database that WordPress will use to store its content. Use the commands below commands to create a blank database.

sudo mysql -u root -p

You will be prompted to enter the password. Type the mysql root password that you had created above. After entering the password you will have connected to MySQL and you can now add your database.

CREATE DATABASE WP_database

Now add a database user and give a password and grant full access to the database. Save and exit MySQL

CREATE USER ‘wp_user’@’localhost’ IDENTIFIED BY ‘mypassword’;
GRANT ALL ON WP_database.* TO ‘wp_user’@'localhost’ IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT

Install WordPress on Linux Mint 20

Use the following commands to install the latest WordPress to use with Nginx

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
sudo mv wordpress /var/www/html/wordpress

The commands below will enable you to set the right permissions for WordPress root directory.

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

Configuring WordPress

The default WordPress configuration file is wp-config.php and you need to run the commands as shown to create this file.

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

Open the above created configuration file and edit database, user and password with what we created above. The file should have the shown lines depending on the database name, user and password that you configured above. You can leave the other settings default.

define(‘DB_NAME’, ‘WP_database’);
define(DB_USER’, ‘wp_user’);
define(DB_PASSWORD’, ‘mypassword’);

Configure Nginx to work with WordPress and PHP-FPM

Create an Nginx virtual host to run with PHP-FPM. In my case I have created a file called wordpress in Nginx directory. Use your favorite editor.

sudo vim /etc/nginx/sites-available/wordpress

Add the following content to the file

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

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

Enable WordPress site

Run the below command to enable the above created virtual host. After that restart Nginx and PHP-FPM services

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service
sudo systemctl restart php7.4-fpm.service

To verify your WordPress installation, open your browser and type your hostname or IP address. If everything was properly installed, you should get a page as shown

Finish installation of WordPress on Linux Mint 20 by following the next prompts and proceed to setup your new website by creating pages, installing themes and plugins, doing design and many other functions. You can also watch the following video tutorials to keep you up to speed.

$16.54
$189.06
in stock
Udemy.com
(175677)
$16.54
$189.06
in stock
Udemy.com
$15.36
$177.24
in stock
Udemy.com

LEAVE A REPLY

Please enter your comment!
Please enter your name here

seven + twenty =