Skip to main content

Command Palette

Search for a command to run...

Step-by-Step LAMP Stack Installation on Ubuntu

Updated
โ€ข2 min read
Step-by-Step LAMP Stack Installation on Ubuntu
A

Hi ๐Ÿ‘‹ Iโ€™m Abhinav Prakash - a full-stack dev who loves building with Node.js, React, Next, Astro, MongoDB & Cloud. I share my blogs, learnings, side-projects, and dev journey here ๐Ÿš€

Follow these steps to set up a LAMP (Linux, Apache, MySQL, PHP) stack on your Ubuntu server. Copy commands directly and get started quickly! ๐Ÿ˜Ž


๐Ÿ› ๏ธ Step 1: Update and Upgrade System

sudo apt update && sudo apt upgrade -y

๐Ÿ“Œ What to Do: Keep your system up to date with this single command.


๐ŸŒ Step 2: Install Apache

sudo apt install apache2 -y

๐Ÿ“Œ What to Do: Install Apache, the web server.

  • Check Apache Status:
sudo systemctl status apache2
  • Test Apache:
    Open your browser and navigate to http://your-server-ip to see the Apache default page.

๐Ÿฌ Step 3: Install MySQL

sudo apt install mysql-server -y

๐Ÿ“Œ What to Do: Install MySQL for database management.

  • Secure MySQL:
sudo mysql_secure_installation

๐Ÿ‘‰ Detailed Guide: MySQL Secure Installation

  • Login to MySQL:
sudo mysql

๐Ÿ’ป Step 4: Install PHP

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

๐Ÿ“Œ What to Do: Install PHP and its modules.

  • Test PHP:

    • Create a test file:

        sudo nano /var/www/html/info.php
      
    • Add the following code:

        <?php
        phpinfo();
        ?>
      
    • Visit http://your-server-ip/info.php in your browser to confirm PHP installation.


๐Ÿ›ก๏ธ Step 5: Adjust Firewall (Optional)

sudo ufw allow in "Apache Full"

๐Ÿ“Œ What to Do: Allow Apache through the firewall for proper access.


๐Ÿ”„ Step 6: Enable Modules and Restart Apache

sudo a2enmod rewrite  
sudo systemctl restart apache2

๐Ÿ“Œ What to Do: Enable Apache modules for better functionality.


โœ… Step 7: Verify Installation

  • Apache: Navigate to http://your-server-ip in your browser.

  • PHP Info: Navigate to http://your-server-ip/info.php in your browser.


๐Ÿ“Š Optional: Install phpMyAdmin

sudo apt install phpmyadmin -y

๐Ÿ“Œ What to Do: Install phpMyAdmin to manage MySQL databases via a web interface.

  • Configure: Follow the installation prompts and integrate it with Apache.

  • Access: Visit http://your-server-ip/phpmyadmin in your browser.


๐ŸŽ‰ Congratulations! Your LAMP stack is ready to use.

More from this blog

A

Abhinav Prakash | Blogs

6 posts

I write about programming, AI, open-source tools, and my developer journey.
From building side projects to solving real-world dev problems