How to Install LAMP Stack on Ubuntu 24.04

Introduction

LAMP stack consists of four open-source software applications: Linux (OS), Apache (webserver), MySQL (database management), and PHP (scripting language). Apache is a widely used, reliable, and compatible web server. MySQL provides secure data storage for web apps. PHP, which can be embedded in HTML and runs on the server, enhances security for web applications and offers server-site scripting.

This guide shows you how to install the LAMP stack on Ubuntu 24.04.

Prerequisites

Before you begin, ensure you have the following:

Install Apache webserver On Ubuntu 24.04

In this step, you'll update your system and install Apache using the Ubuntu APT utility. Follow the steps below.

  1. SSH to your Ubuntu 24.04 using Putty or open SSH.
  2. Update the package information index

    CONSOLE
    $ sudo apt update
    
  3. Install Apache web server

    CONSOLE
    $ sudo apt install apache2 -y
    
  4. Allow port 80 through the firewall.

    CONSOLE
    $ sudo ufw allow 80
    
  5. Reload UFW to apply the new changes.

    CONSOLE
    $ sudo ufw reload
    
  6. Enter the public IP address associated with your server on a web browser to test Apache installation.

    http://198.18.0.12
    
  7. Ensure your web browser displays the default Apache web page.

By default, Apache creates a root directory at /var/www/html. To publish your website, upload all your files to that directory via an FTP client like Filezilla.

Install MySQL Server on Ubuntu 24.04

Install MySQL server using the Ubuntu APT command and secure the database server by following the steps below:

  1. Install MySQL server

    CONSOLE
    $ sudo apt install mysql-server -y
    
  2. Secure the MySQL server.

    CONSOLE
    $ sudo mysql_secure_installation
    
  3. Enter the following responses and press Enter after each response:

    CONSOLE
    Setup 'validate password' plugin? [Y/N] Y
    Password Validation Policy Level: 2
    Remove anonymous users: Y
    Disallow root login remotely? [Y/N] Y  
    Remove test database and access to it? [Y/N] Y
    Reload privilege tables now? [Y/N] Y
    

Install PHP Scripting Language on Ubuntu 24.04

PHP works on top of a web server to deliver web content to a client. When you request a PHP file, the PHP software processes the request and sends HTML back to your browser via a web server. In this case, Apache performs this function.

  1. Run the following command to install PHP.

    CONSOLE
    $ sudo apt install php -y
    
  2. Reload Apache to load the new changes.

    CONSOLE
    $ sudo service apache2 restart
    
  3. Create a new info.php in the root directory of your webserver.

    CONSOLE
    $ sudo nano /var/www/html/info.php
    
  4. Copy the content below and paste it to the

    PHP
    <?php
        phpinfo();
    ?>
    
  5. Press Ctrl + X, Y and press Enter to save the file:

  6. Visit the following address on a web browser. Replace 198.18.0.12 with your Ubuntu server's public IP address.

    http:// 198.18.0.12/info.php
    

    You should see a PHP page.

  7. Install the most common PHP extensions for running dynamic websites and applications.

    CONSOLE
    $ sudo apt install php-cli php-common php-mbstring php-gd php-intl php-xml php-mysql php-zip php-curl php-xmlrpc -y
    
  8. Restart Apache to load the new extensions.

    CONSOLE
    $ sudo service apache2 restart
    

Conclusion

You've installed a LAMP stack on an Ubuntu 22.04 server. These four open-source applications set a foundation for running a web server, database server, and scripting environment. To create and run a website or web application with these applications, consider installing a CMS like WordPress.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js