LAMP is a popular stack of software that is commonly used for hosting web applications. It stands for Linux, Apache, MySQL, and PHP. In this article, we will guide you through the process of installing LAMP on Ubuntu 20.04.
Before we begin, make sure that you have a fresh installation of Ubuntu 20.04. You will also need to be logged in as a user with sudo privileges.
Install Apache
The first step is to install Apache, the web server that will host our web application. To do this, open a terminal and run the following command:
sudo apt-get update
sudo apt-get install apache2
This will download and install Apache on your system. Once the installation is complete, you can verify that Apache is running by visiting http://localhost
in your web browser. You should see the default Apache web page.
Install MySQL
Next, we need to install MySQL, the database server that will store our web application’s data. To do this, run the following command in the terminal:
sudo apt-get install mysql-server
During the installation, you will be prompted to set a password for the MySQL root user. Make sure to choose a strong password and remember it, as you will need it later.
Once the installation is complete, run the following command to secure your MySQL installation:
sudo mysql_secure_installation
You will be asked to enter the password for the MySQL root user that you set earlier. After that, you will be presented with a series of questions. It is recommended to answer "yes"
to all of them, as this will enable some additional security features.
Install PHP
The last piece of the LAMP stack is PHP, the scripting language that will be used by our web application. To install PHP, run the following command in the terminal:
sudo apt-get install php libapache2-mod-php php-mysql
This will install PHP and the necessary modules for it to work with Apache and MySQL.
Test your LAMP stack
To verify that your LAMP stack is working properly, you can create a test PHP file. To do this, open a terminal and run the following commands:
sudo nano /var/www/html/info.php
This will open the Nano text editor and create a new file called info.php
in the Apache web root directory. In the editor, paste the following PHP code:
<?php
phpinfo();
?>
This code will display information about your PHP installation. Save the file and exit the editor.
To access the info.php
file from your web browser, visit http://localhost/info.php
. You should see a page with information about your PHP installation, indicating that your LAMP stack is working properly.
Congratulations! You have successfully installed LAMP on Ubuntu 20.04. You can now use this stack to host your own web applications.