Valid for VPS+, Cloud Servers, migrated Cloud Serverss, VPS, and Dedicated Servers that are managed in the Cloud Panel.

This article explains how to install a LAMP stack on a Cloud Server, migrated Cloud Server, VPS, VPS+, Dedicated Server, or Bare Metal Server running Debian 13, Ubuntu 24.04, or Ubuntu 26.04.

A LAMP stack consists of the Linux operating system and the software applications Apache, MariaDB, and PHP. These are installed together to host dynamic websites and web applications on a server.

How to install a LAMP stack:

Requirements

Install Apache

To install Apache, complete the following:

  • To update the package lists and bring the system up to date, enter the following commands:

    sudo apt update
    sudo apt upgrade

  • To install Apache, enter the following command:

    sudo apt install apache2

    The installation will begin. During the installation, the following message will be displayed:

    The following NEW packages will be installed:
    apache2 apache2-bin apache2-data apache2-utils bzip2 libapr1 libaprutil1
    libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0 mailcap mime-support
    ssl-cert
    0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
    Need to get 2,135 kB of archives.
    After this operation, 8,486 kB of additional disk space will be used.
    Do you want to continue? [Y/n]

  • Type [y] and press Enter. Apache will be installed.
  • To check whether Apache has been successfully installed and started, enter your server’s public IP address in your web browser in the following format:
    http://YOUR.SERVER.IP.ADDRESS/
    If a test page is displayed, the installation of Apache was successful.

Install MariaDB

  • To install MariaDB, enter the following command:

    sudo apt install mariadb-server

    Once you have entered the command, the following message will be displayed:

    Need to get 28.6 MB of archives.
    After this operation, 240 MB of additional disk space will be used.
    Do you want to continue? [Y/n]

  • Type [y] and press Enter. MariaDB will be installed.
  • Log in to MariaDB. To do this, enter the following command:

    sudo mariadb

  • Enter the following command, replacing the placeholder MY_NEW_PASSWORD with your chosen password.

    mariadb> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MY_NEW_PASSWORD';

    Then enter the following command:

    FLUSH PRIVILEGES;

  • To exit MariaDB, enter the following command:

    mariadb> exit

  • To run a security script that removes some dangerous default settings and restricts access to the database system, enter the following command:

    mariadb-secure-installation

    After entering the command, the following message will be displayed:

    Securing the MariaDB server deployment.
    Connecting to MariaDB using a blank password.

  • Enter the root password for the MariaDB database that you have set. The following message will then be displayed:

    Switch to unix_socket authentication [Y/n]

  • Press the Enter key or type [n] to skip this step. The following message will then appear:

    Change the root password? [Y/n]

  • To keep the password unchanged, enter [n] and press Enter. The following message will appear:

    By default, a MariaDB installation includes an anonymous user, allowing anyone to log into MariaDB without needing a user account created for them. This is intended solely for testing purposes and to make the installation run a little more smoothly. Yo

    Remove anonymous users? [Y/n]

  • To remove anonymous users, type [y] and press Enter. The following message will then be displayed:

    Disallow remote root login? [Y/n]

  • Type [y] and press Enter. The following message will then appear:

    Remove the test database and access to it?

  • Type [y] and press Enter. The following message will then appear:

    Reload privilege tables now?

  • To reload the MariaDB privilege tables, type [y]. To confirm your entry, press the Enter key.

Install PHP

To install the PHP scripting language, complete the following:

  • To install PHP, the Apache module for PHP and the MariaDB extension, enter the following command:

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

    The following message will be displayed:

    After this operation, 21.8 MB of additional disk space will be used.
    Do you want to continue? [Y/n]

  • To continue with the installation, type [y]. Then press the Enter key.

Adjust the settings in the dir.conf file

If a user does not specify a particular page in the URL, Apache will, by default, first look for the home page named index.html. To configure Apache so that the file index.php is given priority, complete the following:

  • To open the dir.conf file using the vi editor, enter the following command:

    sudo vi /etc/apache2/mods-enabled/dir.conf

Notes

  • The vi editor has an insert mode and a command mode. You can enter insert mode by pressing the [i] key. In this mode, the characters you type are inserted into the text immediately. To switch to command mode, press [ESC] afterwards. When you are in command mode, your keystrokes are interpreted as commands.
  • vi cannot be exited whilst in insert mode. You should therefore always enter command mode to exit vi.
  • Press [i] and edit the following entry:

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

  • Move the entry ‘index.php’ so that it appears after the ‘DirectoryIndex’ entry.
  • To enter command mode, press [ESC]. Then enter the command :wq to save the text and close the editor.
  • You must restart Apache for these changes to take effect. To restart Apache, enter the following command:

    sudo systemctl restart apache2

Install PHP modules

To extend PHP’s functionality, you can install additional modules.

To view the available options for PHP modules and libraries, pipe the output of apt search to less. Less is a pager that allows you to view text files from the command line. Additionally, you can navigate freely through documents using less. To do this, enter the following command:

sudo apt search php- | less

To scroll up or down, use the arrow keys. To exit less, press [q].

To obtain detailed information about a PHP module, enter the following command:

sudo apt show package_name

Example:

sudo apt show php-xml

To install the required PHP modules, enter the command below:

sudo apt install package1 package2

Example:

sudo apt install php-xml php-cli

Test PHP

To check whether PHP has been installed correctly, create a script using an editor. This must be saved in the /var/www/html directory. Follow these steps to create the script and test PHP:

  • To create the script in the /var/www/html directory, enter the following command:

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

    The vi editor will open.

  • Press the [i] key and then enter the following PHP code:

    <?php
    phpinfo();
    ?>

  • To return to command mode, press [ESC]. Then enter the command :wq to save the text and close the editor.
  • To check whether the contents of the PHP script are displayed, enter the relevant URL in the following format in your web browser:

    http://YOUR.SERVER.IP.ADDRESS/info.php

  • To remove the displayed page, enter the following command:

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

Your LAMP stack is now ready to use. Next, you could install a web application such as WordPress, or create your first PHP page.