Guides 11792 Published by

A step‑by‑step guide to installing the full LAMP stack—Apache, MariaDB, and PHP—on AlmaLinux 8. It walks you through updating packages, securing the database, and enabling services for automatic start. The article also highlights common pitfalls like firewall rules and missing PHP extensions. After following the four short sections your server will be ready to host any web application.



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 packages

Keeping 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 Apache
dnf 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.

Real‑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.

Install MariaDB
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 database
mysql_secure_installation

The script walks you through:

  1. Setting a root password – never run with a blank one.
  2. Removing anonymous accounts – they’re a back‑door for anyone on the network.
  3. Disallowing remote root login – unless you really need it, keep it local.
  4. Deleting the test database – it’s just clutter.
  5. 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 extensions
dnf 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 test

Create 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.