• Help & contact
    • Unlock security benefits
      %

    For Cloud Servers, migrated Cloud Servers, VPS, Dedicated Servers and Server Power Deals managed in Cloud Panel

    This article explains how to install a LAMP stack on a Cloud Server, a migrated Cloud Server, a VPS or a Dedicated Server with AlmaLinux 8 or Rocky Linux 8.

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

    Requirements

    Before installing the LAMP stack, you have ensured that your server has sufficient hardware capacity.

    Install Apache

    Proceed as follows to install Apache:

    • To check if an update is available, enter the command below:

      yum update

    • To install Apache, enter the following command:

      yum install httpd

      The following message is displayed:

      Total download size: 2.3 M
      Installed size: 6.5 M
      Is this ok [y/N]:

    • Enter [y] and press [Enter].


      Apache will be installed.
       

    • To start Apache, enter the command below:

      systemctl start httpd.service

    • To check whether Apache has been successfully installed and started, enter the following command.

      systemctl status httpd

    • To exit the status display, press the q key.
    • To generate a test page, enter the following command:

      echo "Welcome to this site!" > /var/www/html/index.html

    • To check whether Apache has been successfully installed and started, enter the public IP address of your server in the following format in your web browser.

      http://THE-SERVER-IP-ADDRESS

       

      If a test page is displayed, the installation of Apache was successful.
       

    • To ensure that Apache is also restarted automatically when the server is restarted, enter the following command:

      systemctl enable httpd.service

    Install MariaDB

    • To install MariaDB, enter the following command:

      yum install mariadb-server mariadb

      The following message is displayed:

      Total download size: 26 M
      Installed size: 135 M
      Is this ok [y/N]:

    • Enter [y] and press [Enter].


      MariaDB will be installed.

    • To start MariaDB, enter the following command:

      systemctl start mariadb

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

      mysql_secure_installation

    • After entering the command, you will be asked for a password. As you have not yet defined a password for MariaDB, you can skip this point. To do this, press Enter.

      You will then be asked whether you want to set the root password.
    • Enter [y] and press [Enter].
    • Enter a new root password, repeat it and then press [Enter]. The following message is displayed:

      By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. this is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environmentt.

      Remove anonymous users? [Y/n]

    • To remove anonymous users, enter [y] and press [Enter]. The following message is then displayed:

      Disallow root login remotely? [Y/n]

    • Enter [y] and press [Enter]. The following message is then displayed:

      Remove test database and access to it?

    • Enter [y] and press [Enter]. The following message is displayed:

      Reload privilege tables now?

    • To reload the privilege tables, enter [y]. To confirm the entry, press [Enter].
    • To enable MariaDB at boot time, enter the following command:

      systemctl enable mariadb.service

    Install PHP

    To install the PHP scripting language, proceed as follows:

    • To install the PHP, the MySQL driver, the POD_MySQL driver, the GD library and the PHP module for multibyte strings, enter the following command:

      yum install php php-mysqlnd php-pdo php-gd php-mbstring

      The following message is displayed:

      Total download size: 9.3 M
      Installed size: 44 M
      Is this ok [y/N]:

    • To continue the installation, enter [y]. Then press [Enter].
    • To restart the Apache web server, enter the following command:

      systemctl restart httpd.service

    Install PHP modules

    To extend the functionality of PHP, you can install additional modules.

    • To display the available options for PHP modules and libraries, enter the following command:

      yum search php-

    • To get detailed information about a PHP module, enter the command below:

      yum info package_name

      Example:

      yum info php-embedded.x86_64

    • To install the desired PHP modules, enter the following command:

      yum install package1 package2

      Example:

      yum install php-cli.x86_64 php-devel.x86_64 php

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

    Test PHP

    To test whether PHP has been installed correctly, create a script with the editor. This must be saved in the /var/www/html directory.

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

      vi /var/www/html/info.php

      The vi editor opens.

    Notes

    • The vi editor has an insert mode and a command mode. You can call up insert mode with the [i] key. In this mode, the characters entered are immediately inserted into the text. To call up command mode, press the ESC key. If you use command mode, your keystrokes are interpreted as a command.
    • vi cannot be terminated in insert mode. Therefore, always enter command mode to exit vi.
    • Press [i] and enter the following PHP code:

      <?php phpinfo(); ?>

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


      http://THE-SERVER-IP-ADDRESS/info.php
       

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

      rm /var/www/html/info.php

      The following message is displayed:

      rm: remove regular file '/var/www/html/info.php'?

    • Enter y and press[Enter].