Install Linux, Apache, MySQL and PHP (LAMP) in Ubuntu

How to Install Linux, Apache, MySQL and PHP (LAMP) in Ubuntu

LAMP is a group of open source software used for running web servers. LAMP stands for Linux, Apache, Mysql and PHP. In this post we will learn how to Install Linux, Apache, MySQL and PHP (LAMP) in Ubuntu step by step.

How to Setup

To install LAMP stack user need root privileges on you ubuntu distribution. see the step by step to install and configure LAMP.

1. Install Apache

Apache is open source software which runs on various web servers. To install apache2 open the terminal and type the command below :

$ sudo apt-get update
$ sudo apt-get install apache2 -y

That’s it. apache2 is installed on the system. you can check it on your browser by just typing http://localhost/ or http://yourip/ . You can check you have an available path as /var/www/html in your physical drive.

If you are not able to find your ip, you can run the command as below-

ifconfig eth0 | grep inet | awk '{ print $2 }'

You can adjust the firewall by allowing web traffic using ufw. you can check UFW using following command –

$ sudo ufw app list

Apache Full
Apache Secure

You can allow any of the incoming traffic using - 

$ sudo ufw allow in "Apache Full"

2. Install MySQL

Mysql is a open source software to manage database. install the mysql using :

$ sudo apt-get install mysql-server

if you want to have some secure installation you can run the command :
$ sudo mysql_secure_installation

this will configure the VALIDATE PASSWORD PLUGIN .

once mysql server installed, we need to create the native password to run and connect to another platform. to connect mysql just run

sudo mysql -u <username> -p

after entering your password you will be entered to mysql console. Now write mysql query to set mysql native password. Write the query as below :

mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';


mysql > exit;

3. Install PHP 7.3/7.4

PHP is open source scripting language that is widely used to write dynamic web pages. to install php7.3 or 7.4 we need to runt he following command –

$ sudo apt-get install php 

It will install the latest version of php. If you want to install specific version of php then write -
$ sudo apt-get install php7.3

You need to install the php extension as well like mysql, mod-php. To install php extension, use the command as –

$ sudo apt-get install php 7.4-mysql //7.x-extension

$ sudo apt-get install php7.4-mod-php

Then restart the apache2 server –

//to restart apache2 
$ sudo service apache2 restart
//to stop apache2 server
$ sudo service apache2 stop
//to start apache2 server
$ sudo service apache2 start

To make mod rewrite enabled you need to run the command –

$ sudo a2enmod rewrite

That’s it. You can develop a web project using php now and run it.


Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment