Install LAMP Stack on Rocky Linux

Introduction

In this tutorial, How to Install LAMP Stack on Rocky Linux. A LAMP stack, which stands for Linux, Apache, MySQL (or MariaDB), and PHP, is a popular software bundle that provides the necessary components for hosting dynamic websites and web applications. In this tutorial, we’ll walk you through the steps to set up a LAMP stack on a Rocky Linux server.

Prerequisites

Before we begin, ensure that you have:

  • A running Rocky Linux instance
  • Root or sudo privileges
  • A stable internet connection

How to install LAMP Stack on Rocky Linux

Install Apache on Rocky Linux

Apache HTTP Server is one of the most widely used web servers in the world. To install it, run the following command:

dnf install -y httpd httpd-devel httpd-tools

Enable Apache start at boot time

systemctl enable httpd

start the Apache HTTPd daemon

systemctl start httpd

To check Apache running on Rocky Linux

systemctl status httpd

The output terminal is below

Install LAMP Stack on Rocky Linux

Opens a browser that can access your Server’s IP address

http://Your-IP-address
OR
http://domain.com
Install LAMP Stack on Rocky Linux

Install MariaDB on Rocky Linux

Next, you’ll need a database server. You can choose between MariaDB and MySQL. In this example, we’ll use MariaDB. Install it with the following command:

dnf install mariadb-server mariadb

The output terminal as below

Install LAMP Stack on Rocky Linux

Enable MariaDB to start at boot time

systemctl enable --now mariadb

Start the MariaDB daemon

systemctl start mariadb

To check MariaDB running on Rocky Linux

systemctl status mariadb

Additional steps to harden the database server. Run the MariaDB security script to secure your installation:

mysql_secure_installation
Set root password? [Y/n] y
Remove anonymous users? [Y/n] 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

Follow the on-screen prompts to set a root password and improve the security of your database server.

Install PHP on Rocky Linux

The default PHP stream is PHP 7.2. PHP is a server-side scripting language commonly used in web development. Install PHP and the PHP MySQL extension with the following command:

To install the latest module Stream. We will reset the PHP streams.

dnf module reset php

Install PHP 7.4

dnf module install php:7.4

The output terminal is below

Install LAMP Stack on Rocky Linux

Install additional PHP extensions

dnf install php-cli php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

Confirm the version of PHP installed

php -v

The output terminal is below

Install LAMP Stack on Rocky Linux

Test Your Install LAMP Stack

To verify that your LAMP stack is installed and running correctly, create a test PHP file in the Apache web root directory. We’ll use info.php as an example:

We create a test PHP file in the /var/www/html path.

vi /var/www/html/info.php

The content info.php is below

<?php
phpinfo();
?>

Save the changes and restart the webserver.

systemctl restart httpd

Open back browser

http://server-ip/info.php

The output is below

Install LAMP Stack on Rocky Linux

Remove file test PHP

rm -f /var/www/html/info.php

Conclusion

Congratulations! You’ve successfully install LAMP stack on your Rocky Linux server. You now have a powerful platform for hosting websites and web applications. Remember to secure your server, keep your software up to date, and regularly back up your data to ensure a stable and reliable web hosting environment. I hope will this your helpful. Thank you for reading the DevopsRoles page!

This comprehensive guide should equip you with the knowledge to manage and expand your LAMP stack setup. For any further customization or troubleshooting, refer to the official documentation and community forums. Happy coding!

Refer to:

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.