
Table of Contents
Install LAMP stack on Ubuntu
LAMP stack is a set of packages such as Linux, Apache, MySQL, and PHP. LAMP stack is used for hosting Websites and Apps. In this tutorial, you are going to learn How to install LAMP stack on Ubuntu.
Prerequisites
Before you start to install LAMP stack on Ubuntu 18.04. You must have the non-root user account on your server/desktop with sudo privileges.
1. Install Apache
First, you will need to update the package manager index by typing
sudo apt update
Now install Apache by running following command
sudo apt install apache2
Confirm the installation of Apache by using the following command
sudo systemctl status apache2
If you have UFW firewall enabled then you should open port 80 for HTTP and 443 for HTTPS to Apache Web Server. Enter the following commands to enable ports.
sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw reload
Now you can verify your Apache installation by visiting http://YOUR_DOMAIN_NAME/ or http://localhost/
2. Install MariaDB
Update apt package manager index by typing following command
sudo apt update
Now you can install MariaDB by running following command
sudo apt install mariadb-server mariadb-client
Check the status and confirm installation by typing following command
sudo systemctl status apache2
To secure MariaDB run following command.
sudo mysql_secure_installation
Once you execute above command you will be asked to enter current password (Press ENTER for none) then you will be asked following questions, enter y for following questions:
- Set root password? : y
- Remove anonymous users? : y
- Disallow root login remotely? : y
- Remove test database and access to it? : y
- Reload privilege tables now? : y
3. Install PHP
To install PHP you should first update package manager index then you will install PHP.
Update apt package manager index by typing
sudo apt update
Install PHP and some of its common extensions by typing
sudo apt install php php-common php-mysql php-gd php-cli
After installing PHP you can confirm installtion by creating info.php file. Run following command to create info.php file.
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Now visit http://YOUR_DOMAIN_NAME/info.php or http://localhost/info.php in your browser to confirm installtion.
Conclusion
You have successfully learned how to install LAMP stack on Ubuntu 18.04. If you have any queries regarding this please don’t forget to comment below.