How To Install Linux, Apache, MySQL, PHP (LAMP) Stack on Debian 9 Stretch

Here are the steps to install the LAMP stack on Debian 9 Stretch:

  1. Install Apache Web Server:
    sudo apt-get update
    sudo apt-get install apache2
  2. Install MySQL Server:
    sudo apt-get install mysql-server

    During the installation, you’ll be prompted to set a root password for MySQL.

  3. Install PHP:
    sudo apt-get install php libapache2-mod-php php-mysql
  4. Configure Apache to use PHP:
    sudo nano /etc/apache2/mods-enabled/dir.conf

    Change the order of the files so that index.php is listed first:

    <IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
    </IfModule>
  5. Restart Apache:
    sudo systemctl restart apache2
  6. Verify the LAMP installation by creating a test PHP file:
    sudo nano /var/www/html/info.php

    Add the following code to the file:

    <?php
    phpinfo();
    ?>
  7. Access the test PHP file in your web browser:
    http://your_server_ip_or_domain/info.php

The LAMP stack should now be installed and working on your Debian 9 system.

Leave a Comment