Install PHP 8.3, MySQL, phpMyAdmin, and Apache on Alma / Rocky Linux (LAMP Stack)
Author
John CavilCentOS 7 is dead (EOL was June 30, 2024).
AlmaLinux and Rocky Linux are supported, RHEL-compatible rebuilds, so if CentOS 7 were still alive, the overall LAMP install flow would look essentially the same.
Prerequisites
- Root or sudo access
- AlmaLinux/Rocky 8 or 9
- Internet access to pull repositories/packages
Check your major version:
cat /etc/os-release
rpm -E %rhel
1) Update the server
sudo dnf -y update
sudo reboot
2) Install Apache (httpd)
sudo dnf -y install httpd
sudo systemctl enable --now httpd
Open HTTP/HTTPS in the firewall:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Quick check:
curl -I http://127.0.0.1
3) Install MySQL Community Server (8.4 LTS by default)
Alma/Rocky ship MariaDB in the base repos, so for Oracle MySQL you install the official MySQL repo RPM first. The current repo setup RPMs are published by MySQL (EL8/EL9).
3.1 Add the MySQL Yum repo (EL9 vs EL8)
For EL9 (Alma/Rocky 9):
sudo dnf -y install https://dev.mysql.com/get/mysql84-community-release-el9-2.noarch.rpm
For EL8 (Alma/Rocky 8):
sudo dnf -y install https://dev.mysql.com/get/mysql84-community-release-el8-2.noarch.rpm
3.2 Install and start MySQL
sudo dnf -y install mysql-community-server
sudo systemctl enable --now mysqld
3.3 Set root password and secure MySQL
MySQL generates a temporary root password and writes it to the error log; grab it like this:
sudo grep 'temporary password' /var/log/mysqld.log
Then run:
sudo mysql_secure_installation
Optional: Use MySQL 8.0 instead of 8.4
MySQL’s Yum repo enables 8.4 LTS by default; other series (like 8.0) are available as separate subrepos you can enable/disable.
Edit /etc/yum.repos.d/mysql-community.repo, disable the 8.4 repo, enable the 8.0 repo, then dnf install mysql-community-server.
4) Install PHP 8.3 (Remi) + common extensions
Remi’s repo is the standard way to get a consistent PHP 8.3 on EL8/EL9, and the exact flow is: install EPEL + Remi release RPM, enable CRB/PowerTools, then switch the PHP module to remi-8.3.
4.1 Enable CRB / PowerTools (needed for EPEL deps)
- EL9:
crb - EL8:
powertools
sudo dnf -y install dnf-plugins-core
# EL9:
sudo dnf config-manager --set-enabled crb
# EL8:
sudo dnf config-manager --set-enabled powertools
4.2 Install EPEL + Remi release RPM
EL9:
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
EL8:
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
(Those are Remi’s published install URLs for Alma/Rocky 8/9.)
4.3 Enable PHP 8.3 module stream and install PHP
sudo dnf -y module reset php
sudo dnf -y module install php:remi-8.3
Install PHP + common modules for LAMP:
sudo dnf -y install \
php php-cli php-common php-opcache \
php-mysqlnd \
php-gd php-mbstring php-xml php-json php-zip php-curl php-intl
Restart Apache:
sudo systemctl restart httpd
5) Install phpMyAdmin
phpMyAdmin is typically installed from EPEL on EL-family systems; once EPEL is enabled (and CRB/PowerTools is on), the package install is straightforward.
sudo dnf -y install phpmyadmin
sudo systemctl restart httpd
5.1 Allow access (don’t leave it wide open)
EPEL’s Apache config often restricts phpMyAdmin to localhost by default; edit the Apache config and allow only your IP (or your admin subnet).
Common location:
sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
Typical pattern (example: allow only your workstation IP):
Require ip 203.0.113.10
Reload:
sudo systemctl reload httpd
Access it:
http://YOUR_SERVER_IP/phpmyadmin
6) Validate the stack
6.1 Confirm versions
php -v
mysql --version
httpd -v
6.2 Quick PHP test page
echo '<?php echo "PHP OK\n"; ?>' | sudo tee /var/www/html/health.php
curl -s http://127.0.0.1/health.php
(Optional) If you also want a phpinfo() page for debugging, Rocky’s docs show the classic info.php method—just don’t leave it sitting there.
Troubleshooting
Apache shows PHP code instead of executing it
- Verify PHP is installed from the expected module stream:
sudo dnf module list php - Restart Apache:
sudo systemctl restart httpd
phpMyAdmin 403 Forbidden
- You didn’t allow your IP in
/etc/httpd/conf.d/phpMyAdmin.conf. Fix theRequirerules, then:sudo systemctl reload httpd
Can’t log in to MySQL root
- Re-check the generated temporary password:
sudo grep 'temporary password' /var/log/mysqld.log
Leave a Comment