Categories: LinuxUbuntu

How to Install and Configure LAMP Server on Ubuntu

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

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:

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"

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.

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"

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

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

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.

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. You can reach Karim on LinkedIn

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago