How to install and configure the LAMP server on Ubuntu

s2 0

LAMP, or LAMP stack, is a very useful open source development platform designed for Linux. It’s called LAMP because it uses Linux as its operating system. Apache as a web server, MySQL as a relational DBMS and PHP as a scripting language. Installing LAMP on Ubuntu is pretty straightforward. This article describes a very convenient way to install and configure LAMP on your Ubuntu system.

The commands and procedures described in this article were run on an Ubuntu 18.04 LTS system.

LAMP installation

Let’s follow these steps to easily install LAMP on our system:

Step 1: Install the tasksel package

In this tutorial we install LAMP on our systems using the tasksel utility. It is therefore important to check whether tasksel is installed on your system or not. Run the following command as root in your Ubuntu terminal to install Tasksel:

$ sudo apt install tasksel

Enter Y to continue the installation.

Step 2: Install LAMP with Tasksel

Use the following command to install the LAMP server as sudo via Tasksel:

$ sudo tasksel install lamp-server

Your LAMP package will be installed as follows:

Step 3: check the LAMP installation

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

Example:

Let’s create a PHP information page by entering the following command into our terminal:

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

Check the LAMP installation

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

http: //localhost/phpinformation.php

The following page will verify 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 advisable to configure it according to your needs.

Secure MySQL

If you want to use your LAMP server in production, it is best to back up your MySQL installation. To do this, run the following command:

$ sudo mysql_secure_installation

You can then use the output to remedy the situation to secure the root password and other security configurations.

Configure the firewall

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

$ sudo ufw allow in "Apache Full"

Configure the UFW firewall

This configuration allows inbound traffic on two ports, TCP 80 and TCP 443.

Install PHP modules

You can customize PHP modules for use with LAMP that are not already shipped with the LAMP installation. First, let’s make a list of the modules that you can select using the following command:

$ apt-cache search ^php- | grep module

Looking for additional PHP modules

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

Syntax:

Install $ sudo apt [module-name]

Example:

$ sudo apt install php7.2-zip

Install additional PHP module

In this article, you learned how to install and configure LAMP on your Ubuntu system. This included installing LAMP using Tasksel and then checking the installation by creating a .php example file. In addition, you can also configure LAMP to make it safer and more user-friendly by following the steps outlined above.

How to install and configure the LAMP server on Ubuntu