Install WordPress on Ubuntu 16

In this post,  we will setup a server and install WordPress on it. My distribution of choice is Ubuntu Server, version 16.04 LTS. I happen to like the non-GUI interface, so everything will be done in the terminal. I will make this as short as possible. Let’s start!

The server has 1 virtual processor and 1 GB of memory. More than enough for a home test server running WordPress. Use the default settings during install. At the end, when asked about packages to add, choose these three:

When asked, set a password for MySQL root user and remember it.

After installation, update the server:

sudo apt update
sudo apt upgrade

There is a good idea to set up a static IP for the server. Open and edit this file:

sudo nano /etc/network/interfaces

Replace this:

iface [your adapter name] inet dhcp

with this:

iface [your adapter name] inet static
address 192.168.1.10 (or whatever IP you wish to assign to it)
netmask 255.255.255.0
gateway 192.168.1.1 (the address of your router)
dns-nameservers 192.168.1.1

Save and close the file with Ctrl-O and Ctrl-X. Reboot the server to reflect the changes.

Next, we are going to create a MySQL database for WordPress:

sudo mysql -u root -p
create database wordpress;
GRANT ALL ON wordpress.* TO ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘password’;
flush privileges;
exit

Choose your own database name, user and password. We will need them later.
A good practice is to secure the mysql installation. Run this command:

sudo mysql_secure_installation

Answer no the the first two questions and yes to the rest.

Next, edit the Apache configuration file:

sudo nano /etc/apache2/apache2.conf

Copy and paste the following block of text at the end of the file:

<Directory /var/www/html/>
AllowOverride All
</Directory>

Ctrl-O to save the changes, and Ctrl-X to close the file.
Next step is to enable mod_rewrite module:

sudo a2enmod rewrite
sudo systemctl restart apache2

Now comes the beautiful part of installing WordPress:

wget -c http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

After downloading and unzipping the files, we will copy everything in the web directory:

sudo rsync -av wordpress/* /var/www/html/

Give the right permissions for the web directory:

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

We need to rename the sample configuration file and edit it:

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

Put the values that you choose earlier for your database_name, db_user and db-password. Leave everything else as it is.

Save and close the file.

One more thing: remove the index.html file from the web directory, since wordpress uses an index.php to run.

sudo rm index.html

Reboot.

After reboot, open the IP address of your server in a browser, fill out the required fields, click on Install WordPress and start blogging !

Leave a Reply

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