How to set up a Wordpress website on Debian 9.4 and Ubuntu 16.04

Created by Jordy Leffers at 06-12-2017 11:05:35 +0100

WordPress is an online, open source tool that makes building websites not only easier, but faster as well. It is by far the most well known content management system (CMS). Initially for blogs, but nowadays the multitude of available (and free) plugins have opened up WordPress for many more purposes than just blogging: webshops even. In this tutorial we'll be going over how to install WordPress step by step, so you can get your website up and running as soon as possible! 

Before we start, we need a Linux Debian or Ubuntu installation. We'll skip that step in this tutorial since you can easily get a default Linux installation on one of your containers on the website. This tutorial is based on the cloud containers created on the page. This means that you are by default the root user, so all of the commands below don't make use of sudo. If however, you are not the root user on your system, you'll have to add "sudo" in front of the commands found in the guide below.


To start off, it's always good practice to first update our current packages:

apt update && apt upgrade -y


Before we start installing WordPress, we'll first need either a LAMP or a LEMP installation. We have some quick and easy to follow step-by-step tutorials ready for both LEMP on Debian and LEMP on Ubuntu, as well as LAMP on Debian and LAMP on Ubuntu.

When you're done installing either LAMP or LEMP, continue with the rest of this guide.


Installing additional PHP modules

With LAMP/LEMP you've already installed PHP, however, you might not have all PHP modules we're going to need for our WordPress installation. Use the following command to make sure you have all the correct PHP modules installed:

apt install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd -y


Setting up the WordPress database

Next, we'll need to create a database for WordPress to use. For this, we could either use the regular MySQL administrator (root, most likely), or create a separate user for WordPress to use. In this tutorial we'll be creating a separate user solely for WordPress' database.

Enter the MySQL command prompt as root:

mysql -u root -p

The password is the password you chose upon installing MySQL 

We'll first create a WordPress user, you could name it whatever you want but sticking to wordpress will keep things more clear and straightforward. Remember to set a good password as well!

CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress_password';


Now we have created our user, we are going to make a database which we will later grant our new user all privileges to. Create the database:

CREATE DATABASE wordpress_db;


Grant our WordPress user all priviliges to this database:

GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress'@'localhost';


Next, we reload MySQL's grant privileges tables to make our changes take effect:



Exit the terminal:




Installing WordPress

Now we have prepared our server to host our WordPress website, it's finally time to install WordPress itself. 


Download and install WordPress

Since you might be using this server to host other services as well, navigate to your html folder and install WordPress here:

cd /var/www/html


Download and unpack the latest version of WordPress:

wget -c && tar -xzf latest.tar.gz

You can now remove the .tar.gz package to preserve disc space:

rm latest.tar.gz


Configuring WordPress

You will now have the WordPress directory next to you index.html file. The next step is to give the WordPress folder the proper permissions using the following commands:

chown -R www-data:www-data /var/www/html/wordpress && chmod -R 755 /var/www/html/wordpress


Navigate into your WordPress folder:

cd wordpress


Here, you'll find all sorts of files (list them using ls), one of which is a template we can use for our WordPress configuration. This file is called "wp-config-sample.php", we're going to want to rename this file simply "wp-config.php".

 mv wp-config-sample.php wp-config.php


Open the file in your editor, I'm using Nano, but you can use whichever you want:

nano wp-config.php

Look for this part of the file, as we'll have to edit a few things here:


Replace database_name_here, username_here and password_here with the appropriate values in accordance with our WordPress database.


Now, restart both Apache and MySQL with the following commands:

service apache2 restart && service mysql restart


The server-side installation is now finished! Navigate your browser to the IP/domain of your server, followed by "/wordpress"


You will enter a page that asks for your preferred language, choose one and click continue.

You'll be redirected to a form to finalize your WordPress installation:

Fill in the form and press install.


Congratulations, you've just installed WordPress on your machine, have fun blogging!


Comments are turned off.