Electronics Engineer Fixing Cables on Server

Install the LAMP Stack on Ubuntu

How to Install LAMP (Linux Apache MySQL PHP) Stack

Establish a robust foundation for your web applications! This comprehensive guide walks you through installing the LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu, empowering you to create dynamic and interactive websites.

Prerequisites:

  • An Ubuntu server with root or sudo privileges.
  • Basic understanding of using the command line.
  • Access to your server via SSH.
  • To Get Access via SSH
Syntax:- ssh -p PORT USERNAME@HOSTIP
Example:- ssh -p 22 root@216.32.44.12
  • Updates the package lists for Upgrades then Upgrade
apt update
apt upgrade
  • Install Apache
apt install apache2
  • (Optional) If Get Error While Installation “cannot stat ‘/usr/share/apache2/default-site/index.html’: No such file or directory
    dpkg: error processing package apache2 (–configure)” then Try to Install Again
apt purge apache2-data
  • Allow Apache through Firewall
ufw allow "Apache Full"
  • Check Server IP on Web Browser You will see Apache Default Page
  • Install MySQL
apt install mysql-server
  • Install PHP
apt install php libapache2-mod-php php-mysql
The above command includes three packages:-
php -  To Install PHP
libapache2-mod-php - It is Used by apache to handle PHP files
php-mysql - It is a PHP module that allows PHP to connect to MySQL 
  • To Restart Apache
service apache2 restart