1080*80 ad

Installing LAMP Stack on Rocky Linux 8

Deploy Your Web Server: A Step-by-Step Guide to Installing LAMP on Rocky Linux 8

Powering a significant portion of the web, the LAMP stack is a robust and reliable open-source solution for hosting dynamic websites and web applications. This powerful combination consists of Linux as the operating system, Apache as the web server, MariaDB (a fork of MySQL) as the database management system, and PHP as the server-side scripting language.

This comprehensive guide will walk you through the entire process of installing and configuring a fully functional LAMP stack on a Rocky Linux 8 server. By the end, you’ll have a secure and optimized environment ready for your development projects.

Prerequisites

Before we begin, ensure you have the following:

  • A server running a fresh installation of Rocky Linux 8.
  • Access to a user account with sudo or root privileges.
  • A basic understanding of the command-line interface.

Step 1: Update Your System

First, it’s always a best practice to ensure your system’s packages are up to date. This helps patch security vulnerabilities and resolves potential dependency issues.

Open your terminal and run the following command:

sudo dnf update -y

Step 2: Install and Configure the Apache Web Server (httpd)

The first component of our stack is Apache, the web server responsible for serving content to visitors. On Rocky Linux, the Apache package is named httpd.

Install Apache

Install the Apache web server using the dnf package manager:

sudo dnf install httpd -y

Configure the Firewall

By default, Rocky Linux’s firewall will block web traffic. We need to create an exception to allow HTTP (port 80) and HTTPS (port 443) traffic.

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Reloading the firewall applies the new rules without requiring a system restart.

Start and Enable Apache

Now, let’s start the Apache service and enable it to launch automatically on boot:

sudo systemctl start httpd
sudo systemctl enable httpd

You can verify that Apache is running with this command:

sudo systemctl status httpd

To confirm it’s working correctly, open a web browser and navigate to your server’s IP address (http://your_server_ip). You should see the default Apache HTTP Server Test Page.

Step 3: Install and Secure the MariaDB Database

Next, we’ll install MariaDB, a high-performance, open-source relational database that serves as a drop-in replacement for MySQL.

Install MariaDB

Install the MariaDB server and client packages:

sudo dnf install mariadb-server mariadb -y

Once installed, start and enable the MariaDB service:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure Your Database Installation

A default MariaDB installation is not secure. This next step is crucial for protecting your data. Run the included security script to set a root password, remove anonymous users, and disable remote root login.

sudo mysql_secure_installation

The script will guide you through several prompts. Here are the recommended answers for a secure setup:

  • Enter current password for root (enter for none): Press Enter
  • Set root password? [Y/n]: Y (and set a strong password)
  • 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

Your database server is now installed and properly secured.

Step 4: Install PHP

The final component is PHP, the scripting language used to process dynamic content. We will install PHP along with common modules that enable it to connect to MariaDB and work with Apache.

Install PHP and Required Modules

Install the main PHP package and several essential extensions:

sudo dnf install php php-mysqlnd php-gd php-xml php-mbstring -y
  • php: The core PHP package.
  • php-mysqlnd: The MySQL Native Driver, allowing PHP to communicate with MariaDB/MySQL databases.
  • php-gd: For image processing.
  • php-xml: For working with XML data.
  • php-mbstring: For handling multi-byte strings.

Restart Apache to Integrate PHP

For Apache to recognize and process PHP files, you must restart the httpd service:

sudo systemctl restart httpd

Step 5: Test Your Complete LAMP Stack

With all components installed, it’s time to verify that everything is working together correctly. We’ll do this by creating a simple PHP file that displays system information.

Create a new file called info.php in the web root directory (/var/www/html):

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

Add the following PHP code to the file:

<?php
phpinfo();
?>

Save the file and exit the editor (Ctrl+X, then Y, then Enter in nano).

Now, open your web browser and navigate to http://your_server_ip/info.php. You should see a detailed page displaying your server’s PHP configuration. This confirms that Apache is correctly processing PHP files.

Important Security Tip: This info.php file reveals sensitive information about your server’s configuration. After confirming your setup works, it is highly recommended to delete this file.

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

Conclusion

Congratulations! You have successfully installed and configured a complete LAMP (Linux, Apache, MariaDB, and PHP) stack on your Rocky Linux 8 server. You now have a powerful and flexible platform ready to host everything from a personal blog to a complex web application. Your next steps could include installing a content management system like WordPress, deploying your custom code, or further hardening your server’s security.

Source: https://kifarunix.com/install-lamp-stack-on-rocky-linux-8/

900*80 ad

      1080*80 ad