How to Install LAMP Stack on AlmaLinux 8 (Step-by-Step)

Install LAMP stack on AlmaLinux 8 with Apache, PHP 8.2, MariaDB, PHP-FPM, and firewalld, then verify a working web server on a fresh VPS in minutes.
A blue-lit web server, PHP processor, and database cylinder connected by glowing data trails.

Install LAMP stack on AlmaLinux 8 with Apache, PHP 8.2, PHP-FPM, and MariaDB in about ten minutes. You will finish with a firewalld-protected web server, a local application database, and a safe PHP health check.

AlmaLinux 8.10 provides the PHP 8.2 and MariaDB 10.11 application streams used here. The commands use DNF, systemd, firewalld, and SELinux-compatible defaults so you can move from a fresh VPS to a working application base without third-party repositories.

Prerequisites

  • A 64-bit AlmaLinux 8 VPS, preferably updated to 8.10, with at least 2 GB of RAM and 10 GB of free disk space.
  • SSH access as root, or a regular account with working sudo privileges.
  • A public IPv4 address for testing HTTP access. A domain is optional for this installation, but required for a production TLS certificate.
  • A VPSLake Linux VPS with root access if you need a server for this stack.

The examples assume a non-root SSH account. If you are logged in as root, remove sudo from each command.

Step 1: Confirm the release and apply updates

Checking the release first keeps EL8 instructions away from an EL9 or EL10 machine, while updating packages installs current security fixes.

grep -E '^(PRETTY_NAME|VERSION_ID|ID_LIKE)=' /etc/os-release
uname -m
sudo dnf upgrade -y

You should see AlmaLinux 8 and normally the x86_64 architecture. The minor release and package versions may change as AlmaLinux publishes updates.

PRETTY_NAME="AlmaLinux 8.10 (Cerulean Leopard)"
VERSION_ID="8.10"
x86_64

If the upgrade installs a new kernel, keep this SSH session open until you know the VPS can reboot and reconnect.

Step 2: Install Apache and open web ports

Apache serves your site files, while firewalld limits public traffic to the HTTP and HTTPS services the web server needs.

sudo dnf install -y httpd firewalld
sudo systemctl enable --now firewalld httpd
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
sudo systemctl is-active httpd
sudo firewall-cmd --zone=public --list-services

The service check should print active; the firewalld output should include http and https. HTTPS is opened now so adding a certificate later does not require another firewall change.

curl -I http://127.0.0.1

An Apache response normally starts with HTTP/1.1 200 OK or another successful HTTP status.

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8

Step 3: Install PHP 8.2 and PHP-FPM

PHP-FPM runs PHP through FastCGI, keeping application execution separate from Apache’s web-serving process. AlmaLinux 8.10’s AppStream includes the PHP 8.2 stream, so no external repository is needed for this base setup.

sudo dnf module reset php -y
sudo dnf module enable php:8.2 -y
sudo dnf module install php:8.2 -y
sudo dnf install -y php-mysqlnd php-gd php-mbstring php-opcache php-xml php-curl php-intl php-pecl-zip
sudo systemctl enable --now php-fpm httpd
php -v
sudo systemctl is-active php-fpm httpd

The version should begin with PHP 8.2, and both services should report active. The PHP module command installs the common profile, which includes PHP-FPM and its Apache integration. The PHP-FPM documentation explains the process manager used by this layout.

PHP 8.2.x (cli) (built: ...)
active
active

Test execution with a temporary endpoint rather than exposing phpinfo(), which can reveal configuration details. The last command removes the file immediately after the request.

printf '%s\n' '<?php echo "PHP OK\\n"; ?>' | sudo tee /var/www/html/health.php > /dev/null
curl -fsS http://127.0.0.1/health.php
sudo rm -f /var/www/html/health.php

The curl request should print PHP OK. If it prints PHP source code, PHP-FPM is not connected to Apache; use the troubleshooting checks below before deploying an application.

Step 4: Install and secure MariaDB

MariaDB stores application data, and the local database account created below avoids exposing port 3306 to the Internet.

sudo dnf install -y mariadb-server mariadb
sudo systemctl enable --now mariadb
sudo systemctl is-active mariadb
sudo mariadb-secure-installation

The security script is interactive. Remove anonymous accounts, disallow remote root login, remove the test database, and reload the privilege tables. On current MariaDB releases, keeping Unix-socket authentication for the administrative account is a reasonable default; you do not need to force a root password just to complete this guide. See the official MariaDB security script reference for prompt details.

Create a database and a separate user for your application. Replace YOUR_DB_PASSWORD with a long, unique password before running the block.

