LAMP or LAMP stack is a very useful open-source development platform designed for Linux. It is called LAMP as it uses Linux as an OS, Apache as the webserver, MySQL as Relational DBMS and PHP as the scripting language. Installing LAMP on Ubuntu is fairly simple. This article describes a very convenient way to install and configure LAMP on your Ubuntu system.

The commands and procedures described in this article have been run on a Ubuntu 18.04 LTS system.

LAMP Installation

Let us follow these steps in order to easily install LAMP on our system:

Step 1: Install the tasksel package

In this tutorial, we are installing LAMP on our systems through the tasksel utility. Therefore, it is important to verify if tasksel is installed on your system or not. Run the following command as root in your Ubuntu Terminal in order to install tasksel:

$ sudo apt install tasksel

Install Tasksel

Enter Y in order to continue installation.

Step 2: Install LAMP using tasksel

Use the following command in order to install the LAMP server as sudo through tasksel:

$ sudo tasksel install lamp-server

You LAMP package will be installed in the following manner:

Install LAMP server with tasksel

Step 3: Verify LAMP Installation

You can verify if your LAMP installation is working properly or not by creating a sample PHP page.

Example:

Let us create a PHP information page by entering the following command in our Terminal:

$ sudo bash -c "echo -e '<?php\nphpinfo();\n?>' > /var/www/html/phpinformation.php"

Verify LAMP install

You can access this page on your localhost by entering the following link in your browser:

http://localhost/phpinformation.php

The following page verifies that LAMP has been properly installed on your system.

PHP info on Ubuntu LAMP Server

Configure LAMP (Linux Apache MySQL and PHP)

After installing LAMP, it is a good idea to configure it according to your needs.

Secure MySQL

If you wish to use your LAMP server in production, it is best to secure your MySQL installation. To do so, run the following command:

$ sudo mysql_secure_installation

You can then workaround with the output to secure root password and other security configurations.

Configure Firewall

To configure your firewall, run the following command as sudo:

$ sudo ufw allow in "Apache Full"

Configure UFW Firewall

This configuration will allow incoming traffic on two ports, TCP 80 and TCP 443.

Install PHP Modules

You can customize PHP modules to be used with LAMP other than the ones that already come with the LAMP install. First, let us grab a list of the modules you can choose through the following command:

$ apt-cache search ^php- | grep module

Search for additional PHP modules

You can then install any of these modules through the following command:

Syntax:

$ sudo apt install [module-name]

Example:

$ sudo apt install php7.2-zip

Install additional PHP Module

Through this article, you have learned how to install and configure LAMP on your Ubuntu system. That included installing LAMP through tasksel and then verifying the installation by creating a sample .php file. Moreover, you can also configure LAMP to make it more secure and usable through the steps described above.

How to Install and Configure LAMP Server on Ubuntu
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.