Install LAMP stack on Rocky Linux 10 and you will have Apache serving pages, PHP 8.3 processing dynamic requests, and MariaDB ready for an application in about ten minutes. The setup uses Rocky’s repositories, firewalld, and SELinux-friendly file labels, then leaves you with a local database account and a temporary PHP test.
Rocky Linux 10 changed PHP packaging compared with older Enterprise Linux releases: its AppStream repository supplies PHP 8.3 without the old module-stream commands. That means the base repositories are enough for this first deployment; you do not need to add Remi or EPEL just to build the stack.
Prerequisites
- A 64-bit Rocky Linux 10 VPS with at least 2 GB of RAM and 10 GB of free disk space.
- A root SSH session, or a standard account that can invoke
sudosuccessfully. - A public IPv4 address for testing Apache and outbound access to Rocky’s BaseOS and AppStream repositories.
- A domain is optional during installation. You need one before issuing a trusted TLS certificate for a production site.
- A VPSLake Linux VPS if you need a fresh Rocky Linux server with root access.
These examples assume a non-root SSH login. A root session can omit the sudo prefix throughout.
Step 1: Confirm Rocky Linux 10 and update the server
Checking the release first prevents an EL9 or EL8 package instruction from being applied to this machine, while the upgrade installs current security fixes.
grep -E '^(PRETTY_NAME|VERSION_ID|ID_LIKE)=' /etc/os-release
uname -m
sudo dnf upgrade -y
The release should identify Rocky Linux 10 and the architecture should normally be x86_64. The minor release and package versions change over time, so do not hard-code them in later commands.
PRETTY_NAME="Rocky Linux 10.x (Red Quartz)"
VERSION_ID="10.x"
ID_LIKE="rhel fedora"
x86_64
If DNF installs a new kernel, keep this SSH session open until you have confirmed that the VPS can reboot and accept a new connection.
Step 2: Install Apache and open the web ports
Apache serves the document root, while firewalld limits public traffic to SSH and the HTTP services the server actually needs.
sudo dnf install -y httpd firewalld curl
sudo systemctl enable --now firewalld httpd
sudo firewall-cmd --permanent --zone=public --add-service=ssh
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 firewalld
sudo firewall-cmd --zone=public --list-services
Adding SSH before the reload reduces the chance of locking yourself out. If SSH uses a custom port, add that port instead of relying only on the ssh service. The service check should print active for both units, and the firewalld list should include ssh, http, and https.
Test Apache locally before testing the public address. A local response proves the daemon is listening even when a provider-level firewall or DNS record is still wrong.
sudo apachectl configtest
curl -fsSI http://127.0.0.1/
Syntax OK
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Step 3: Install PHP 8.3 from AppStream
Rocky Linux 10’s AppStream repository provides PHP 8.3, and installing the native php package connects PHP to Apache through the packaged Apache PHP module. Rocky 10 no longer needs the dnf module enable and module install pattern used by older releases; see Rocky’s PHP and PHP-FPM documentation for the release-specific packaging notes.
sudo dnf install -y php php-cli php-mysqlnd php-gd php-curl php-zip php-mbstring php-xml php-opcache
php -v
sudo systemctl restart httpd
sudo systemctl is-active httpd
The version line should begin with PHP 8.3, and Apache should remain active. The package list includes the MySQL-compatible connector and common extensions used by PHP applications without pulling in an external repository.
Create a short-lived endpoint that returns a fixed value. This tests PHP execution without exposing the detailed configuration that phpinfo() would reveal.
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 response should be PHP OK. Remove the endpoint after the request, as even a small diagnostic script should not remain in a public document root.
PHP OK
Step 4: Install MariaDB and create a local application database
MariaDB supplies the SQL layer, and a user restricted to localhost lets a website on this VPS connect without exposing port 3306 to the Internet.
sudo dnf install -y mariadb-server mariadb
sudo systemctl enable --now mariadb
sudo systemctl is-active mariadb
sudo mariadb-secure-installation
The security program is interactive. Remove anonymous accounts, reject remote root login, remove the test database, and reload the privilege tables when prompted. Keeping local administrative access through the Unix socket is a sensible default; the application should use its own account. MariaDB explains these choices in the official mariadb-secure-installation reference.
Create a database and a separate login for the application. Replace YOUR_DB_PASSWORD with a long, unique secret before running this block; it is a placeholder, not a password to keep.
sudo mariadb <<'SQL'
CREATE DATABASE lampdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'lampuser'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';
GRANT ALL PRIVILEGES ON lampdb.* TO 'lampuser'@'localhost';
FLUSH PRIVILEGES;
SQL
sudo mariadb -e "SHOW DATABASES LIKE 'lampdb';"
The final query should return one row named lampdb. Keep the real password in your application’s secret configuration, not in a file under /var/www/html.
Verify the LAMP stack
Run these checks together to confirm that Apache, firewalld, and MariaDB start at boot, PHP has the database connector, and the web server answers a local request.
sudo systemctl is-active httpd firewalld mariadb
sudo systemctl is-enabled httpd firewalld 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/
sudo firewall-cmd --zone=public --list-services
Expect three active lines, three enabled lines, Syntax OK, the PHP module names, a MariaDB version, an HTTP success response, and the three public services.
active
active
active
enabled
enabled
enabled
Syntax OK
HTTP/1.1 200 OK
ssh http https
Troubleshooting
No match for argument: php-mysqlnd
The repository metadata may be stale, or the server may not actually be Rocky Linux 10. Confirm the release and refresh Rocky’s enabled repositories before adding any third-party source.
grep -E '^(PRETTY_NAME|VERSION_ID|ID_LIKE)=' /etc/os-release
sudo dnf clean all
sudo dnf makecache
sudo dnf repolist --enabled
Rocky Linux 10 uses the AppStream PHP package rather than a PHP module stream. Do not run an EL9 module command or install repositories built for another Enterprise Linux major version.
PHP source appears in the browser
Apache is serving the .php file as text because the PHP Apache module is missing or the web server has not been restarted after installation. Check the loaded modules and package state, then restart Apache.
sudo dnf reinstall -y php php-cli
sudo httpd -M | grep php_module
sudo apachectl configtest
sudo systemctl restart httpd
The module check should print a line containing php_module. Recreate the temporary health.php endpoint from Step 3, test it locally, and remove it again.
403 Forbidden after changing files in /var/www/html
Apache may be blocked by an incorrect SELinux label or unreadable file mode. Restore the standard web-content labels and use readable, non-world-writable permissions; 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
If an application needs uploads, label only its upload directory with the appropriate SELinux policy after checking the application’s requirements instead of making the entire document root writable.
Access denied for user 'lampuser'@'localhost'
The application password differs from the value used when the account was created, or the application is connecting with a different database host. Test the credentials over the local socket before changing grants.
mariadb -u lampuser -p lampdb -e "SELECT 1;"
Enter the real password, not the placeholder. If it is wrong, reset the account from the administrative socket and update the application configuration at the same time.
sudo mariadb -e "ALTER USER 'lampuser'@'localhost' IDENTIFIED BY 'NEW_DB_PASSWORD';"
Hardening
- Keep port 3306 closed in firewalld. A local application can use
localhostor MariaDB’s Unix socket without public database access. - Point
YOUR_DOMAINto the VPS, issue a trusted TLS certificate, and redirect HTTP to HTTPS before accepting logins or other sensitive data. - Restore SELinux labels after copying site files, remove temporary health checks, and never place database passwords under
/var/www/html. - Apply Rocky Linux updates regularly and back up both the web root and MariaDB databases before major PHP or application changes.
FAQ
Which PHP version does Rocky Linux 10 use?
Rocky Linux 10’s AppStream repository provides PHP 8.3, with patch updates arriving through normal DNF updates. The exact patch number can change, so the guide checks the installed version rather than pinning one build.
Why does this guide not enable a PHP module stream?
Rocky Linux 10 follows the EL10 packaging change in which the default PHP version comes directly from AppStream. The older dnf module enable php:8.3 commands belong to releases that still publish PHP as a module stream.
Should I open MariaDB port 3306 for a PHP website?
No. A PHP application on the same VPS can connect through localhost or the Unix socket. Only configure remote database access for a separate host that genuinely needs it, and then restrict the source address and require encryption.
Can I install the stack before I have a domain?
Yes. Apache and the PHP test work with the VPS IP or loopback address. Add the domain later, create a name-based Apache virtual host, and obtain a TLS certificate after DNS points to the server.