How to install LAMP stack on Rocky Linux Cloud Servers

2021-12-28 By Nathan 1717 Views linux rockylinux lamp apache mariadb php development
6 reviews

Lamp stack is a free Open source combination of Software components installed in the Server machines. It contains Linux OS, Apache web server, MySQL database and PHP. These software work together to serve web content hosted on the server.


Prerequisite

Primarily the requirement is to have root SSH access to the Cloud server.


Installing Apache webserver


Apache is the common webserver used in servers. The step describes the installation of httpd package.

  1. Firstly, refresh the repositories and update them.

    # dnf update
    

    rockylinuxlamp1

  2. The installation of the httpd package is given here, this installs the webserver.

    # dnf install httpd -y
    

    rockylinuxlamp2

  3. Once the webserver is installed, it requires to start it manually and then enable them so that it automatically starts up while booting up.

    # systemctl start httpd
    
    # systemctl enable httpd
    

    rockylinuxlamp3

  4. Now, the firewall by default would be disabled, please enable the firewall by the following commands.

    # systemctl start firewalld
    
    # systemctl enable firewalld
    

    rockylinuxlamp4

  5. Firewall has become active, now can add the rules to allow http, https traffic, and open port 80 on your server, this is an additional layer of security.

    # firewall-cmd --permanent --zone=public --add-service=http
    
    # firewall-cmd --permanent --zone=public --add-service=https
    
    # firewall-cmd --permanent --zone=public --add-port=80/tcp
    

    rockylinuxlamp5


    Once entered the rules, reload the firewall:

    # firewall-cmd --reload
    

    rockylinuxlamp6


    To verify the changes made, the below command will show the rules listed:

    # firewall-cmd --permanent --list-all
    

    rockylinuxlamp7

  6. This completes the installation of Apache, to verify the installation log on to browser with the IP address of the server, the correct installation will show the default apache page shown below:

    http://<the-server ip-address="">
    

    rockylinuxlamp8


Installing MariaDB

MariaDB and MySQL are very similar, Installation of the database for Rocky Linux here we use MariaDB.


  1. Installing MariaDB is given below:

    # dnf install mariadb-server mariadb
    

    rockylinuxlamp9

  2. Once installed, the process needs to be started manually and enabled so that it starts while booting up the server.

    # systemctl start mysqld
    
    # systemctl enable mysqld
    

    rockylinuxlamp10

  3. Secure the MariaDB installation using the command and provide the root password for the database and it will run an interactive process that will ask the following as per the screenshots.

    # mysql_secure_installation
    

    rockylinuxlamp11


  • Set Root Passwords: Set your passwords and note them down in a password manager
  • Remove anonymous users: Yes
  • Disallow root login remotely: Recommended
  • Remote test database and access to it: Yes

    rockylinuxlamp12


Installing PHP


  1. Installing PHP in Rocky Linux can be done easily, as you can intend to change the version by specifying the version number after a colon.

    # dnf module install php:7.4
    

    rockylinuxlamp13

  2. Once installed, you can verify the version installed using the command.

    # php -v
    

    rockylinuxlamp14

  3. Now, for testing the PHP functionality we disable the default welcome page of Apache.

    # nano /etc/httpd/conf.d/welcome.conf
    


    Comment all the lines of the file and save it, as shown in the screenshot:

    rockylinuxlamp15

  4. Now, create a simple test.php file at /var/www/html/.

    # vi /var/www/html/test.php
    


    Copy-paste and save the code.

    <!--?php
    
    phpinfo();
    
    ?-->
    
  5. Now call the file using a browser, and check the PHP configuration.

    http:// <ip-address>/test.php
    


    The desired output may show like the below screenshot:

    rockylinuxlamp16


Related Tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.