top of page
  • Bankim Bhagat

Install LAMP stack on Ubuntu 18.04 / 20.04 / 22.04

Updated: May 29

Open terminal (ctrl+alt+t) and type the following commands

sudo apt-get update 
sudo apt-get install apache2 mysql-server php7.2 libapache2-mod-php libapache2-mod-php7.2 php7.2-mysql php7.2-curl php7.2-json php7.2-cgi php7.2-gd git htop curl htpdate php7.2-mbstring 

For 20.04 use the following command

sudo apt-get install apache2 mysql-server php7.4 libapache2-mod-php libapache2-mod-php7.4 php7.4-mysql php7.4-curl php7.4-json php7.4-cgi php7.4-gd git htop curl htpdate php7.4-mbstring 

For 22.04 use the following command

sudo apt-get install apache2 mysql-server php8.1 libapache2-mod-php libapache2-mod-php8.1 php8.1-mysql php8.1-curl php8.1-cgi php8.1-gd git htop curl htpdate php8.1-mbstring 

The above command will install all the necessary packages

Goto any web browser and open “http://localhost”.You will see the default Ubuntu 18.04 / 20.04 Apache web page

sudo a2enmod userdir deflate expires rewrite
sudo nano /etc/apache2/mods-enabled/php7.2.conf 

For Ubuntu 20.04 us the following command

sudo nano /etc/apache2/mods-enabled/php7.4.conf 

For Ubuntu 22.04 us the following command

sudo nano /etc/apache2/mods-enabled/php8.1.conf 

comment these lines to enable php in userdir

To save and exit the nano text editor. hit ctrl+o,then hit enter, then hit ctrl+x to exit

Create the web directory

mkdir ~/public_html 

Restart Apache server for the new configuration to take affect.

service apache2 restart 

Now goto the browser and open http://localhost/~YourUserName

In this case the username is bkm

You’ll see the following page

Setup SSL

a2enmod ssl

Install certbot

sudo snap install core; sudo snap refresh core
sudo apt-get remove certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo snap set certbot trust-plugin-with-root=ok
sudo certbot

Set MySQL Password

sudo mysql 
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; 

MySQL password is set to ‘password’


Try logging in the terminal. Enter the following command

mysql -u root -p 
52 views0 comments

Recent Posts

See All
bottom of page