{"id":1185,"date":"2026-11-27T09:00:00","date_gmt":"2026-11-27T09:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1185"},"modified":"2026-11-27T09:00:00","modified_gmt":"2026-11-27T09:00:00","slug":"install-lamp-stack-rocky-linux-9","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/27\/install-lamp-stack-rocky-linux-9\/","title":{"rendered":"How to Install LAMP Stack on Rocky Linux 9 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install lamp stack on Rocky Linux 9 and you will have Apache serving web pages, PHP 8.3 handling dynamic requests, and MariaDB ready for an application database. On a fresh VPS, the setup takes about ten minutes and includes firewalld rules plus a disposable PHP health check.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 9 uses DNF modules for alternate application versions. This guide selects the PHP 8.3 AppStream stream, keeps PHP behind PHP-FPM, and leaves SELinux enabled rather than weakening the server to make a test site work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>A 64-bit Rocky Linux 9 VPS with at least 2 GB of RAM and 10 GB of free disk space.<\/li>\n\n\n<li>SSH access as <code>root<\/code>, or a regular account that can run <code>sudo<\/code>.<\/li>\n\n\n<li>A public IPv4 address and outbound access to Rocky Linux BaseOS and AppStream repositories.<\/li>\n\n\n<li>A domain is optional while installing the stack. You need <code>YOUR_DOMAIN<\/code> later for a named Apache virtual host and a trusted TLS certificate.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need a fresh Rocky Linux server with root access.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The commands assume a non-root SSH session. If you are already logged in as <code>root<\/code>, remove <code>sudo<\/code> from each command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Confirm Rocky Linux 9 and apply updates<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking the release first prevents an EL8 or EL10 package instruction from being applied to this server, while the update installs current security fixes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(PRETTY_NAME|VERSION_ID|ID_LIKE)=' \/etc\/os-release\nuname -m\nsudo dnf upgrade -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release should identify Rocky Linux 9 and the architecture should normally be <code>x86_64<\/code>. The exact minor release and package revisions change as Rocky publishes updates, so do not copy a version number from an old install log.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Rocky Linux 9.x (Blue Onyx)\"\nVERSION_ID=\"9.x\"\nID_LIKE=\"rhel fedora\"\nx86_64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the upgrade installs a new kernel, keep the current SSH connection open until you have confirmed that the VPS can reboot and accept a new connection.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Apache and permit web traffic<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache handles HTTP requests, while firewalld limits public access to SSH and the two web ports used by an HTTP-to-HTTPS deployment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y httpd firewalld curl\nsudo systemctl enable --now firewalld httpd\nsudo firewall-cmd --permanent --zone=public --add-service=ssh\nsudo firewall-cmd --permanent --zone=public --add-service=http\nsudo firewall-cmd --permanent --zone=public --add-service=https\nsudo firewall-cmd --reload\nsudo systemctl is-active httpd firewalld\nsudo firewall-cmd --zone=public --list-services<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the SSH rule before reloading firewalld so a normal SSH connection remains allowed. If SSH listens on a custom port, add that port with <code>--add-port=YOUR_SSH_PORT\/tcp<\/code> and replace the placeholder with the numeric port.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Put a small index file in the document root before testing. A local response confirms that Apache is listening even when a provider firewall, DNS record, or browser is the real source of a later connectivity problem.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>printf '%s\\n' 'Rocky Linux 9 Apache is running.' | sudo tee \/var\/www\/html\/index.html &gt; \/dev\/null\nsudo apachectl configtest\ncurl -fsSI http:\/\/127.0.0.1\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Syntax OK\nHTTP\/1.1 200 OK\nContent-Type: text\/html; charset=UTF-8<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install PHP 8.3 with PHP-FPM<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 9.6 and later 9.x updates provide PHP 8.3 as an AppStream module. PHP-FPM runs the interpreter separately from Apache, which gives PHP requests a clear service boundary and avoids older <code>mod_php<\/code> instructions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf module reset php -y\nsudo dnf module enable php:8.3 -y\nsudo dnf module install php:8.3\/common -y\nsudo dnf install -y php-mysqlnd php-gd php-mbstring php-opcache php-xml php-curl php-intl php-zip\nsudo systemctl enable --now php-fpm httpd\nphp -v\nsudo systemctl is-active php-fpm httpd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The version line should begin with <code>PHP 8.3<\/code>, and both units should report <code>active<\/code>. The <a href=\"https:\/\/www.php.net\/manual\/en\/install.fpm.php\" target=\"_blank\" rel=\"noopener\">PHP-FPM documentation<\/a> describes the process manager used for these requests. Rocky\u2019s <a href=\"https:\/\/docs.rockylinux.org\/guides\/web\/php\/\" target=\"_blank\" rel=\"noopener\">PHP and PHP-FPM guide<\/a> covers the distribution package layout.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a short-lived endpoint that returns a fixed value. This proves Apache can pass a <code>.php<\/code> request to FPM without publishing the detailed configuration that <code>phpinfo()<\/code> would reveal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>printf '%s\\n' '&lt;?php echo \"PHP OK\"; ?&gt;' | sudo tee \/var\/www\/html\/health.php &gt; \/dev\/null\ncurl -fsS http:\/\/127.0.0.1\/health.php\nsudo rm -f \/var\/www\/html\/health.php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The response should be <code>PHP OK<\/code>. Remove the endpoint immediately after the test; diagnostic files do not belong in a public document root.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP OK<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Install MariaDB and create an application database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB provides the SQL layer, and a user restricted to <code>localhost<\/code> lets a website on this VPS connect without exposing port 3306 to the Internet.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y mariadb-server mariadb\nsudo systemctl enable --now mariadb\nsudo systemctl is-active mariadb\nsudo mariadb-secure-installation<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The security utility 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; an application should have its own database account.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a database and a separate login for the application. Replace <code>YOUR_DB_PASSWORD<\/code> with a long, unique secret before running the block; the placeholder is not a password to keep.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mariadb &lt;&lt;'SQL'\nCREATE DATABASE lampdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\nCREATE USER 'lampuser'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';\nGRANT ALL PRIVILEGES ON lampdb.* TO 'lampuser'@'localhost';\nFLUSH PRIVILEGES;\nSQL\nsudo mariadb -e \"SHOW DATABASES LIKE 'lampdb';\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final query should return one row named <code>lampdb<\/code>. Keep the real password in your application\u2019s secret configuration, not in <code>\/var\/www\/html<\/code> or a shell history file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the LAMP stack<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run these checks together to confirm that Apache, PHP-FPM, firewalld, and MariaDB are active and enabled at boot, PHP has the MariaDB connector, and the web server answers locally.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl is-active httpd php-fpm firewalld mariadb\nsudo systemctl is-enabled httpd php-fpm firewalld mariadb\nsudo apachectl configtest\nphp -m | grep -E 'mysqli|mysqlnd|PDO|mbstring|xml'\nsudo mariadb -e \"SELECT VERSION();\"\ncurl -fsSI http:\/\/127.0.0.1\/\nsudo firewall-cmd --zone=public --list-services<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see five <code>active<\/code> results, five <code>enabled<\/code> results, <code>Syntax OK<\/code>, PHP module names, a MariaDB version, an HTTP success status, and <code>ssh http https<\/code> in the firewalld service list.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\nactive\nactive\nactive\nactive\nenabled\nenabled\nenabled\nenabled\nenabled\nSyntax OK\nHTTP\/1.1 200 OK\nssh http https<\/code><\/pre>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Launch your LAMP server\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">Rocky Linux VPS<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Launch your LAMP server<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Get root access for Apache, PHP, and MariaDB on a Rocky Linux VPS.<\/p>\n\t<\/div>\n\t<a class=\"vl-cta-banner__button\" href=\"\/buy-vps\" aria-label=\"View Linux VPS plans\">View Linux VPS plans<\/a>\n<\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><code>No matching module streams for php:8.3<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The server may be on an older Rocky 9 minor release, or DNF\u2019s AppStream metadata may be stale. Bring the system current and refresh the repository metadata before considering any third-party source.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(PRETTY_NAME|VERSION_ID)=' \/etc\/os-release\nsudo dnf clean all\nsudo dnf makecache\nsudo dnf upgrade -y\nsudo dnf module list php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The list should include the <code>8.3<\/code> stream on a current Rocky Linux 9 system. Do not enable a PHP stream from a different Enterprise Linux major version.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>503 Service Unavailable<\/code> when opening a PHP page<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PHP-FPM may be stopped, or Apache may still have a stale configuration after the package installation. Check the service log and the FPM socket, then restart both services.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status php-fpm --no-pager\nsudo journalctl -u php-fpm -n 40 --no-pager\nsudo test -S \/run\/php-fpm\/www.sock &amp;&amp; echo \"FPM socket present\"\nsudo apachectl configtest\nsudo systemctl restart php-fpm httpd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the socket is absent, resolve the PHP-FPM error shown by <code>journalctl<\/code> before restarting again. A successful restart should make the temporary <code>health.php<\/code> test return <code>PHP OK<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>403 Forbidden<\/code> after changing files in <code>\/var\/www\/html<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apache can be denied by an incorrect SELinux label or by unreadable file permissions. Restore the standard web-content context and use conservative modes instead of disabling SELinux.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo restorecon -Rv \/var\/www\/html\nsudo find \/var\/www\/html -type d -exec chmod 0755 {} +\nsudo find \/var\/www\/html -type f -exec chmod 0644 {} +\nsudo systemctl reload httpd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For uploads, label only the directory that truly needs Apache write access using the appropriate SELinux policy. Do not make the whole document root world-writable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>Access denied for user 'lampuser'@'localhost'<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The application password may not match the value used when the account was created, or the application may be connecting with a different host name. Test the account directly over the local database socket.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mariadb -u lampuser -p lampdb -e \"SELECT 1;\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enter the real password. If it is wrong, reset it from the administrative socket and update the application\u2019s secret at the same time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mariadb -e \"ALTER USER 'lampuser'@'localhost' IDENTIFIED BY 'NEW_DB_PASSWORD';\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Hardening<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>Keep port 3306 closed. A local PHP application can use <code>localhost<\/code> or MariaDB\u2019s Unix socket without public database access.<\/li>\n\n\n<li>Point <code>YOUR_DOMAIN<\/code> to the VPS, configure an Apache virtual host, and issue a trusted TLS certificate before accepting logins or personal data.<\/li>\n\n\n<li>Keep SSH key authentication enabled, remove unused firewalld services, and review the final rules before opening any additional port.<\/li>\n\n\n<li>Remove test files, back up <code>\/var\/www\/html<\/code> and the MariaDB databases, and apply Rocky Linux security updates regularly.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Which PHP version does Rocky Linux 9 use here?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This guide selects the PHP 8.3 AppStream module available in current Rocky Linux 9 updates. Patch releases change through normal DNF updates, so the command checks the installed major and minor version rather than pinning one RPM build.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why use PHP-FPM instead of loading PHP directly into Apache?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PHP-FPM keeps the interpreter in its own managed service and is the current Enterprise Linux approach for Apache PHP requests. It also makes service status and troubleshooting clearer than mixing an older <code>mod_php<\/code> configuration with FPM.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I open MariaDB port 3306 for a website?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A website running on this VPS can connect through <code>localhost<\/code>, so public database access is unnecessary. If a separate server must connect, restrict the source address and configure encrypted database traffic before adding a firewall rule.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I finish the installation without a domain name?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Apache and the PHP health check work with <code>127.0.0.1<\/code> or the VPS IP. Add the domain later, create the virtual host, and obtain TLS after DNS points to the server.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Which PHP version does Rocky Linux 9 use here?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"This guide selects the PHP 8.3 AppStream module available in current Rocky Linux 9 updates. Patch releases change through normal DNF updates, so the command checks the installed major and minor version rather than pinning one RPM build.\"}}, {\"@type\": \"Question\", \"name\": \"Why use PHP-FPM instead of loading PHP directly into Apache?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"PHP-FPM keeps the interpreter in its own managed service and is the current Enterprise Linux approach for Apache PHP requests. It also makes service status and troubleshooting clearer than mixing an older `mod_php` configuration with FPM.\"}}, {\"@type\": \"Question\", \"name\": \"Should I open MariaDB port 3306 for a website?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. A website running on this VPS can connect through `localhost`, so public database access is unnecessary. If a separate server must connect, restrict the source address and configure encrypted database traffic before adding a firewall rule.\"}}, {\"@type\": \"Question\", \"name\": \"Can I finish the installation without a domain name?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Apache and the PHP health check work with `127.0.0.1` or the VPS IP. Add the domain later, create the virtual host, and obtain TLS after DNS points to the server.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install lamp stack on Rocky Linux 9 with Apache, PHP 8.3, MariaDB, firewalld, SELinux-safe defaults, and a working PHP test on a fresh VPS today.","protected":false},"author":1,"featured_media":1186,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[5,9],"tags":[71,117,73,72,100],"class_list":["post-1185","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-apache","tag-lamp-stack","tag-mariadb","tag-php","tag-rocky-linux-9","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/comments?post=1185"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1185\/revisions"}],"predecessor-version":[{"id":4237,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1185\/revisions\/4237"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1186"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}