sudo mariadb <<'SQL'
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
SQL
sudo mariadb -e "SHOW DATABASES LIKE 'appdb';"

The final query should return one row named appdb. Keep the real password in your application’s secret store, not in a web-accessible file.

Verify the LAMP stack

Run these checks together to confirm that Apache, PHP-FPM, and MariaDB start at boot, Apache accepts its configuration, PHP has the database connector, and the server answers a local request.

sudo systemctl is-active httpd php-fpm mariadb
sudo systemctl is-enabled httpd php-fpm mariadb
sudo apachectl configtest
php -m | grep -E 'mysqli|mysqlnd|PDO|mbstring|xml'
sudo mariadb -e "SELECT VERSION();"
curl -fsSI http://127.0.0.1/

Expected output includes four active lines, three enabled lines, Syntax OK, the PHP modules, a MariaDB version, and an HTTP success response.

active
active
active
active
enabled
enabled
enabled
Syntax OK
HTTP/1.1 200 OK

Troubleshooting

No match for argument: php-fpm or php-pecl-zip

The PHP stream may not be enabled, metadata may be stale, or the system may not be running the expected AlmaLinux release. Confirm the OS and refresh the native repositories before considering any third-party source.

grep -E '^(PRETTY_NAME|VERSION_ID)=' /etc/os-release
sudo dnf clean all
sudo dnf makecache
sudo dnf module list php

The list should contain the 8.2 stream on a current AlmaLinux 8.10 system. Do not mix EL9 or EL10 repositories into an EL8 installation.

PHP source appears in the browser

Apache is serving the .php file as plain text because PHP-FPM or the Apache PHP handler is unavailable. Check the services and Apache configuration, then restart the two services.

sudo systemctl status php-fpm --no-pager
sudo journalctl -u php-fpm -n 40 --no-pager
sudo apachectl configtest
sudo systemctl restart php-fpm httpd

After the restart, recreate the temporary health endpoint and test it with curl. Remove it again when the response is correct.

403 Forbidden after changing files in /var/www/html

Incorrect permissions or SELinux labels can prevent Apache from reading a file. Restore the standard label and use readable, non-world-writable modes; do not turn off SELinux.

sudo restorecon -Rv /var/www/html
sudo find /var/www/html -type d -exec chmod 0755 {} +
sudo find /var/www/html -type f -exec chmod 0644 {} +
sudo systemctl reload httpd

Access denied for user 'appuser'@'localhost'

The password entered by the application does not match the account, or the account was created for a different host. Test the credentials through the local connection before changing grants.

mariadb -u appuser -p appdb -e "SELECT 1;"

Enter the real value used instead of YOUR_DB_PASSWORD. A result containing 1 confirms that the account can access appdb without making MariaDB public.

Hardening

  • Keep port 3306 closed in firewalld. Local applications can use localhost or the Unix socket.
  • Point your domain to the VPS, issue a trusted TLS certificate, and redirect HTTP to HTTPS before accepting logins or personal data.
  • Remove temporary health-check files and never store database passwords under /var/www/html.
  • Schedule AlmaLinux updates and back up both the web root and MariaDB databases before major PHP or application changes.

FAQ

What does LAMP mean on AlmaLinux 8?

LAMP stands for Linux, Apache, MariaDB, and PHP. In this setup, httpd serves requests, PHP-FPM executes PHP through FastCGI, and MariaDB handles relational data.

Is PHP 8.2 available from the AlmaLinux 8 repositories?

Yes. AlmaLinux 8.10 updated its AppStream module streams to include PHP 8.2. Enable that stream explicitly so a machine with an older default does not silently install an outdated PHP branch.

Do I need to open port 3306 for WordPress or another website?

No. An application on the same VPS can connect to MariaDB over localhost without public database access. Only open 3306 for a separate host when you have a specific need and a tightly restricted source address.

Can I use MySQL instead of MariaDB?

You can, but the package names, service behavior, authentication defaults, and security commands change. Choose one database server and follow its own AlmaLinux 8 installation guidance rather than installing both implementations together.

Samrat Ghosh
Written by

Samrat Ghosh

Founder & Infrastructure Engineer

Samrat Ghosh is the founder of VPSLake, where he builds and runs the remote desktop and VPS hosting infrastructure the company is built on. He writes hands-on guides about RDP, Windows Server, VPS management and secure remote access - the practical documentation he wishes had…

Previous Article

Best RDP for Sri Lanka in 2026: Price, Speed and Payment

Write a Comment

Leave a Comment

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

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