
This guide walks through setting up a full LAMP stack (Linux, Apache, MariaDB, PHP) on Rocky Linux 8. The steps are much the same on other releases and on RHEL, so just adjust the PHP and MariaDB versions to suit if you’re on something different.
Prerequisites
You’ll need a user with sudo privileges, which on Rocky Linux means being a member of the wheel group. If your user isn’t already in it, you can add them with:
su -
gpasswd -a user wheel
Step 1: Update the System
Start from a fully updated system so you’re not fighting old packages later:
sudo dnf upgrade -y
Step 2: Add the EPEL and REMI Repositories
The current PHP releases come from the REMI repository, which in turn needs EPEL. Install EPEL first, then the REMI release package, refresh the repo list, and update:
sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
sudo dnf repolist
sudo dnf update -y
Step 3: Install the Apache Web Server
On Rocky Linux, Apache is the httpd package. Install it, then enable and start it in one command so it runs now and comes back after a reboot:
sudo dnf install httpd -y
sudo systemctl enable --now httpd
Confirm it’s running with:
sudo systemctl status httpd
Rocky Linux runs a firewall by default, so you’ll also need to open ports 80 (HTTP) and 443 (HTTPS), otherwise the web server won’t be reachable from other machines:
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --reload
Step 4: Install PHP
PHP is managed as a DNF module, so reset it first to clear the default selection, then list what’s available:
sudo dnf module reset php -y
sudo dnf module list php
Pick a version from the list, for example php:remi-8.0, and install it:
sudo dnf module install php:remi-8.0 -y
You’ll also want the MySQL extension so PHP can talk to the database. The recommended one is php-mysqlnd:
sudo dnf install php-mysqlnd -y
Check the version to confirm PHP installed cleanly:
php -v
Step 5: Test PHP
To make sure Apache and PHP are working together, create a small info file in the web root:
sudo nano /var/www/html/info.php
Add the following, then save:
<?php
phpinfo();
?>
Open localhost/info.php in a browser on the machine itself, or the server’s IP followed by /info.php from another machine on the network, and you should see the PHP info page. Once you’ve confirmed it works, delete the file, since leaving it up exposes details about your server that are better kept private:
sudo rm /var/www/html/info.php
Step 6: Install MariaDB
MariaDB is also a DNF module, so list the available versions first:
sudo dnf module list mariadb
Then install the server, and enable and start it:
sudo dnf install mariadb mariadb-server -y
sudo systemctl enable --now mariadb
Check it’s up:
sudo systemctl status mariadb
Step 7: Secure MariaDB
A fresh install has some insecure defaults, so run the hardening script:
sudo mysql_secure_installation
Work through the prompts, which let you:
- Set the root password
- Remove the anonymous user accounts
- Disallow remote root login
- Remove the test database
- Reload the privilege tables
Saying yes to all of these is the sensible default for any server you’ll expose to real traffic. Once that’s done, you can log in to confirm everything works:
mysql -u root -p
That’s the full LAMP stack in place on Rocky Linux. Apache is serving pages through the firewall, PHP is installed and tested, and MariaDB is running and secured, so you’ve now got a solid base to host a site on. A natural next step is installing phpMyAdmin and WordPress on top, which is covered in the related guide below.


Leave a Reply