DEV Community

Cover image for Setting up LAMP stack on Ubuntu in under 10 minutes
Feroz Chand
Feroz Chand

Posted on

Setting up LAMP stack on Ubuntu in under 10 minutes

Efficiency is crucial in today's digital world. That's why we're here to demonstrate how you can set up the LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 20.04 in under 10 minutes. With Ubuntu 20.04's user-friendly interface and dependable performance, it's the ideal platform for this task. Let's dive in and streamline your development process!

Installing Apache and configuring our Firewall

Apache2 is one of the best open-source webserver currently out there. To set up Apache on Ubuntu 20.04, first, update the package index and install Apache with these commands:

sudo apt update
sudo apt install apache2 -y
Enter fullscreen mode Exit fullscreen mode

Once installed, Apache starts automatically. Verify the installation by entering your server's IP address in a web browser; you should see the Apache2 Ubuntu Default Page.

Next, configure the firewall to allow HTTP (port 80) and HTTPS (port 443) traffic:

sudo ufw allow 'Apache Full'
Enter fullscreen mode Exit fullscreen mode

Verify the changes take effect:

sudo ufw status
Enter fullscreen mode Exit fullscreen mode

Result should look like this:

Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere                  
Apache Full (v6)           ALLOW       Anywhere (v6)
Enter fullscreen mode Exit fullscreen mode

You can now go to the server URL (IP address) and the apache2 default page will be displayed on the screen.

Apache2 landing page.

Congratulations! You have successfully installed Apache on Ubuntu 20.04. We can now move on to MySQL.

Installing MySQL on Ubuntu 20.04

In the LAMP stack, MySQL serves as the backbone for data management. Here's a step-by-step guide to installing MySQL on your Ubuntu 20.04 server.

To kickstart the installation process, execute the following command:

sudo apt install mysql-server -y
Enter fullscreen mode Exit fullscreen mode

To verify that MySQL is running correctly, execute:

sudo systemctl status mysql
Enter fullscreen mode Exit fullscreen mode

You should see an active (running) status, indicating that MySQL is operational.

With MySQL installed and secured, your LAMP stack is nearly complete. Next, we'll proceed to install PHP, the final component, enabling server-side scripting and dynamic content generation.

Installing PHP on Ubuntu 20.04

Now, let's proceed with installing PHP, the dynamic scripting language that completes the trio in your LAMP stack, enabling powerful server-side functionality.

To begin, execute the following command to install PHP and essential extensions:

sudo apt install php libapache2-mod-php php-mysql
Enter fullscreen mode Exit fullscreen mode

This command not only installs PHP but also ensures compatibility with MySQL and Apache, seamlessly integrating all components of your LAMP stack.

Once PHP is installed, you can verify the installation by creating a test PHP file. Use the following command to create a file named info.php in the default web directory:

sudo nano /var/www/html/info.php
Enter fullscreen mode Exit fullscreen mode

In this file, add the following PHP code:

<?php
phpinfo();
?>
Enter fullscreen mode Exit fullscreen mode

Save and close the file. Now, access this file through your web browser by navigating to "http://your_server_ip/info.php". You should see a comprehensive PHP information page, confirming that PHP is installed and operational.

With PHP successfully installed and configured, your LAMP stack is now fully equipped to handle dynamic content and power your web applications. Congratulations on completing the setup!

Top comments (0)