{"id":1175,"date":"2026-11-26T03:00:00","date_gmt":"2026-11-26T03:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1175"},"modified":"2026-11-26T03:00:00","modified_gmt":"2026-11-26T03:00:00","slug":"install-lamp-stack-almalinux-9","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/26\/install-lamp-stack-almalinux-9\/","title":{"rendered":"How to Install LAMP Stack on AlmaLinux 9 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install LAMP stack on AlmaLinux 9 and you will have Apache serving pages, PHP 8.3 running through PHP-FPM, and MariaDB ready for an application in about ten minutes. This setup uses AlmaLinux repositories, firewalld, and SELinux-friendly permissions so the first deployment has a sensible security baseline.<\/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 AlmaLinux 9 VPS with at least 2 GB of RAM and 10 GB of available 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>A public IPv4 address for testing the web server. A domain is optional for the installation, but required for a trusted production TLS certificate.<\/li>\n\n\n<li>Internet access to the AlmaLinux BaseOS and AppStream repositories.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need a fresh AlmaLinux server with root access.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The commands use <code>sudo<\/code> for a non-root account. If your SSH session is already root, remove <code>sudo<\/code> from each command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Confirm AlmaLinux 9 and update the server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking the release before installing packages prevents an EL8 or EL10 command set from being applied to this server, while the update brings the base system current.<\/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 AlmaLinux 9 and the architecture should normally be <code>x86_64<\/code>. AlmaLinux publishes minor releases and package updates independently, so do not rely on a fixed patch number in later commands.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"AlmaLinux 9.x (...)\"\nVERSION_ID=\"9.x\"\nID_LIKE=\"rhel centos 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 reconnect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Apache and allow web traffic<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache handles HTTP requests, and firewalld exposes only the web services needed by visitors instead of opening arbitrary ports.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y httpd firewalld\nsudo systemctl enable --now firewalld httpd\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\nsudo firewall-cmd --zone=public --list-services<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The service check should return <code>active<\/code>, and the firewalld list should contain <code>http<\/code> and <code>https<\/code>. HTTPS is opened in advance so adding a certificate later does not require another firewall edit.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -I http:\/\/127.0.0.1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Apache should return an HTTP response, usually <code>200 OK<\/code> for the default page.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HTTP\/1.1 200 OK\nContent-Type: text\/html; charset=UTF-8<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To test from another computer, replace <code>SERVER_IP<\/code> with the VPS public address:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -I http:\/\/SERVER_IP<\/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\">AlmaLinux 9 provides PHP 8.3 as an AppStream module; using its <code>common<\/code> profile installs the web-oriented packages and avoids the removed <code>mod_php<\/code> approach used by older Enterprise Linux guides.<\/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\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 should begin with <code>PHP 8.3<\/code>, and both services should report <code>active<\/code>. PHP-FPM is the process manager Apache uses for PHP requests; its configuration and behavior are described in the <a href=\"https:\/\/www.php.net\/manual\/en\/install.fpm.php\" target=\"_blank\" rel=\"noopener\">official PHP-FPM documentation<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make a temporary endpoint that returns a fixed string. This proves PHP executes without publishing the detailed server information that <code>phpinfo()<\/code> would expose.<\/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<p class=\"wp-block-paragraph\">The response should be <code>PHP OK<\/code>. The final command removes the test file immediately; never leave diagnostic scripts 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 supplies the SQL layer, while a database account limited to <code>localhost<\/code> lets a local website connect without making port 3306 public.<\/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 tool is interactive. On a new installation, follow its prompts to remove anonymous accounts, reject remote root login, remove the test database, and reload the privilege tables. Keeping local administrative socket authentication is fine; an application should use its own database account instead. MariaDB documents the choices in its <a href=\"https:\/\/mariadb.com\/docs\/server\/clients-and-utilities\/deployment-tools\/mariadb-secure-installation\" target=\"_blank\" rel=\"noopener\">official <code>mariadb-secure-installation<\/code> reference<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a separate database and user for your application. Replace <code>YOUR_DB_PASSWORD<\/code> with a long, unique secret before running this block.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mariadb &lt;&lt;'SQL'\nCREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\nCREATE USER 'appuser'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';\nGRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';\nFLUSH PRIVILEGES;\nSQL\nsudo mariadb -e \"SHOW DATABASES LIKE 'appdb';\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final query should return one row named <code>appdb<\/code>. Store the real password in your application\u2019s secret configuration, not in <code>\/var\/www\/html<\/code>.<\/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 this final set of checks to confirm that all services are running at boot, Apache accepts its configuration, PHP has the MariaDB connector, and the web server responds locally.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl is-active httpd php-fpm mariadb\nsudo systemctl is-enabled httpd php-fpm 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\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expect three <code>active<\/code> results, three <code>enabled<\/code> results, <code>Syntax OK<\/code>, PHP module names, a MariaDB version, and a successful HTTP status.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\nactive\nactive\nenabled\nenabled\nenabled\nSyntax OK\nHTTP\/1.1 200 OK<\/code><\/pre>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Deploy your LAMP server\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">AlmaLinux VPS<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Deploy your LAMP server<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Get a root-access VPS for Apache, PHP, and MariaDB on AlmaLinux 9.<\/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 AppStream metadata may be stale, or the machine may be an older AlmaLinux 9 minor release that has not been updated. Confirm the release and refresh repository metadata before changing package sources.<\/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 list php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After the refresh, the list should show the <code>8.3<\/code> stream on a current AlmaLinux 9 system. Do not install an EL8 or EL10 repository on this server.<\/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\">Apache cannot reach PHP-FPM, commonly because the service failed to start or a configuration file has an error. Inspect the unit log and Apache syntax before restarting 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 apachectl configtest\nsudo systemctl restart php-fpm httpd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the log reports a PHP configuration error, correct that line and rerun <code>apachectl configtest<\/code>. A successful test prints <code>Syntax OK<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>AH00558: Could not reliably determine the server's fully qualified domain name<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This warning means Apache has no global <code>ServerName<\/code>; it does not usually stop the service, but it makes diagnostics noisy. Add a local configuration file using the server IP or fully qualified domain name, then validate and reload Apache.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>printf '%s\\n' 'ServerName SERVER_IP' | sudo tee \/etc\/httpd\/conf.d\/servername.conf &gt; \/dev\/null\nsudo apachectl configtest\nsudo systemctl reload httpd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>SERVER_IP<\/code> with the actual address or use <code>YOUR_DOMAIN<\/code> after DNS points to this VPS. <code>ServerName<\/code> is not a substitute for a TLS certificate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>Access denied for user 'appuser'@'localhost'<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The application password does not match the value used when the account was created, or the account exists for another host name. Test the same local account directly before changing its privileges.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mariadb -u appuser -p appdb -e \"SELECT 1;\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enter the real password, not the literal placeholder. If the test fails, reset the password from the administrative socket with <code>sudo mariadb<\/code>, then update the application\u2019s configuration as well.<\/p>\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 site on this VPS can reach MariaDB through <code>localhost<\/code> or the Unix socket.<\/li>\n\n\n<li>Point <code>YOUR_DOMAIN<\/code> to the VPS, install a trusted TLS certificate, and redirect HTTP to HTTPS before collecting credentials or personal data.<\/li>\n\n\n<li>Restore SELinux labels after copying site files with <code>sudo restorecon -Rv \/var\/www\/html<\/code>; do not disable SELinux to hide a labeling problem.<\/li>\n\n\n<li>Remove health checks and unused sample files, update AlmaLinux regularly, and back up both the web root and MariaDB data.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Does AlmaLinux 9 include PHP 8.3?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Current AlmaLinux 9 AppStream repositories provide PHP 8.3 as a module stream. Enabling the stream explicitly makes the intended PHP branch clear and avoids silently selecting the older base package.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does this guide use PHP-FPM instead of <code>mod_php<\/code>?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Enterprise Linux 9 removed the Apache <code>mod_php<\/code> module. PHP-FPM runs PHP as a FastCGI service, which Apache can pass PHP requests to without loading the interpreter directly into its worker process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I expose MariaDB to the Internet?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Not for a website hosted on the same VPS. The local application account works without a public database port; only configure remote 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 later?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. You can install and test the stack with the server IP first. When the domain\u2019s DNS record points to the VPS, create a virtual host, issue a TLS certificate, and update the Apache <code>ServerName<\/code> to the domain.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Does AlmaLinux 9 include PHP 8.3?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Current AlmaLinux 9 AppStream repositories provide PHP 8.3 as a module stream. Enabling the stream explicitly makes the intended PHP branch clear and avoids silently selecting the older base package.\"}}, {\"@type\": \"Question\", \"name\": \"Why does this guide use PHP-FPM instead of `mod_php`?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Enterprise Linux 9 removed the Apache `mod_php` module. PHP-FPM runs PHP as a FastCGI service, which Apache can pass PHP requests to without loading the interpreter directly into its worker process.\"}}, {\"@type\": \"Question\", \"name\": \"Should I expose MariaDB to the Internet?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Not for a website hosted on the same VPS. The local application account works without a public database port; only configure remote 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 later?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. You can install and test the stack with the server IP first. When the domain\u2019s DNS record points to the VPS, create a virtual host, issue a TLS certificate, and update the Apache `ServerName` to the domain.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install LAMP stack on AlmaLinux 9 with Apache, PHP 8.3, PHP-FPM, MariaDB, and firewalld, then test the complete web stack safely on a new VPS in minutes.","protected":false},"author":1,"featured_media":1176,"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":[95,71,117,73,72],"class_list":["post-1175","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-almalinux-9","tag-apache","tag-lamp-stack","tag-mariadb","tag-php","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1175","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=1175"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1175\/revisions"}],"predecessor-version":[{"id":4217,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1175\/revisions\/4217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1176"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}