How To Install LAMP Stack On Ubuntu 22.04

Setting Up LAMP Stack on Ubuntu 22.04

In this comprehensive guide, we’ll walk you through the step-by-step process of setting up a robust LAMP Stack on your Ubuntu 22.04 system. The LAMP Stack, comprising Apache, MariaDB, and PHP, is a powerful combination for hosting dynamic web applications.

Prerequisites

Before we dive into the installation, make sure you have the following prerequisites in place:

  • A dedicated server or Cloud VPS running Ubuntu 22.04.
  • Access with either root user privileges or a normal user with sudo capabilities.

1. Keeping Your Server Updated

Ensure your server is up-to-date by running the following commands:

sudo apt update && sudo apt upgrade -y

2. Installing Apache Webserver

Install Apache using the following command:

sudo apt install apache2 -y

If you’re using UFW firewall, configure the ports:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Verify the Apache installation by accessing the default page in your browser: http://SERVER_IP

3. Securing MariaDB Installation

Install MariaDB and secure it with:

sudo apt install mariadb-server -y
sudo mysql_secure_installation

Follow the prompts to set a secure password and configure other security settings.

4. Installing PHP

Install PHP along with common packages:

sudo apt install php php-common php-mysql php-gd php-cli -y

For testing, create a simple info.php page:

sudo echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Access it in your browser: http://SERVER_IP/info.php

5. Deploying a Website

Create a website root directory and an index.html file:

sudo mkdir -p /var/www/website_name
cd /var/www/website_name
sudo nano index.html

Paste your HTML content, save, and change ownership:

sudo chown -R www-data:www-data /var/www/website_name

Create a virtual host for your website:

sudo nano /etc/apache2/sites-available/website_name.com.conf

Add the virtual host configuration, save, and enable it:

sudo ln -s /etc/apache2/sites-available/website_name.com.conf /etc/apache2/sites-enabled/website_name.com.conf
sudo systemctl restart apache2

6. Installing Certbot for SSL

Add Certbot repository and install the Apache package:

sudo add-apt-repository ppa:certbot/certbot
sudo apt install python3-certbot-apache -y

Obtain an SSL certificate:

sudo certbot --apache -d <your_domain>

Test automatic renewal:

sudo certbot renew --dry-run

Now, your LAMP Stack is ready. Navigate to your domain or server IP in your browser to see the deployed website.

Congratulations on successfully setting up your LAMP Stack on Ubuntu 22.04!

Facebook
Pinterest
Twitter
LinkedIn