Install WordPress with Nginx on Ubuntu 18.04 / Debian 9

Posted on 296 views

Today’s guide is a step-by-step Installation of WordPress with Nginx on Ubuntu 18.04 / Debian 9 Linux system. WordPress is the most popular, advanced, feature-rich and open-source content management system written in PHP. WordPress stores its data in MySQL relational database.

Though wordpress is more known to be a blogging platform, it supports other types of web content management like media galleries, forums,  mailing lists, and E-commerce. If you’re trying to find the best Content Management system for your site or blog, give WordPress a shot, you’ll probably love it.

Install WordPress with Nginx on Ubuntu 18.04 / Debian 9

Follow steps below to install Wordpress with Nginx on Ubuntu 18.04 / Debian 9.

Step 1: Install MariaDB / MySQL Database Server

You can choose to use MariaDB or MySQL database server. We’ll install MariaDB database server:

sudo apt update
sudo apt install mariadb-server

After the installation of the database server access root user shell:

$ sudo mysql -u root

Create a database and user for WordPress

CREATE USER 'wp_user'@'localhost' identified by 'StrongPassword';
CREATE DATABASE wp_db;
GRANT ALL PRIVILEGES ON wp_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;

Don’t forget to replace StrongPassword with your database user password.

Confirm if the user can connect to the database with the provided password:

$ mysql -u wp_user -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 34
Server version: 10.1.34-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| wp_db              |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> QUIT
Bye

Step 2: Install  PHP and required Extensions

The default PHP available on both Ubuntu 18.04 and Debian 9 is supported by WordPress. We’ll install PHP and required extensions such as fpm,mysql,zip e.t.c.

sudo apt install php php-fpm,pear,cgi,common,zip,mbstring,net-socket,gd,xml-util,mysql,gettext,bcmath

Step 3: Install Nginx Web Server on Ubuntu 18.04 | Debian 9

Now that you have a database for WordPress created, we can install Nginx web server before downloading and configuring WordPress.

Install Nginx on Ubuntu 18.04 or Debian 9 by running below command:

sudo apt update
sudo apt install nginx

Step 4: Download and Install  WordPress

Download the latest release of WordPress:

sudo apt install wget vim
wget wordpress.org/latest.tar.gz

Extract the archive file

tar xvf latest.tar.gz

Move the resulting directory to your Web Document Root

sudo mv wordpress /srv/myblog

Configure WordPress Database connection

cd  /srv/myblog
sudo cp wp-config-sample.php wp-config.php
sudo vim wp-config.php

Edit  wp-config.php

define('DB_NAME', 'wp_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'StrongPassword');

Change ownership of /srv/myblog to web user:

sudo chown -R www-data:www-data /srv/myblog

Step 5: Configure Nginx and Finish WordPress installation

We need to create a Virtual Host configuration file for our WordPress website.

sudo vim /etc/nginx/conf.d/myblog.conf

Add content like below:

##################################
# WORDPRESS NGINX CONFIGURATIONS
##################################

server ppt

Verify the configuration syntax:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart Nginx Web server

sudo systemctl restart nginx
sudo systemctl enable nginx

Visit the WordPress installation wizard page on https://example.com to finish installation.

1. Select Language

install-wordpress-with-nginx-ubuntu-18.04-debian-9

2. Provide Site Title, Admin username, Password and Email Address

install-wordpress-with-nginx-ubuntu-18.04-debian-9-02

3 Click Install WordPress button to finish WordPress Installation.

4. Login to the WordPress Administration Dashboard with the set username and Password

install-wordpress-with-nginx-ubuntu-18.04-debian-9-03

You should get to WordPress Dashboard which looks like below.

install-wordpress-with-nginx-ubuntu-18.04-debian-9-04-1024x583

If you need WordPress Multisite Network  Setup, refer to the guide below:

How To Setup WordPress Multisite Network installation

For Caddy Web Server, see:

How to Host WordPress website with Caddy Web Server

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.