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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s