Install and Configure LAMP Stack on AlmaLinux 10

By Raman Kumar

Updated on Jun 09, 2025

In this tutorial, we'll learn how to install and configure LAMP stack on AlmaLinux 10 server.

If you're looking to host dynamic websites or web applications on your AlmaLinux 10 server, the LAMP stack is the industry-standard setup to get started. LAMP stands for Linux, Apache, MariaDB, and PHP—a powerful combination used by millions of developers and hosting providers worldwide.

This tutorial covers everything from the basics to advanced configurations for setting up a LAMP stack on AlmaLinux 10, the latest release built for stability and performance. 

Prerequisites

Before starting, make sure our new Ubuntu server is ready. The following components should be installed and configured:

  • A AlmaLinux 10 installed dedicated server or KVM VPS.
  • A root user or normal user with administrative privileges.
  • A domain name with pointing A record to server.

Step 1: Update Your AlmaLinux 10 Server

Before starting, make sure your server is up-to-date.

sudo dnf update -y
sudo dnf install epel-release -y

Step 2: Install Apache Web Server (httpd)

Apache is the most widely used web server, trusted for its stability and scalability.

sudo dnf install httpd -y

Enable and start Apache:

sudo systemctl enable httpd
sudo systemctl start httpd

To allow HTTP and HTTPS traffic through the firewall:

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

Verify Apache is running:

sudo systemctl status httpd

Visit your server IP in a browser to see the default Apache test page.

Step 3: Install MariaDB Server (MySQL Alternative)

MariaDB is a reliable open-source fork of MySQL, and it's included in AlmaLinux 10's official repos.

sudo dnf install mariadb-server -y

Enable and start MariaDB:

sudo systemctl enable mariadb
sudo systemctl start mariadb

Run the secure installation:

sudo mysql_secure_installation

Answer the prompts to set root password, remove anonymous users, and secure your installation.

Step 4: Install PHP (Latest Stable Version)

AlmaLinux 10 comes with PHP support. Install PHP along with common extensions:

sudo dnf install php php-mysqlnd php-opcache php-gd php-xml php-mbstring php-cli php-curl -y

Restart Apache to apply PHP:

sudo systemctl restart httpd

Test PHP:

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

Visit http://your-server-ip/info.php to verify PHP is working.

Step 5: Create a Virtual Host for Your Website

To host multiple websites or isolate apps, set up virtual hosts.

Create a new config file:

sudo nano /etc/httpd/conf.d/yourdomain.com.conf

Paste the following:

<VirtualHost *:80>
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/yourdomain.com/public_html
    ErrorLog /var/log/httpd/yourdomain.com_error.log
    CustomLog /var/log/httpd/yourdomain.com_access.log combined
</VirtualHost>

Create directory and set permissions:

sudo mkdir -p /var/www/yourdomain.com/public_html
sudo chown -R apache:apache /var/www/yourdomain.com
sudo chmod -R 755 /var/www

Add an index.php file to test:

echo "<?php echo 'Welcome to yourdomain.com!'; ?>" | sudo tee /var/www/yourdomain.com/public_html/index.php

Restart Apache:

sudo systemctl restart httpd

Step 6: Configure SELinux (Optional but Recommended)

If SELinux is enforcing, set the right context for Apache:

sudo chcon -Rt httpd_sys_content_t /var/www/yourdomain.com

To allow Apache to connect to the database:

sudo setsebool -P httpd_can_network_connect_db 1

Step 7: Enable HTTPS with Let’s Encrypt SSL (Certbot)

Secure your website with free SSL.

Install Certbot and Apache plugin:

sudo dnf install certbot python3-certbot-apache -y

Generate and install SSL certificate:

sudo certbot --apache

Set up auto-renewal:

sudo systemctl enable --now certbot-renew.timer

Step 8: Advanced PHP Configuration (For Performance & Security)

Edit your PHP configuration:

sudo nano /etc/php.ini

Recommended changes:

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
display_errors = Off

Apply changes:

sudo systemctl restart httpd

Step 9: Configure Apache for Security

Hide Apache version:

sudo nano /etc/httpd/conf/httpd.conf

Add:

ServerTokens Prod
ServerSignature Off

Disable directory listing:

<Directory /var/www/>
    Options -Indexes
</Directory>

Step 10: Secure MariaDB with a Dedicated User

Login to MariaDB:

sudo mysql -u root -p

Create a database and user:

CREATE DATABASE myapp_db;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 11: Setup Fail2Ban for Apache

Prevent brute force and bot abuse:

sudo dnf install fail2ban -y
sudo systemctl enable --now fail2ban

Create Apache jail:

sudo nano /etc/fail2ban/jail.d/httpd.conf

Add:

[apache]
enabled = true
port = http,https
logpath = /var/log/httpd/*_log
maxretry = 5

Restart Fail2Ban:

sudo systemctl restart fail2ban

Final Thoughtsnv

In this tutorial, we've learnt how to install and configure LAMP stack on AlmaLinux 10 server. Your AlmaLinux 10 LAMP server is now fully operational—from base setup to advanced optimization. This modern hosting environment is ready for WordPress, Laravel, custom PHP apps, or any dynamic web platform.

As a professional web hosting provider, we recommend regular backups, SSL monitoring, and database optimization to maintain peak performance. For more tutorials like this, bookmark our knowledge base and stay ahead in hosting technology.