In this tutorial, we'll learn how to install and configure LAMP stack on AlmaLinux 10.
Setting up a powerful web server begins with a solid stack. The LEMP stack—Linux, Nginx (pronounced “Engine-X”), MariaDB (or MySQL), and PHP—is a fast, reliable, and secure solution for hosting modern websites and applications. In this step-by-step guide, we’ll walk you through installing and configuring the LEMP stack on AlmaLinux 10, the newly released enterprise-grade Linux distro that’s perfect for hosting.
This guide is written by a professional web hosting provider and is tailored for both beginners and experienced sysadmins who want a clean, modern setup on AlmaLinux 10. Let’s get started.
Prerequisites
Before we begin, let’s ensure we have the following in place:
- A AlmaLinux 10 dedicated server or KVM VPS.
- A basic programming knowledge.
- A domain name pointing at server IP.
Step 1: Update the AlmaLinux 10 System
Start by updating your system packages to the latest available versions.
sudo dnf update -y
sudo dnf install epel-release -y
Step 2: Install Nginx Web Server on AlmaLinux 10
Nginx is a lightweight and high-performance web server widely used for hosting PHP applications.
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
Verify Nginx:
Visit your server’s IP address in a browser:
http://your_server_ip
You should see the Nginx default welcome page.
Step 3: Install MariaDB (MySQL Alternative)
MariaDB is a drop-in replacement for MySQL and fully supported by AlmaLinux.
sudo dnf install mariadb-server mariadb -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure the installation:
sudo mysql_secure_installation
Follow the prompts to set the root password and secure your database server.
Step 4: Install PHP 8.2 and Required Extensions
LEMP uses PHP to handle dynamic web content. Install PHP along with essential modules for Nginx compatibility.
sudo dnf install -y php php-fpm php-mysqlnd php-cli php-opcache php-gd php-curl php-mbstring php-xml php-common
Enable and start PHP-FPM:
sudo systemctl enable php-fpm
sudo systemctl start php-fpm
Configure PHP Processor:
Edit the file:
sudo nano /etc/php-fpm.d/www.conf
Set the user and group to nginx:
user = nginx
group = nginx
Then restart PHP-FPM:
sudo systemctl restart php-fpm
Step 5: Configure Nginx to Use PHP
Create a new Nginx server block (virtual host):
sudo nano /etc/nginx/conf.d/lemp-site.conf
Paste the following configuration:
server {
listen 80;
server_name your_domain.com;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Restart Nginx:
sudo systemctl restart nginx
Step 6: Test PHP Processing
Create a test PHP file:
echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/info.php
Visit:
http://your_server_ip/info.php
You should see the PHP info page, confirming that PHP is working with Nginx.
Step 7: Adjust Firewall Settings
If your firewall is enabled, allow HTTP and HTTPS:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Step 8: Secure Your Server with SSL (Optional but Recommended)
Install Certbot for free Let's Encrypt SSL:
sudo dnf install certbot python3-certbot-nginx -y
Run the following to generate and install the SSL certificate:
sudo certbot --nginx
Set up automatic SSL renewal:
echo "0 0 * * * root certbot renew --quiet" | sudo tee -a /etc/crontab > /dev/null
Advanced Configuration Tips
1. Enable Gzip Compression
sudo nano /etc/nginx/nginx.conf
Inside http {}
block:
gzip on;
gzip_types text/plain application/xml application/json text/css application/javascript;
2. PHP Optimization (in php.ini)
sudo nano /etc/php.ini
Recommended tweaks:
memory_limit = 256M
upload_max_filesize = 50M
post_max_size = 50M
max_execution_time = 300
Restart PHP-FPM:
sudo systemctl restart php-fpm
3. Secure MariaDB with Better Settings (Optional)
Edit the config:
sudo nano /etc/my.cnf.d/mariadb-server.cnf
Add:
[mysqld]
bind-address=127.0.0.1
skip-name-resolve
Final Notes
In this tutorial, we've learnt how to install and configure LAMP stack on AlmaLinux 10. You have the performance of Nginx, the flexibility of PHP, and the reliability of MariaDB. This stack is ideal for running content management systems like WordPress, Laravel apps, or any modern PHP-based site.
If you're a developer or running a web hosting business like us, keeping your LEMP stack clean and secure is key. AlmaLinux 10 is a powerful CentOS alternative that gives you long-term support and a modern, secure foundation.