Guide to Installing the LAMP Stack on AlmaLinux 9.3

Welcome, fellow Linux Administrators! Today, we’re diving into the setup of a robust LAMP stack on AlmaLinux 9.3. The LAMP stack, comprising Linux, Apache, MySQL (or MariaDB), and PHP, is a popular web server environment for hosting web applications. We’ll also cover the installation of PHP 8.2, IonCube Loader, Webmin, and phpMyAdmin using the DNF package manager, ensuring a comprehensive setup for managing web applications effectively.

Prerequisites

Before we start, ensure you have:

  • A running AlmaLinux 9.3 server
  • Root or sudo privileges
  • Access to a terminal or SSH

Step 1: Update Your System

First, let’s make sure your system is up-to-date:

sudo dnf update -y

Step 2: Install Apache

Apache is our web server of choice. Install it with:

sudo dnf install httpd -y

Enable and start the Apache service:

sudo systemctl enable --now httpd

Verify Apache is running:

sudo systemctl status httpd

Step 3: Install MariaDB

MariaDB serves as our database management system. Install it using DNF:

sudo dnf install mariadb-server -y

Then, enable and start the MariaDB service:

sudo systemctl enable --now mariadb

Secure your MariaDB installation:

sudo mysql_secure_installation

Follow the prompts to set a root password and adjust settings accordingly.

Step 4: Install PHP 8.2

AlmaLinux’s default repository might not have PHP 8.2, so we’ll use the Remi repository:

sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm -y

Enable the PHP 8.2 module:

sudo dnf module reset php 
sudo dnf module enable php:remi-8.2

Modifying PHP 8.2 Installation and Extensions

When installing PHP 8.2 and its extensions on AlmaLinux 9.3, you have two primary approaches to choose from. This flexibility allows you to tailor the installation to your specific needs, whether you’re running a complex application requiring numerous extensions or a simpler setup. Here’s how you can proceed with either option:

Option 1: Standard Installation

This approach installs PHP 8.2 along with a wide range of commonly used extensions, covering most use cases for web applications:

sudo dnf install php php-cli php-common php-mbstring php-gd php-intl php-xml php-mysqlnd php-pgsql php-imap php-curl php-exif php-xmlrpc php-soap -y
Option 2: Customized Installation

For a more customized setup, you might want to install PHP and then select specific extensions that are necessary for your application. This method is particularly useful if you’re looking to minimize the installation footprint or if you have unique requirements not covered by the standard installation.

First, install PHP 8.2:

sudo dnf install php php-cli php-common -y

Next, install the extensions you need. Here’s a command that includes a broad selection, but you should adjust it based on your specific needs:

sudo dnf install php-mysqli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-imap php-exif php-xml php-xmlrpc php-pear php-bcmath php-json php-pgsql php-fileinfo php-gmp php-iconv php-intl php-openssl php-soap -y

This approach allows you to tailor your PHP installation more closely to the requirements of your web applications, potentially reducing the attack surface by omitting unused extensions.

Verifying the Installation

Regardless of the option you choose, it’s a good idea to verify your PHP installation and the active extensions:

php -v 
php -m

These commands will show you the installed PHP version and a list of enabled PHP modules, respectively. Ensure that all the extensions you need are listed in the output of php -m.

Step 5: Install IonCube Loader

IonCube Loader is a PHP extension for executing encoded files. Download and install it as follows:

cd /tmp 
wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar xfz ioncube_loaders_lin_x86-64.tar.gz 
sudo cp ioncube/ioncube_loader_lin_8.2.so /usr/lib64/php/modules/ 
echo "zend_extension=ioncube_loader_lin_8.2.so" | sudo tee -a /etc/php.ini

Restart Apache to apply the changes:

sudo systemctl restart httpd

Step 6: Install Webmin

Webmin is a web-based interface for system administration. Install it with:

curl -o setup-repos.sh https://raw.githubusercontent.com/webmin/webmin/master/setup-repos.sh
sh setup-repos.sh
dnf install webmin

Access Webmin by navigating to https://<your-server-ip>:10000. You might need to adjust your firewall settings.

Step 7: Adding Firewall Exceptions for Your LAMP Stack

Securing your server includes properly configuring the firewall to allow necessary traffic while blocking unauthorized access. For a LAMP stack on AlmaLinux 9.3, you typically need to allow HTTP and HTTPS traffic for your web server, along with specific ports for other services like Webmin. Here’s how to manage your firewall settings using firewalld, the default firewall management tool on AlmaLinux.

Step 1: Check firewalld Status

First, ensure firewalld is installed and running:

sudo systemctl status firewalld

If it’s not running, start and enable it on boot:

sudo systemctl start firewalld 
sudo systemctl enable firewalld
Step 2: Allow HTTP and HTTPS Traffic

For a web server, allowing HTTP (port 80) and HTTPS (port 443) traffic is essential. Use the following commands to add exceptions for these services:

sudo firewall-cmd --permanent --add-service=http 
sudo firewall-cmd --permanent --add-service=https
Step 3: Allow Webmin Traffic

If you’ve installed Webmin, you’ll need to allow traffic on port 10000, which is the default port used by Webmin:

sudo firewall-cmd --permanent --add-port=10000/tcp
Step 4: Apply Changes

After adding the necessary exceptions, reload the firewall to apply the changes:

sudo firewall-cmd --reload
Step 5: Verify Firewall Configuration

It’s a good practice to verify your firewall settings to ensure the correct ports and services are allowed. Use this command to list all current settings:

sudo firewall-cmd --list-all

This command provides a comprehensive overview of the active zones, services, and ports allowed through your firewall. Ensure that the services section includes http and https, and the ports section lists any custom ports you’ve opened, such as 10000/tcp for Webmin.

Step 8: Install phpMyAdmin

phpMyAdmin provides a web interface for MySQL/MariaDB administration. Install it using:

sudo dnf install phpMyAdmin -y

Configure access by editing the Apache configuration file for phpMyAdmin:

sudo nano /etc/httpd/conf.d/phpMyAdmin.conf

Adjust the Require ip directive to your client IP or use Require all granted for broader access, then restart Apache:

sudo systemctl restart httpd

Final Thoughts

Congratulations! You’ve successfully set up a LAMP stack on AlmaLinux 9.3, complete with PHP 8.2, IonCube Loader, Apache, MariaDB, Webmin, and phpMyAdmin. This setup provides a solid foundation for hosting and managing web applications. Remember to secure your server and applications, keeping them up-to-date with the latest security patches and updates.

Leave a Reply

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