Install LAMP stack on AlmaLinux 10 with Apache, PHP 8.3, PHP-FPM, and MariaDB in about ten minutes. You will finish with a running web server, a local database user, firewalld rules for web traffic, and a safe PHP request test.
AlmaLinux 10 uses DNF, firewalld, and SELinux, so the commands below follow the Enterprise Linux 10 layout instead of Ubuntu conventions. The PHP packages come from the AlmaLinux repositories, which keeps the initial stack simple to update.
Prerequisites
- A fresh 64-bit AlmaLinux 10 VPS with at least 2 GB of RAM and 10 GB of free disk space.
- SSH access as
root, or a normal account with workingsudoprivileges. - Outbound internet access for DNF repositories and a public IPv4 address for browser testing.
- A domain is optional for this base installation. You need one before putting a production site behind a trusted TLS certificate.
- A VPSLake Linux VPS if you need an AlmaLinux server with root access.
The commands use sudo for a non-root SSH account. If you are already logged in as root, remove sudo from each command.
Step 1: Confirm AlmaLinux 10 and update packages
Checking the release first prevents you from applying Enterprise Linux instructions to the wrong system.
grep -E '^(PRETTY_NAME|VERSION_ID|ID_LIKE)=' /etc/os-release
uname -m
sudo dnf upgrade -y
The first command should identify AlmaLinux 10 and the architecture should normally be x86_64. The exact minor version changes as updates are published.
PRETTY_NAME="AlmaLinux 10.x (Purple Lion)"
VERSION_ID="10.x"
ID_LIKE="rhel centos fedora"
x86_64
If the upgrade installs a new kernel, keep the current SSH session open until you have confirmed that the VPS can reboot and reconnect.
Step 2: Install Apache and allow web traffic
Apache serves the static files and hands PHP requests to PHP-FPM later, while firewalld controls which public services can reach the VPS.
sudo dnf install -y httpd policycoreutils-python-utils
sudo systemctl enable --now 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, and firewalld should report http and https among the enabled services. HTTPS is opened now so a later TLS setup does not require another firewall change.
curl -I http://SERVER_IP
Replace SERVER_IP with the VPS public IP. A healthy Apache installation returns an HTTP response such as 200 OK.
Step 3: Install PHP 8.3 and PHP-FPM
AlmaLinux 10’s base application stream provides PHP 8.3; PHP-FPM runs PHP outside Apache’s worker process and is the supported web-server arrangement for this release.
sudo dnf install -y php php-fpm php-mysqlnd php-gd php-mbstring php-opcache php-xml
sudo systemctl enable --now php-fpm httpd
php -v
sudo systemctl is-active php-fpm httpd
The version will include a current 8.3 patch number, and both services should be active. For the PHP-FPM model and its configuration files, see the official PHP-FPM documentation.
Create a short-lived PHP endpoint to test execution rather than exposing phpinfo(), which can disclose server configuration. The endpoint is removed 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 command should print PHP OK. If it prints PHP source code or returns a 503 response, stop and use the troubleshooting section before deploying an application.
Step 4: Install and secure MariaDB
MariaDB supplies the relational database layer, and the local-only application account below avoids exposing database traffic on the public network.
sudo dnf install -y mariadb-server mariadb
sudo systemctl enable --now mariadb
sudo systemctl is-active mariadb
sudo mariadb-secure-installation
The hardening script may use slightly different prompts as MariaDB changes. Keep Unix-socket authentication for the administrative account, remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables. MariaDB documents these choices in its mariadb-secure-installation reference.
Create an application database and a separate local user. Replace YOUR_DB_PASSWORD with a long, unique password before running this block; it is a placeholder, not a password to keep.
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 last command should return one row named appdb. Keep the database name, username, and real password for the application installer; do not open TCP port 3306 for this local connection.
Verify the LAMP stack
Run the checks below from SSH. Together they confirm that all three daemons start, Apache accepts its configuration, PHP modules for MariaDB are loaded, and the web server answers locally.
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 three active lines, three enabled lines, Syntax OK, the listed PHP modules, a MariaDB version, and an HTTP success response.
active
active
active
enabled
enabled
enabled
Syntax OK
HTTP/1.1 200 OK
Troubleshooting
No match for argument: php-fpm or php-mysqlnd
DNF may have stale metadata, disabled repositories, or the machine may not actually be AlmaLinux 10. Confirm the release and refresh metadata before adding any third-party PHP repository.
grep -E '^(PRETTY_NAME|VERSION_ID)=' /etc/os-release
sudo dnf clean all
sudo dnf makecache
sudo dnf repolist --enabled
If the release is not AlmaLinux 10, stop and use instructions for the installed release. Do not mix EL9 and EL10 repositories.
Apache returns 503 Service Unavailable for PHP
PHP-FPM is stopped, failed to start, or Apache has a syntax error in a drop-in configuration. Check the service log and configuration, then restart only after correcting the reported problem.
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
403 Forbidden after changing files under /var/www/html
A custom file may have the wrong owner, mode, or SELinux label. Restore the default web-content labels and ensure Apache can read the files; do not disable 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 application password does not match the value used in CREATE USER, or the account was created for a different host. Test the credentials through the local socket and recreate the account only if you have confirmed the intended password.
mariadb -u appuser -p appdb -e "SELECT 1;"
Enter the real value that replaced YOUR_DB_PASSWORD. A result containing 1 confirms that the account can reach its database without making MariaDB publicly accessible.
Hardening
- Keep port 3306 closed in firewalld. Applications on this VPS can use the local MariaDB socket or
localhostwithout a public database listener. - Remove temporary health-check files after testing, and never leave
phpinfo()or database passwords in the web root. - For a real domain, point DNS to the VPS, obtain a trusted TLS certificate, and redirect HTTP to HTTPS before accepting logins or other sensitive data.
- Apply regular AlmaLinux updates and back up both
/var/www/htmland the MariaDB databases before changing PHP or Apache configuration.
FAQ
What is included in a LAMP stack on AlmaLinux 10?
LAMP means Linux, Apache, MariaDB, and PHP. In this guide, Apache is the httpd service, PHP runs through PHP-FPM, and MariaDB provides the SQL database service.
Do I need PHP 8.4 or PHP 8.5 for this installation?
No. The AlmaLinux 10 base repositories provide PHP 8.3 for a stable starting point. If an application specifically requires another supported PHP stream, check that application’s compatibility requirements and use a repository designed for AlmaLinux 10 rather than mixing package sources.
Should I open port 3306 for my website?
No. A website running on the same VPS can connect to MariaDB through localhost or the Unix socket. Leave 3306 closed unless a separate host truly needs database access, and then restrict the source address and use encrypted database connections.
Can I install MySQL instead of MariaDB?
Yes, but the server package, service behavior, authentication defaults, and security commands differ. Use one database server for this stack and follow that product’s AlmaLinux 10 documentation instead of installing both database implementations together.