How to install WordPress on Ubuntu 18.04

Install WordPress on Ubuntu 18.04 in just a couple of steps, it will be secure and you will directly be able to make use of your freshly installed WordPress website.

We have explained two ways on how you can install WordPress on Ubuntu 18.04, the fast way, which is a list of all the commands you need to follow to install WordPress, and the second, which is a step by step guide.

We strongly recommend to make use of the step by step guide, as this will provide more details. It also contains screenshots, so that you can verify if you are getting the same results.

Clean Ubuntu 18.04 Terminal

How to install WordPress on Ubuntu 18.04

Install WordPress on Ubuntu is easy, in this guide, we will make use of the software package LAMP, and we will install some PHP and of course, we will download and install WordPress on your Ubuntu 18.04 system.

The fast way of Installing WordPress on Ubuntu

If you do not have a lot of time left, and you want to install WordPress, then we have made this list for you. In the list below, you will find 16 commands that you need to execute, once these commands have been executed, you can enjoy your freshly Ubuntu installed WordPress website.

The 16 steps to install WordPress on Ubuntu 18.04 are:

  1. sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc
  2. sudo tasksel install lamp-server
  3. sudo mysql_secure_installation
  4. sudo ufw allow in “Apache Full”
  5. sudo mysql -u root -p
  6. create database wordpress;
  7. create user ‘wpdb’@’localhost’ IDENTIFIED BY ‘your-freshly-generated-password’;
  9. exit;
  10. cd /var/www/html
  11. ls
  12. sudo rm index.html
  13. wget
  14. sudo tar xpf latest.tar.gz
  15. sudo cp -R /var/www/html/wordpress/* /var/www/html/
  16. sudo rm -rf wordpress
  17. sudo chown -R www-data:www-data /var/www/wordpress

The step by step guide way

If you want to install WordPress step by step, then this part is for you. We have listed down the commands, and we have included the screenshots that will provide additional information so that you can verify if the installation is going as wanted.

Install PHP

In this part we will install the webserver software (LAMP) that will allow the WordPress website to be viewed.

LAMP stands for Linux, Apache, MariaDB/MySQL and PHP

The installation command is:

$ sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc

followed by the installation of LAMP

$ sudo tasksel install lamp-server
The screen you should see after running the PHP installation commands

Time to setup MYSQL in a more secure way

Now that we have MySQL on the system, we will make sure that we have a default secure MySQL installation. In order to do this, we need to enter the command shown below.

$ sudo mysql_secure_installation 
the result after running mysql_secure_installation

Add some rules to the Ubuntu Firewall

$ sudo ufw allow in "Apache Full"
Adding port 80 and port 443 access to the website

Login to Mysql

$ sudo mysql -u root -p
Login at MySQL

Create the database for WordPress

$ create database wordpress;
Database creation in MySQL

Create WordPress DB user

$ create user 'wpdb'@'localhost' IDENTIFIED BY 'your-freshly-generated-password';
creation of the user wpdb

Flush the priviliges


Exit MySQL

$ exit;

Download and install WordPress

Now we will download and install WordPress, but before we continue, we will remove all the default files that are not needed in the /var/www/html folder, afterwards, we will move WordPress to that folder.

Remove default files

Alright, let’s remove the default files by following the commands below.

$ cd /var/www/html
$ ls
$ sudo rm index.html
Navigate to /var/www/html and delete index.html

Download WordPress

It is time to download WordPress, we have setup the LAMP environment, we did some small security configurations, and now we need to download, install and configure WordPress.

Download the latest version

Always download the latest version from the official WordPress website.

$ wget

Unpack WordPress

The download is a tar.gz file, we need to unpack this with the tar command.

$ sudo tar xpf latest.tar.gz
WordPress downloaded and unpacked

Lets place WordPress in the /var/www/html folder

Instead of having the folder ‘WordPress’, we will move the content of that folder, one layer up, so we can remove the foldername WordPress.

$ sudo cp -R /var/www/html/wordpress/* /var/www/html/
The result of the copy
$ sudo rm -rf wordpress
Remove all the folder WordPress

Make sure to set the permissions correct

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

Navigate to your website IP address or domain, and follow the WordPress installation wizard.

Share This Message