Install LAMP Stack on AlmaLinux 8
You’re about to turn a fresh AlmaLinux 8 box into a working LAMP server. This guide shows the exact commands, why each one matters, and a couple of pitfalls you might run into if you skip the obvious steps.
Update all installed packagesKeeping the base system current prevents obscure library mismatches later on.
dnf update -y
Why? The dnf tool pulls in security patches and newer versions of core libraries that Apache, MariaDB and PHP will link against. Skipping this step can leave you chasing “missing symbol” errors after the LAMP install.
Install and start Apachednf install httpd httpd-tools -y
systemctl start httpd
systemctl enable httpd
Apache is the web server that will serve your PHP pages. Enabling it makes sure it comes up automatically after a reboot, which saves you from manually typing systemctl start httpd every time.
Install MariaDBReal‑world note: I once deployed AlmaLinux on a VPS and forgot to open port 80 in firewalld. The service was running fine, but the browser just showed “connection refused”. A quick firewall-cmd --add-service=http --permanent && firewall-cmd --reload fixed it.
dnf install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
MariaDB stores your data. Starting and enabling the daemon now means you won’t have to hunt down a dead socket when your PHP app tries to connect.
Secure the databasemysql_secure_installation
The script walks you through:
- Setting a root password – never run with a blank one.
- Removing anonymous accounts – they’re a back‑door for anyone on the network.
- Disallowing remote root login – unless you really need it, keep it local.
- Deleting the test database – it’s just clutter.
- Reloading privilege tables – applies your changes immediately.
If you answer “Y” to everything, you’ll have a lock‑tight MariaDB ready for production.
Install PHP and common extensionsdnf install php php-mysqlnd php-dom php-simplexml php-xml \
php-curl php-exif php-ftp php-gd php-iconv php-json \
php-mbstring php-posix -y systemctl restart httpd
PHP is the glue that talks to Apache and MariaDB. The extension list covers most everyday scripts (WordPress, Drupal, custom APIs). Restarting Apache reloads the new PHP module so your pages are interpreted correctly.
Quick sanity testCreate a file called /var/www/html/info.php with this single line:
<?php phpinfo(); ?>
Then point your browser to http://your-server-ip/info.php. If you see a massive page full of configuration details, the stack is alive. Remember to delete that file afterward; it’s a gold mine for would‑be attackers.
That’s all there is to it. Your AlmaLinux 8 box now runs a fully functional LAMP environment, ready for whatever web app you want to throw at it.