Installing WordPress on Ubuntu 18.04 LTS

In this post, we will deploy a server with Ubuntu 18.04 LTS and install WordPress on it.

The installation of Ubuntu Server is straightforward. The only step we need to pay attention to, is the static IP. It will make the things easier later.

Once Ubuntu is installed, we need to run the two simple, yet important commands:

sudo apt update
sudo apt upgrade

Once this is done, we will install the Apache web server:

sudo apt install apache2

If everything went well, we should see the Apache default configuration page on our browser:

Next, we will install the MySQL database engine, and secure the installation (we will choose a password for the MySQL root user during this step):

sudo apt install mysql-server
sudo mysql_secure_installation

Then, we will install php and some additional modules:

sudo apt install php libapache2-mod-php php-mysql

Once this is done, we will restart and enable Apache:

sudo systemctl restart apache2
sudo systemctl enable apache2

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

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 !

Note: If we want this WordPress installation to be available on the internet, by forwarding port 80 to the IP address of the server and add a domain to it, it is a good practice to add a SSL certificate to our server. Check my post about adding free ssl certificate in ubuntu with let’s encrypt

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 !