Ultimate Guide: LAMP Stack and WordPress on Ubuntu 20.04

Ultimate Guide: LAMP Stack & WordPress on Ubuntu 20.04

Foreword How to Install  LAMP Stack on Ubuntu 20.04

A local installation of WordPress is a must if you do a lot of WordPress Theme and website development work. You don’t need to keep uploading files back and forth clearing cache. Another reason is that you can see all your changes instantly. For this reason I decided to write this extensive tutorial that walks you through the whole process step by step on how to install the LAMP Stack on Ubuntu 20.04.

There are a lot of tutorials out there that is written for Ubuntu 18.04 and 16.04. This guide is for Ubuntu 20.04. Although the 18.04 might work for the latest 20.04 release, I cannot guarantee that it works.

It is extremely important to follow each step carefully.

Why you should use Ubuntu 20.04 LTS  (Long Term Support)  release as the development platform

The reason I use Ubuntu LTS releases as a platform to develop a WordPress website for the reason that it is more secure and transparent and it is rock stable and has 5 years of support. The tools work better. It’s faster to run a web server on GNU/Linux then Windows and you can use dual boot, or run it in a a virtual machine like VirtualBox as well. This is why I wrote this guide on How to Install and Configure LAMP Stack on Ubuntu 18.04.

ubuntu logo

First of all I use Ubuntu 20.04 as an example in this guide. Ubuntu is the most widely used GNU/Linux distribution operating system in the world. And I highly recommend using the LTS (Long Term Support) version for this as it is supported for 5 years. There are many other (flavors) of Ubuntu, for example Lubuntu, Xubuntu, Ubuntu Mate, Kubuntu. And ZorinOS these are all based on Ubuntu as well.

If Gnome isn’t your choice you could try a different Ubuntu 18.04 “flavor” like Xubuntu (XFCE), Ubuntu Mate (MATE), Lubuntu (LXQT) or any other “flavor” which might be a little lighter on system resources. ZorinOS 15.1 Lite could also be a possibility, which is what I use.

This tutorial will work on all Ubuntu based distributions because the core system is all the same.


Updating Ubuntu 20.04 before installing the LAMP Stack

Before we start with the installation process we want to make sure everything is up to date, so there are no conflicts. To do this Right Click on the desktop and select terminal. and type the following commands.

sudo apt-get update

sudo apt-get upgrade

These commands make sure your system has all the updates and this prevents security issues.


Installing the LAMP Stack on Ubuntu 20.04.

Lets get to work and install the LAMP Stack and all of the modules.

Right Click on a open spot on the desktop and click Open Terminal, at the Terminal type the following
sudo tasksel install lamp-server
This will install all the modules to run WordPress.


Configuring The Lamp Stack

Setting up the LAMP Stack apache2 userdir modules.

The LAMP stack is installed, now lets make life easier. This way it is easier to work so you are working and staying in your home directory.

After this process is done type the following at the command prompt.

I know I might get some bad replies for this one, and some people don’t agree with running Apache web server as a user. Everything has it’s drawbacks. The reason we do this so that we can update plugins and keep the right file permissions. We are not going to run it live, only locally.

sudo gedit /etc/apache2/envvars and add the following lines.

replace [username] with your username.

export APACHE_RUN_USER=[username]
export APACHE_RUN_GROUP=[username]


Next step is to make sure it looks like this next we need to make sure the files are being read in your home directory [public_html] to do this we check and make sure it is enabled and that we have the right permissions.

And replace [username] with your username.

sudo gedit /etc/apache2/mods_enabled/userdir.conf

<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root

<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
<Directory /home/[username]/public_html>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


By default PHP is disabled in user directories (for security purposes). We will only use the installation locally.

We need to enable PHP for the userdir module, to do this we need to comment out some lines.

sudo gedit /etc/apache2/mods_enabled/php7.2.conf

Comment out as explained in the file.

# Running PHP scripts in user directories is disabled by default
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off

and make it look like this.

# Running PHP scripts in user directories is disabled by default
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
# <IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>

Setup MYSQL & phpMyAdmin


I personally recommend installing phpMyAdmin to manage and create MYSQL databases. If you haven’t setup up MYSQL yet type the following: mysql_secure_installation

And answer the questions as shown below:

Change the root password? [Y/n] <-- y
New password: <-- Enter a new MySQL root password
Re-enter new password: <-- Repeat the MySQL root password
Remove anonymous users? [Y/n] <-- y
Disallow root login remotely? [Y/n] <-- y
Remove test database and access to it? [Y/n] <-- y
Reload privilege tables now? [Y/n] <-- y 

Next we are going to install phpMyAdmin to make things easier to manage our databases.
sudo apt install phpmyadmin
phpMyAdmin should now be accessible. open your web browser and type the following. localhost/phpmyadmin

This should bring you to the login page of phpMyAdmin. Now log in as root.

phpMyAdmin screenshot

Next click add user account and follow the directions, just make sure the hostname: is set Local and that Native MYSQL Authentication for the Authentication Plugin.

Next log in as the user you just created and create a database, keep the name as simple as possible and leave Collation as is.


Now we are ready to install WordPress.

WordPress Logo

Now the Lamp Stack is installed its time to install WordPress. Lets go to wordpress.org and click Download WordPress 5.4.x

Now open the file manager. and make sure public_html directory exists in your home folder. to do that in Ubuntu 20.04 click the 3×3 dots in the bottom left corner and type Files or Nautilus. And make sure that folder exists.


Extracting the WordPress files


Next double click the Downloads folder, this is where the WordPress zip file is. Right click and extract the archive in the public_html directory.

Open the public_html directory and make sure it is extracted properly, if it’s extracted in the wordpress folder double click the wordpress folder, select all the file with CTRL+A and then CTRL+X click the back button to go back to public_html and with your keyboard shortcut CTRL+V to paste the files in the right directory.

Open your Firefox browser and go to localhost/~[username]and follow the directions. If it fails to write to the wp-config.php copy the content it shows in the browser and paste it into the wp-config.php file and save it.


Set WordPress FS_METHOD to Direct to make updates work.

That’s it, I know its challenging but its worth it. Now we have a lightweight, secure development system to test and can develop your own themes. But we need to edit one last thing to be able to update plugins and also install plugins and themes.

Add the following line in wp-config.php  define('FS_METHOD', 'direct');

This will avoid issues if you decide to install update themes and plugins.

Enable WordPress Debug mode

Now we want to be able for WordPress to show errors warnings, add thew following line also to wp-config.php define( 'WP_DEBUG', true );

Lets start developing your own themes.



Now we are done.  Happy coding and experimenting without all the hassle of uploading files and clearing cache!

Hope this guide was helpful. If you have any questions or comments feel free to leave your comments below in the comment section and don’t forget to check out our other articles.





One thought on “Ultimate Guide: LAMP Stack and WordPress on Ubuntu 20.04