Complete Guide to Installing a LAMP Stack on Ubuntu | SUAR SERVICES

Complete Guide to Installing a LAMP Stack on Ubuntu

A LAMP stack refers to a set of open-source software that includes Linux, Apache, MySQL, and PHP. This guide will walk you through the steps to install a LAMP stack on an Ubuntu system.

Step 1: Update System Packages

sudo apt update
sudo apt upgrade

This will ensure that your system packages are up to date before installing the LAMP stack.

Step 2: Install Apache

sudo apt install apache2

Apache is a popular web server software. After installing Apache, you can start and enable it with the following commands:

sudo systemctl start apache2
sudo systemctl enable apache2

Step 3: Install MySQL

sudo apt install mysql-server

During the installation process, you will be prompted to set a root password for MySQL. Once installed, you can secure MySQL by running:

sudo mysql_secure_installation

Step 4: Install PHP

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

This command will install PHP along with the necessary modules to integrate it with Apache and MySQL.

Step 5: Test PHP
Create a PHP info file to test if PHP is working properly:

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

You can access this file in a web browser by visiting http://your_server_ip/info.php. If PHP is working correctly, you should see a page displaying PHP configuration information.

Step 6: Configure Apache to Use PHP
Edit the Apache configuration file to enable PHP processing:

sudo nano /etc/apache2/mods-enabled/dir.conf

Move the PHP index file to the first position within the block, as shown below:

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

Save the file and restart Apache for the changes to take effect:

sudo systemctl restart apache2

Congratulations! You have successfully installed a LAMP stack on your Ubuntu system. You can now deploy web applications that require Apache, MySQL, and PHP.