Linux Technology

WordPress Setup on Debian 8 with Apache 2 and MySQL

I have this idea to create my own website since a long time ago, but it seems too complicated to do all these steps manually and I’m too lazy to start from the beginning. There are existing solutions for hosting a site, but that’s not my style. I won’t opt for a one-click interface to go through all processes magically. This time, I finally make up my mind and managed to publish this post on my site. I will share what issues I’ve conquered and steps to make one site of your own.

Before started, we need to know how the pipeline looks like:

  1. Rent a server or virtual server that also has a public IP address.
  2. Buy a domain that can be linked to your IP address.
  3. Setup DNS records.
  4. Setup the server environment.
  5. Install WordPress.

Virtual Server

For the Virtual Private Server (VPS), I selected Netcup’s product: VPS 200 G8, which includes 1 vCore, 2 GB RAM, 20 GB SSD, 40TB traffic, 1000 1000 MBit/s, 1 IPv4 address, etc. for a monthly price at 2.71 €. Since this VPS has Debian 8 installed, hence the following tutorials are based on this specific OS. Basically, any virtual server that satisfied the requirements can be used.

Buy a Domain

Here it doesn’t have any restrictions as well. You can buy any domain with your desired name on any site that offers domain registration. I bought this domain: on Namecheap. There is also another famous site like GoDaddy.

Setup DNS Records

This step you need to complete it on the domain registration site of your choice (a.k.a we use the default name server from where we bought the domain). For example, I bought from Namecheap, so I need to set it in the account management panel. If you use another service, the general concept behind this step is the same. You need to find where to set A record for your domain.

If you plan to use a different name server, it’s not discussed here. The following bullet list showed the steps to find where to set records in Namecheap.

  • Log into your account in Namecheap.
  • Then click ‘Domain List’ on your left side of the panel. Your domains will be listed there.
  • Select your domain and click the ‘manage’ button.
  • Click ‘Advanced DNS’ on the top menu bar.
  • We can add records in the first ‘Host Records’ section by clicking the ‘ADD NEW RECORD’ button.

Next, we add two A-type records:

#Type    #Host    #Value    #TTL
  A        @      your ip   auto
  A       www     your ip   auto

@ will direct your site to your destination IP without www prefix, e.g., while www will direct to your IP. For a detailed explanation and how a name server works, you can read the article from this link.

VPS Environment

Because we will use Apache, MySQL, and PHP to run WordPress, these components are required. They are actually installed already on my VPS, but some of them are old. I prefer to upgrade them. Otherwise, in WordPress site health, it will show you some warnings which are annoying to me.

Upgrade PHP

Some of you can do it on your VPS management panel like cPanel with few clicks. But mine isn’t lucky, I have to do it manually.

Inspired by Ayesh’s post, I used Ondřej Surý’s awesome PHP PPA. We need to add the PPA and update the package information.

sudo apt install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg
sudo sh -c 'echo "deb $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update

Then, we note down the current PHP packages into a text file, so we know what to install for the latest version.

dpkg -l | grep php | tee packages.txt

You can see all the packages listed in the text file start with phpx.y- prefix where x.y is the old version number. What we going to do is substituting the old version x.y to the desired version php7.3- in this case. We can install the packages using the command below:

sudo apt install php7.3 php7.3-cli php7.3-common php7.3-curl php7.3-gd php7.3-imap php7.3-json php7.3-mysql php7.3-readline libapache2-mod-php7.3

Note that libapache2-mod-php7.3 is used for Apache server with prefork MPM (check with apachectl -V command). You may need to use php7.2-fpm for your web server.

Next, we need to enable the installed PHP packages and disable the old ones.

sudo a2enmod php7.3
sudo a2dismod php5

Finally, restart the Apache server using:

sudo service apache2 restart
Upgrade MySQL

The latest version of MySQL should provide better stability and performance. Before we start any modification, let’s backup our database:

mysqldump --all-databases > backup_databases.sql

Firstly, we need to download the Debian package for installing MySQL. You can check the latest package from Oracle’s MySQL APT Repository and change the deb file’s name.


Then we install the downloaded package:

sudo dpkg -i mysql-apt-config_0.8.14-1_all.deb

You will see a configuration dialog in the terminal screen with three options to determine which product to configure. You can use the arrow keys and enter key to navigate. In the first option, we select mysql-5.7 to be installed. In the second option, we enable MySQL Tools & Connectors. For the last option, we disable preview packages.

Next, we update the MySQL package before upgrading:

sudo apt-get update

Now, we can install the new MySQL server:

sudo apt-get install mysql-server

Don’t forget to upgrade the existing database (you need your MySQL’s root account and password):

sudo mysql_upgrade -u root -p

Finally, we need to restart the service:

sudo /etc/init.d/mysql restart

Install WordPress

The last step is easy since we already have Apache server, PHP and MySQL installed. Firstly, let’s download WordPress from web:


Next, unzip the archive:

tar -xzvf latest.tar.gz

Then, we move the wordpress folder to the Apache server root /var/www/. This root folder may change based on different configurations.

mv wordpress/ /var/www/

Before visiting your website, we have to create a specific user with all privileges and a database in MySQL. You may change the username and the password as well as the name of the database in the following code. The user can connect to the MySQL server from this VPS only (localhost). If you want to access from any host, substitute localhost to %.

# log into MySQL
mysql -u root -p

# create a new user 
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';

# create a database
USE dbname;

# Grant all privileges
GRANT ALL PRIVILEGES ON dbname.* TO 'your_username'@'localhost';

Next, you should edit a wp-config.php file before running the program. However, this step can be skipped now. You can directly visit your WordPress site to initialize the setup process when you first time opens the site.

If you choose to edit a configuration file…

Copy wp-config-sample.php to wp-config.php

# cd to wordpress folder
cd /var/www/wordpress/

# use a sample config
mv wp-config-sample.php wp-config.php

Then edit the configuration file and edit the following entries based on your setup:

vim wp-config.php

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'dbname' );

/** MySQL database username */
define( 'DB_USER', 'your_username' );

/** MySQL database password */
define( 'DB_PASSWORD', 'your_password' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

If you put wordpress folder in /var/www/ and set up your DNS records correct, you should be able to visit your site from (In this case You will be prompted to create an admin user when the first time logged in.

If you don’t want to write a configuration file…

You can directly visit your site at (In this case without a configuration file. However, you will have to fill in a form before creating an admin user. In this form, you need to provide the DB_NAME, DB_USER, DB_PASSWORD, etc.

Plugins Issues

After you managed to run WordPress on your VPS, you probably will find that when you install a plugin, you need to provide an FTP account. This is because the user of wordpress folder doesn’t have the permission to write files.

To avoid this issue, there are many solutions online, but I found this one works without change any configurations. You basically just need to change the owner of the wordpress folder to a user who has permission to write in Apache’s root folder (e.g. www-data).

chown -R www-data:www-data /var/www/wordpress/

Finally, we can add plugins without requiring an FTP account. And that’s it! WordPress should now be installed.

By 533

♥️•🏊•💪🏻 •🐈•📷
•IG: @53333_ @xᴜɴxᴜɴ_ɢʀᴀᴄᴇ
•TW: @SimonNg533

Leave a Reply

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.