{"id":1183,"date":"2026-11-27T03:00:00","date_gmt":"2026-11-27T03:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1183"},"modified":"2026-11-27T03:00:00","modified_gmt":"2026-11-27T03:00:00","slug":"install-lamp-stack-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/27\/install-lamp-stack-rocky-linux-8\/","title":{"rendered":"How to Install LAMP Stack on Rocky Linux 8 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install LAMP stack on Rocky Linux 8 and you will have Apache serving web pages, PHP 8.2 handling dynamic requests, and MariaDB 10.11 ready for an application database. Set aside about ten minutes for a fresh VPS; this guide also opens only the required web ports and checks the stack without leaving a diagnostic page online.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 8 uses DNF modules for versioned application streams. The commands below select the current PHP and MariaDB streams available in Rocky 8.10 instead of accepting the old PHP 7.2 default.<\/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 8 VPS, preferably updated to Rocky Linux 8.10, 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 commands with <code>sudo<\/code>.<\/li>\n\n\n<li>Outbound Internet access to the Rocky Linux BaseOS and AppStream repositories, plus a public IPv4 address for browser testing.<\/li>\n\n\n<li>A domain is optional while installing the stack. You need one before requesting a trusted TLS certificate for a production site.<\/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 examples assume a non-root SSH session. If you are logged in as <code>root<\/code>, remove <code>sudo<\/code> from the commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Confirm Rocky Linux 8 and apply updates<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking the release first prevents an EL9 or EL10 package instruction from being applied to this server, while the upgrade 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 first lines should identify Rocky Linux 8 and the architecture should normally be <code>x86_64<\/code>. Minor release and package versions change as updates are published, so do not copy a version number from an old package listing.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Rocky Linux 8.10 (Green Obsidian)\"\nVERSION_ID=\"8.10\"\nID_LIKE=\"rhel fedora\"\nx86_64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If DNF installs a new kernel, keep this 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 protect the web ports<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache serves the document root, while firewalld limits incoming traffic to SSH, HTTP, and HTTPS instead of exposing every listening service.<\/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 SSH before reloading the permanent rules so a remote session remains reachable. If SSH uses a custom port, add that port with <code>--add-port=YOUR_SSH_PORT\/tcp<\/code> and keep the current session open while testing a second connection.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\nactive\nssh http https<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Test Apache locally before blaming DNS or a provider-level firewall. A successful loopback response proves that the daemon is listening on the VPS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo 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<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Enable PHP 8.2 and connect it to Apache<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 8.10 publishes PHP 8.2 in AppStream, but the default module stream is older. Selecting the stream explicitly gives Apache a current PHP branch without adding an untrusted repository; Rocky\u2019s <a href=\"https:\/\/docs.rockylinux.org\/guides\/web\/php\/\" target=\"_blank\" rel=\"noopener\">PHP documentation<\/a> covers the available streams and Apache integration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf module reset php -y\nsudo dnf module enable php:8.2 -y\nsudo dnf install -y php php-cli php-mysqlnd php-gd php-curl php-zip php-mbstring php-xml php-opcache\nphp -v\nsudo systemctl restart httpd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first version line should begin with <code>PHP 8.2<\/code>. The <code>php-mysqlnd<\/code> package lets PHP applications use MariaDB\u2019s MySQL-compatible protocol, while the other extensions cover common image, HTTP, archive, multibyte, XML, and opcode-cache needs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a temporary endpoint that returns a fixed string. This tests PHP execution through Apache without publishing the full configuration details exposed by <code>phpinfo()<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>printf '%s\\n' '&lt;?php echo \"PHP OK\\\\n\"; ?&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<pre class=\"wp-block-code\"><code>PHP OK<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final command removes the test file immediately. Keep real application code and secrets outside any public test endpoint.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Install MariaDB 10.11 and create an application database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB stores persistent application data, and a database account limited to <code>localhost<\/code> avoids exposing port 3306 to the Internet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 8.10 provides MariaDB 10.11 as an AppStream module. Reset the old selection before enabling the newer stream so DNF does not combine incompatible module metadata.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf module reset mariadb -y\nsudo dnf module enable mariadb:10.11 -y\nsudo dnf install -y mariadb-server mariadb\nsudo systemctl enable --now mariadb\nsudo systemctl is-active mariadb<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Secure the initial database installation with MariaDB\u2019s supported hardening utility. The <a href=\"https:\/\/mariadb.com\/docs\/server\/clients-and-utilities\/deployment-tools\/mariadb-secure-installation\" target=\"_blank\" rel=\"noopener\">MariaDB secure-installation documentation<\/a> explains each prompt.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mariadb-secure-installation<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When prompted, keep local administrative access through the Unix socket when offered, remove anonymous accounts, disallow remote root login, remove the test database, and reload the privilege tables. A local socket keeps administrative credentials out of a network listener.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a database and a separate login for the website. Replace <code>YOUR_DB_PASSWORD<\/code> with a long, unique password before running the block; the placeholder must not be used on a public server.<\/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 last command should return one row named <code>lampdb<\/code>. Give the application only this account\u2019s database privileges; do not put the administrative MariaDB account in application configuration.<\/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 the checks below after the temporary PHP file has been removed. Together they confirm that the services start at boot, Apache\u2019s configuration parses, PHP has its database connector, MariaDB answers locally, and the firewall exposes the intended services.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl is-active firewalld httpd mariadb\nsudo systemctl is-enabled firewalld httpd mariadb\nsudo apachectl configtest\nsudo httpd -M | grep php_module\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\">Expect <code>active<\/code> and <code>enabled<\/code> for all three services, <code>Syntax OK<\/code>, a shared PHP module, PHP connector names, a MariaDB version, an HTTP success response, and <code>ssh http https<\/code>. From another computer, open <code>http:\/\/SERVER_IP\/<\/code> after replacing <code>SERVER_IP<\/code> with the VPS public address.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\nactive\nactive\nenabled\nenabled\nenabled\nSyntax OK\n php_module (shared)\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 8 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 match for argument: php<\/code> or PHP 7.2 installs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The AppStream metadata may be stale, or the PHP module stream was not selected. Confirm the OS and refresh the repositories before attempting another install.<\/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 module reset php -y\nsudo dnf module enable php:8.2 -y\nsudo dnf install -y php php-cli php-mysqlnd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Do not enable an EL9 or EL10 module on Rocky Linux 8. Mixed major-release packages can leave Apache and PHP unable to load together.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PHP code appears as text in the browser<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apache is not loading the PHP module, or it was not restarted after PHP was installed. Check the module list and Apache syntax, then restart the service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo httpd -M | grep php_module\nsudo dnf reinstall -y php\nsudo apachectl configtest\nsudo systemctl restart httpd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the module check remains empty, inspect <code>sudo journalctl -u httpd -n 40 --no-pager<\/code> for a package or configuration error before recreating the temporary health endpoint.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>403 Forbidden<\/code> after uploading site files<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SELinux may have an incorrect context, or the files may not be readable by Apache. Restore the default labels and use ordinary web-readable modes; disabling SELinux is not a fix.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo restorecon -RFv \/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\">If the application needs uploads, label only its upload directory with the SELinux type it requires instead of making the entire document root 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 password in the application does not match the database account, or the application is connecting with a different host name. Test the credentials directly over the local connection.<\/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, not <code>YOUR_DB_PASSWORD<\/code>. If it is wrong, reset it from the administrative socket and update the application 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 in firewalld. 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, issue a trusted TLS certificate, and redirect HTTP to HTTPS before accepting logins or personal data.<\/li>\n\n\n<li>Keep SELinux enforcing, remove temporary health files, and never store database passwords under <code>\/var\/www\/html<\/code>.<\/li>\n\n\n<li>Back up <code>\/var\/www\/html<\/code> and the MariaDB databases, then apply Rocky Linux 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\">Why does Rocky Linux 8 need a PHP module command?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 8 uses AppStream module streams for software versions that can differ from the base operating system. The default PHP stream is older, so this guide selects PHP 8.2 before installing the packages. Rocky Linux 9 and 10 use different packaging behavior, so do not reuse their commands here.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I open port 3306 for a PHP website?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A website running on the same VPS connects to MariaDB through <code>localhost<\/code> or a Unix socket. Only consider remote database access when a separate host genuinely needs it, and then restrict the source address and require encrypted connections.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I use a domain name later?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Apache works with the public IP while you build the server. After DNS points <code>YOUR_DOMAIN<\/code> to the VPS, create a name-based virtual host and request a TLS certificate before exposing a login or other sensitive form.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is PHP-FPM required for this Rocky Linux 8 setup?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Rocky\u2019s PHP package can serve requests through Apache\u2019s PHP module, which is sufficient for a basic single-site LAMP installation. Choose PHP-FPM later when you need separate pools, per-site process limits, or a larger multi-site configuration.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Why does Rocky Linux 8 need a PHP module command?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Rocky Linux 8 uses AppStream module streams for software versions that can differ from the base operating system. The default PHP stream is older, so this guide selects PHP 8.2 before installing the packages. Rocky Linux 9 and 10 use different packaging behavior, so do not reuse their commands here.\"}}, {\"@type\": \"Question\", \"name\": \"Should I open port 3306 for a PHP website?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. A website running on the same VPS connects to MariaDB through `localhost` or a Unix socket. Only consider remote database access when a separate host genuinely needs it, and then restrict the source address and require encrypted connections.\"}}, {\"@type\": \"Question\", \"name\": \"Can I use a domain name later?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Apache works with the public IP while you build the server. After DNS points `YOUR_DOMAIN` to the VPS, create a name-based virtual host and request a TLS certificate before exposing a login or other sensitive form.\"}}, {\"@type\": \"Question\", \"name\": \"Is PHP-FPM required for this Rocky Linux 8 setup?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Rocky\u2019s PHP package can serve requests through Apache\u2019s PHP module, which is sufficient for a basic single-site LAMP installation. Choose PHP-FPM later when you need separate pools, per-site process limits, or a larger multi-site configuration.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install LAMP stack on Rocky Linux 8 with Apache, PHP 8.2, MariaDB 10.11, firewalld, and a safe PHP test for a working VPS in about ten minutes.","protected":false},"author":1,"featured_media":1184,"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,105],"class_list":["post-1183","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-8","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1183","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=1183"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1183\/revisions"}],"predecessor-version":[{"id":4232,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1183\/revisions\/4232"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1184"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}