Installing LAMP on Ubuntu 20.04.1 LTS Desktop / Server

Here are the steps to be followed for installing LAMP on Ubuntu 20.04.1. LAMP stands for Linux, Apache, MySQL and PHP. LAMP setup on your desktop can enable your local web development, whereas in server facilitate you to host your web contents.

  • Update and Upgrade your Ubuntu Desktop/Server
  • Install Apache web-server
  • Install MariaDB (the community supported alternative for MySQL)
  • Install PHP and PHP-MySQL packages
  • Inline steps to enable required services, open required ports

Update and Upgrade your Ubuntu Desktop/Server

First step is to update your OS, follow this as the best practice before you install any new software, this also brings in better security and reliability of your Desktop or Server.

sudo apt update
sudo apt upgrade

Install Apache webserver

Now, install Apache Webserver. There are other popular alternatives for Apache, such as nginx, however here we will use Apache

# Installing apache
apt install -y apache2 apache2-utils

# Change the ownership of your web html directory
chown -R www-data:www-data /var/www/html

# Start Apache HTTPD service
systemctl start apache2

# Checking Apache HTTPD server status
systemctl status apache2

# Enable this service, so Apache would start automatically after restarts
systemctl enable apache2

Install MariaDB (the community supported alternative for MySQL)

Now, let us install MariaDB Database

# Install MariaDB server and Client
apt install -y mariadb-server mariadb-client

# Start MariaDB database server
systemctl start mariadb

# Checking MariaDB status
systemctl status mariadb

# Execute mysql_secure_installation to configure MySQL database
mysql_secure_installation

# Checking your Database version
mariadb --version

Install PHP and PHP-MySQL packages

# Oneliner to install PHP7.4 and related packages for MySQL connectivity.
# You may customize to suite your needs or install additional packages later
apt install -y php7.4 php-common libapache2-mod-php7.4 php7.4-mysql php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline

# Restart Apache after your PHP installation
systemctl restart apache2

Open required ports

If you want to provide access to your LAMP webserver over the network, open the HTTP port 80

# Opening HTTP port 80
sudo ufw allow http

With this, we have completed all steps to install and configure Linux, Apache MySQL/MariaDB and PHP (LAMP webserver) on Ubuntu 20.

How to check whether Apache and MySQL process are running?

Here are the commands to verify whether your webserver and database are running, this will help you to troubleshoot better.

# Checking mysql process status
dev@ubuntu:~$ ps -ef | grep mysql
 mysql       1002       1  0 08:27 ?        00:00:28 /usr/sbin/mysqld
 dev         8490    7111  0 11:19 pts/1    00:00:00 grep --color=auto mysql

# Checking Apache process status
 dev@ubuntu:~$ ps -ef | grep apache
 root        1042       1  0 08:27 ?        00:00:01 /usr/sbin/apache2 -k start
 www-data    1051    1042  0 08:27 ?        00:00:00 /usr/sbin/apache2 -k start
 www-data    1052    1042  0 08:27 ?        00:00:00 /usr/sbin/apache2 -k start
 www-data    1053    1042  0 08:27 ?        00:00:01 /usr/sbin/apache2 -k start
 www-data    1054    1042  0 08:27 ?        00:00:00 /usr/sbin/apache2 -k start
 www-data    1055    1042  0 08:27 ?        00:00:00 /usr/sbin/apache2 -k start
 www-data    3374    1042  0 08:54 ?        00:00:00 /usr/sbin/apache2 -k start
 www-data    7944    1042  0 10:42 ?        00:00:00 /usr/sbin/apache2 -k start
 dev         8492    7111  0 11:19 pts/1    00:00:00 grep --color=auto apache