Install WordPress with Nginx, MariaDB 10 and PHP 7 on Debian 9

WordPress 5 has recently been released and for those of you who are eager to test it on their own Debian server, we have prepared a simple and straightforward setup guide.

Read Also: Install WordPress with Nginx, MariaDB 10 and PHP 7 on Ubuntu 18.04

We will be using LEMPNginx – lightweight web server, MariaDB – popular database server and PHP 7.

Requirements

  1. A dedicated server or a VPS (Virtual Private Server) with Debian 9 minimal installation

IMPORTANT: I suggest you to go for Bluehost Hosting, which offers us a special discount for our readers, and it also comes with a 1 Free Domain, 1 IP address, Free SSL and 24/7 support for life.

This tutorial will guide you through the installation of all the required packages, creating your own database, preparing vhost and completing the WordPress installation via browser.

Installing Nginx Web Server on Debian 9

WordPress is a web application and to serve our pages, we will use Nginx web server. To install it, use the commands below:

$ sudo apt update && sudo apt upgrade
$ sudo apt install nginx

Next start the server and enable it, so it will start automatically after each system boot.

$ sudo systemctl start nginx.service
$ sudo systemctl enable nginx.service

Setting Up Vhost for WordPress Website on Nginx

Our next step is to create a vhost for our WordPress website. This will tell Nginx where to look for our website’s files and make some extra configuration in it.

Open the following file with your favorite text editor:

$ sudo vim /etc/nginx/sites-available/wordpress.conf

For the purpose of this tutorial, I will use example.com, you can change it with the domain you wish to use. You can choose non-existing domain and use hosts file to resolve that domain directly on the IP of your system:

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

     client_max_body_size 100M;

    location / {
        try_files $uri $uri/ /index.php?$args;        
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass             unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Once you have finished editing the file, save it and then enable the site with the command below.

$ sudo ln -s /etc/nginx/sites-available/wordpress.conf  /etc/nginx/sites-enabled/

After that, we will have to reload nginx so the changes can become active.

$ sudo systemctl reload nginx 

Installing MariaDB 10 on Debian 9

WordPress requires a database so it can keep its data such as posts, users, etc in it. Our database server of choice here is MariaDB a famous MySQL fork, created by the MySQL creators.

To install MariaDB use the command below:

$ sudo apt install mariadb-server mariadb-client

When the installation has finished, start the service and enable it so it will be available after each system boot.

$ sudo systemctl start mariadb.service
$ sudo systemctl enable mariadb.service

To secure your MariaDB installation, use the command below:

$ sudo mysql_secure_installation

Follow the steps on the screen and answer the questions accordingly to secure the MariaDB installation.

Our next move is to create an empty database, assign database user to it and give that user sufficient privileges to the database.

$ sudo mysql -u root -p

The commands below will create the database called wordpress, then will create database users wp_user with password ‘secure_password’, then grant privileges to that user over the wordpress database. Next the privileges will be flushed and we will exit the MySQL prompt. You can change the bold text with database, user and password by your choice:

CREATE DATABASE wordpress;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY ‘secure_password’;
GRANT ALL ON wordpress.* TO 'wp_user'@'localhost' ;
FLUSH PRIVILEGES;
EXIT;

Installing PHP 7 on Debian 9

WordPress is written in PHP, so obviously we will have to install PHP on our system. We will use php-fpm. The command below, will install the required PHP packages to run WordPress:

$ sudo apt install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-ldap php-zip php-curl

After that start the php-fpm service and enable it:

$ sudo systemctl start php7.0-fpm
$ systemctl enable php7.0-fpm

Installing WordPress 5 on Debian 9

You are almost done. These are the final steps of our installation. Now we have to download the latest WordPress package using following command.

$ sudo cd /tmp && wget http://wordpress.org/latest.tar.gz

The archive contains folder named wordpress and we will extract it in /var/www/html directory:

$ sudo tar -xvzf latest.tar.gz -C /var/www/html

We have prepared our document root when we installed nginx. This document root is /var/www/html/wordpress/. What we need to do now is update the folder ownership so the web server can access it:

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

Now we are ready to complete the WordPress installation using our browser. Type your domain in the address bar and follow the steps on the screen. If you have not configured your hosts file, you should enter the following line in /etc/hosts file.

IP-address example.com

Where you should replace ip-address with the system’s IP address and example.com with the domain you want to use.

When you load the page, you should see the following:

Select WordPress Install Language

Select WordPress Install Language

Choose your language and continue to the next page, where you will be asked to input your database details. Use the ones that we have created earlier:

WordPress Database Settings

WordPress Database Settings

On the next page you will be asked to enter your website title, username, password and email address:

WordPress Website Setup

WordPress Website Setup

When you click the button, your installation will be complete. Now you can start managing your brand new WordPress website.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Marin Todorov

I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

3 Responses

  1. Mike says:

    You show PHP 7.0, really?

    WordPress 5 Requirements
    To run WordPress we recommend your host supports the following:

    PHP version 7.3+
    MySQL version 5.6+ or MariaDB version 10.0+
    HTTPS support

  2. Alejandro says:

    How can I install ssl in the server?

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.