Step-by-Step Guide to LAMP Configuration on Ubuntu

How to, Linux By Jul 02, 2023 No Comments

How to Setup LAMP on Ubuntu

LAMP stands for Linux, Apache, MySQL, and PHP. Together, they provide a proven set of software for delivering high-performance web applications. Here is a basic guide on how to install and configure a LAMP stack on Ubuntu:

  1. Update your system: Always start by updating your system to the latest packages. You can do this by running the following command:
sudo apt update && sudo apt upgrade -y
  1. Install Apache: Apache is a popular open-source web server. Install it with the following command:
sudo apt install apache2 -y

After the installation, you can check if Apache is running by typing:

sudo systemctl status apache2

Install MySQL: MySQL is a powerful database management system used for organizing and retrieving data. To install MySQL, run the following command:

sudo apt install mysql-server -y

After the installation, run the security script that comes with the installation:

sudo mysql_secure_installation

This will take you through a series of prompts where you can make some changes to your MySQL installation’s security options.

  1. Install PHP: PHP is a popular server-side scripting language designed for web development. Install PHP along with a few common extensions with the following command:
sudo apt install php libapache2-mod-php php-mysql -y
  1. Configure Apache to prioritize PHP files: By default, Apache will look for an index.html file. We want it to look for index.php first. To do this, open the dir.conf file:
sudo nano /etc/apache2/mods-enabled/dir.conf

Move the PHP index file to the first position after the DirectoryIndex specification:

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

Save and close the file when you are finished.

  1. Restart Apache to apply the changes:
sudo systemctl restart apache2
  1. Test PHP Processing: To confirm that your server is configured correctly for PHP processing, create a very basic PHP script. Use nano or your favorite text editor to create the file:
sudo nano /var/www/html/info.php

This will open a blank file. Add the following text, which is valid PHP code, inside the file:


Save and close the file. Now you can test whether your web server is able to correctly display this page. If you go to http://your_server_ip/info.php, you should see a web page that has been generated by PHP with information about your server.

Remember to replace your_server_ip with your server’s public IP address. If you see this page, then your PHP is working as expected.

You might want to remove this file after this test because it could actually give information about your server to unauthorized users. To do this, you can type this command:

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

That’s it! You have now installed a LAMP stack on your Ubuntu server.

Please note that this is a basic guide. Depending on your specific needs, you might need to configure your LAMP stack differently.


I'm Abhay Singh, an Architect with 9 Years of It experience. AWS Certified Solutions Architect.

No Comments

Leave a comment

Your email address will not be published. Required fields are marked *