Install LAMP Stack on Ubuntu 22.04 LTS

What is LAMP Stack?

LAMP stack is a popular open-source software stack used to develop and run web applications. It stands for Linux, Apache, MySQL, and PHP/Perl/Python.

  • Linux is the operating system that provides the foundation for the stack.

  • Apache is the web server software that receives and processes requests from web clients and serves web pages to them.

  • MySQL is the relational database management system that stores and retrieves data for the web application.

  • PHP, Perl, or Python are the scripting languages used to develop the web application logic.

Together, these components provide a powerful and flexible platform for building and deploying web applications. The LAMP stack has been widely adopted due to its ease of use, flexibility, and low cost of ownership.

How to Install LAMP Stack?

Update your system's package index and install Apache by running the following commands:

sudo apt update
sudo apt install apache2

Once Apache is installed, start and enable it to run automatically at boot time:

sudo systemctl start apache2
sudo systemctl enable apache2

Install MySQL server and client packages by running the following command:

sudo apt install mysql-server mysql-client

During the installation process, you will be prompted to set a password for the MySQL root user. Make sure to remember this password.

Secure your MySQL installation by running the security script that comes with the MySQL package:

sudo mysql_secure_installation

Follow the prompts and answer the questions to secure your MySQL installation.

Install PHP and other required modules by running the following command:

sudo apt install php libapache2-mod-php php-mysql

Test your LAMP installation by creating a PHP test file in the web server's root directory:

sudo nano /var/www/html/info.php

Paste the following code into the file:

<?php
phpinfo();
?>

Save and close the file.

Restart Apache to apply the changes:

sudo systemctl restart apache2

Open your web browser and navigate to http://localhost/info.php. You should see the PHP information page that confirms your LAMP installation is working correctly.

That's it! You now have a working LAMP stack on your Ubuntu system.

To map your LAMP stack with a domain name and install Certbot on Ubuntu, follow these steps:

  1. Configure your domain name to point to the IP address of your Ubuntu server. This can be done through your domain registrar or DNS provider.

  2. Install Certbot and the Apache plugin using the following command:

sudo apt install certbot python3-certbot-apache
  1. Run Certbot to obtain a SSL certificate for your domain name:
sudo certbot --apache -d yourdomain.com
  1. Certbot will ask you a series of questions to configure your SSL certificate. Answer the questions as appropriate for your setup.
  1. Once the certificate is installed, Certbot will automatically configure Apache to use SSL and redirect HTTP traffic to HTTPS.

  2. Test your SSL installation by accessing your website using https://yourdomain.com. Your browser should display a green padlock icon, indicating a secure connection.

That's it! Your LAMP stack is now mapped to your domain name and secured with an SSL certificate.

Did you find this article valuable?

Support PethuVignesh by becoming a sponsor. Any amount is appreciated!