Setting Up a LAMP Stack on AlmaLinux

Setting Up a LAMP Stack on AlmaLinux

AlmaLinux is a robust and open-source Linux distribution designed as a replacement for CentOS. If you're planning to host web applications or websites, setting up a LAMP (Linux, Apache, MySQL, PHP) stack is a fundamental step. This guide will walk you through the process of establishing a LAMP stack on AlmaLinux.


Prerequisites:

  • A fresh installation of AlmaLinux with root or sudo access.


Step 1: Update System Packages

Before installing any components, ensure your system is up to date:

sudo dnf update -y
Updating System Packages On AlmaLinux

Step 2: Install Apache Web Server

Install the Apache web server on your AlmaLinux system:

sudo dnf install httpd -y
Install the Apache web server on AlmaLinux
Installation of the Apache web server completed

Start and enable Apache to ensure it starts on boot:

sudo systemctl start httpd
sudo systemctl enable httpd
Start and Enable Apache

Check Apache service status to ensure it's working:

sudo systemctl status httpd
Check Apache service status

Step 3: Install MySQL Database Server

AlmaLinux uses MariaDB as a drop-in replacement for MySQL. Install MariaDB and secure the installation:

sudo dnf install mariadb-server -y
Install the MariaDB server on AlmaLinux
Installation of the MariaDB server completed

Start and enable MariaDB to ensure it starts on boot:

sudo systemctl start mariadb
sudo systemctl enable mariadb
Start and Enable MariaDB

Check MariaDB service status to ensure it's working:

sudo systemctl status mariadb
Check MariaDB service status

Now we need to secure our MariaDB server:

sudo mysql_secure_installation
Secure our MariaDB server and set our password

Follow the prompts to set a root password and secure your MariaDB installation.

Step 4: Install PHP

Install PHP and some common modules:

sudo dnf install php php-mysqlnd -y
Install PHP and some common modules
Installation of the PHP and some common modules completed

Restart Apache to apply the changes:

sudo systemctl restart httpd
Restart Apache Service

Step 5: Test PHP Processing

Create a simple PHP test file to verify that PHP is configured correctly:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Create a simple PHP test file to verify that PHP is configured correctly

Access the file through your web browser by navigating to http://your_server_ip/info.php.

You should see the PHP information page.


Conclusion

Congratulations! You've successfully set up a LAMP stack on your AlmaLinux server. This lays the foundation for hosting dynamic web content. Feel free to explore more advanced configurations based on your specific requirements.