How can we help?
Categories
< All Topics
Print

Installing LAMP in Ubuntu

LAMP (Linux, Apache, MySQL, PHP) is a software stack that is quite popular for Ubuntu users to host dynamic websites and web applications written in PHP.

To use LAMP properly, we must install Apache, MySQL, and PHP packages individually. Here are the steps for installing and configuring LAMP in the ServerStadium Virtual Machine that uses the Ubuntu operating system.

Step 1 – Installing Apache2

Apache2 is the most famous web server with the most users worldwide. Therefore, it still is a great choice for hosting a website.
To begin with, update the Ubuntu repository with the command :

# apt update

Then, install the Apache2 package with the command :

# apt install apache2

Don’t forget to add port 80 to the Network Security Profile. For example, I’m allowing all IP Addresses to access port 80 on this Virtual Machine.

After that, access the Virtual Machine Public IP Address with a web browser. If the installation succeeds, it should display the Apache2 Ubuntu Default Page, as shown below.

Step 2 – Installing MySQL

If Apache2 is a web server, MySQL acts as RDBMS (Relational Database Management System) on LAMP. MySQL is a Database Management System that is quite popular for the PHP programming language.
To install MySQL on Ubuntu, type the command :

# apt install mysql-server

After the installation process is complete, running a series of processes aimed at improving MySQL security is recommended. To run the process, type the command :

# mysql_secure_installation

A new message will pop up; there is an option if you want to enable the “VALIDATE PASSWORD” feature.

This tool checks the password strength and allows MySQL users to set only those passwords which are secure enough. There is 3 level :

- LOW --> Length >= 8
- MEDIUM --> Length >= 8, numeric, mixed case, and special characters
- STRONG --> Length >= 8, numeric, mixed case, special characters, and dictionary

Press y / Y if you want to use “VALIDATE PASSWORD” or press n / N if you don’t want to use it.

Set the root MySQL user password by filling in these prompts with your desired password.

Removing the “anonymous” MySQL users before moving into a production state is advised. Press y / Y to remove the “anonymous” MySQL user on the next pop-up.

Then, to secure MySQL from a remote connection. Root login by remote access has to disable on the next pop-up.

Same with the anonymous MySQL user, it is advised to remove “test” named database before moving into a production state. Press y / Y to remove “test” named database on the next pop-up message.

Press y / Y to reload the privilege tables so the several configurations above will apply.

To test the MySQL root user locally, test it by typing the command :

# mysql -u root -p

Then, fill in the password on the password prompt that appears.
The MySQL prompt will appear and be ready to use if the credential is correct.

Remember, if you want to use the MySQL remote connection, add port 3306 to the Network Security Profile that the Virtual Machine uses.

Step 3 – Installing PHP

We have Apache2 and MySQL installed as a part of the LAMP installation. PHP is needed in this 3rd step as a scripting language for LAMP. According to w3techs data, PHP is used by 78,9% of websites on the internet. This makes PHP a good choice for a server-side programming language for your website.

Install PHP by typing the command :

# apt install php php-mysql libapache2-mod-php

Explanation :

- php : php core package
- php-mysql : PHP module that allows PHP to communicate with MySQL-based database
- libapache2-mod-php : PHP module that enable Apache2 to handle PHP files

After PHP is installed, you can check the PHP version by typing the command :

# php -v

To test the PHP installation and see the installed PHP’s complete info, make a new PHP file on /var/www/html directory with any text editor and name it info.php. The content of the info.php must be like below :

<?php
        phpinfo();
?>

Save the file, and then access it from the web browser by URL :

http://YOUR_VM_IP_ADDRESS/info.php

As we can see info.php file displayed complete information for PHP that was installed on the Ubuntu ServerStadium Virtual Machine.

Congratulations! You have now configured a LAMP stack on Ubuntu ServerStadium Virtual Machine.

Conclusion

In this guideline, we have installed and configured LAMP stack on the Ubuntu Virtual Machine ServerStadium environment for serving PHP websites and applications using Apache2 as a web server and MySQL as a database management system.

Table of Contents