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 -yStep 2: Install Apache
Apache is our web server of choice. Install it with:
sudo dnf install httpd -yEnable and start the Apache service:
sudo systemctl enable --now httpdVerify Apache is running:
sudo systemctl status httpdStep 3: Install MariaDB
MariaDB serves as our database management system. Install it using DNF:
sudo dnf install mariadb-server -yThen, enable and start the MariaDB service:
sudo systemctl enable --now mariadbSecure your MariaDB installation:
sudo mysql_secure_installationFollow 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 -yEnable the PHP 8.2 module:
sudo dnf module reset php 
sudo dnf module enable php:remi-8.2Modifying 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 -yNext, 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 -yThis 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 -mThese 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.iniRestart Apache to apply the changes:
sudo systemctl restart httpdStep 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.shdnf install webminAccess 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 firewalldIf it’s not running, start and enable it on boot:
sudo systemctl start firewalld 
sudo systemctl enable firewalldStep 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=httpsStep 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/tcpStep 4: Apply Changes
After adding the necessary exceptions, reload the firewall to apply the changes:
sudo firewall-cmd --reloadStep 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-allThis 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 -yConfigure access by editing the Apache configuration file for phpMyAdmin:
sudo nano /etc/httpd/conf.d/phpMyAdmin.confAdjust the Require ip directive to your client IP or use Require all granted for broader access, then restart Apache:
sudo systemctl restart httpdFinal 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.
 
								




