How to Install and Configure LAMP Server on Ubuntu 20.04

Foreword How to Install and Configure LAMP Server on Ubuntu 20.04

Why you should use Ubuntu LTS release as the development platform

The reason I use Ubuntu LTS releases as a platform to develop a 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 Server on Ubuntu 18.04.

ubuntu logo

First of all I use Ubuntu 20.04 as the example in this howto. 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 is 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.

Install and Configure LAMP Server on Ubuntu.

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

How to Install and Configure LAMP Server on Ubuntu 20.04

 

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.

Setting up the LAMP server apache2 userdir modules.

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.

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>
<Directory /home/[username]/public_html>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
</IfModule>

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

 

By default PHP is disabled in user directories (for security purposes).

And 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 and 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
</Directory>
</IfModule>

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>
#</IfModule>

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 and 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 Host name: 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

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 18.04 click the 3×3 dots in the bottom left corner and type Files or Nautilus. And make sure that folder exists.

Ubuntu 18.04 Desktop

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.

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. 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.

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 fully done.  Hope this guide was helpful. Leave your comment below.

 

 

 

 

COMMENTS