{"id":1173,"date":"2026-11-25T18:00:00","date_gmt":"2026-11-25T18:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1173"},"modified":"2026-11-25T18:00:00","modified_gmt":"2026-11-25T18:00:00","slug":"install-lamp-stack-almalinux-8","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/25\/install-lamp-stack-almalinux-8\/","title":{"rendered":"How to Install LAMP Stack on AlmaLinux 8 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install LAMP stack on AlmaLinux 8 with Apache, PHP 8.2, PHP-FPM, and MariaDB in about ten minutes. You will finish with a firewalld-protected web server, a local application database, and a safe PHP health check.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">AlmaLinux 8.10 provides the PHP 8.2 and MariaDB 10.11 application streams used here. The commands use DNF, systemd, firewalld, and SELinux-compatible defaults so you can move from a fresh VPS to a working application base without third-party repositories.<\/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 8 VPS, preferably updated to 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 with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A public IPv4 address for testing HTTP access. A domain is optional for this installation, but required for a production TLS certificate.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> with root access if you need a server for this stack.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The examples assume a non-root SSH account. If you are 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 the release and apply updates<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking the release first keeps EL8 instructions away from an EL9 or EL10 machine, while updating packages 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\">You should see AlmaLinux 8 and normally the <code>x86_64<\/code> architecture. The minor release and package versions may change as AlmaLinux publishes updates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"AlmaLinux 8.10 (Cerulean Leopard)\"\nVERSION_ID=\"8.10\"\nx86_64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the upgrade installs a new kernel, keep this SSH session open until you know the VPS can reboot and reconnect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Apache and open web ports<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache serves your site files, while firewalld limits public traffic to the HTTP and HTTPS services the web server needs.<\/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 print <code>active<\/code>; the firewalld output should include <code>http<\/code> and <code>https<\/code>. HTTPS is opened now so adding a certificate later does not require another firewall change.<\/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\">An Apache response normally starts with <code>HTTP\/1.1 200 OK<\/code> or another successful HTTP status.<\/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<h2 class=\"wp-block-heading\">Step 3: Install PHP 8.2 and PHP-FPM<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP-FPM runs PHP through FastCGI, keeping application execution separate from Apache\u2019s web-serving process. AlmaLinux 8.10\u2019s AppStream includes the PHP 8.2 stream, so no external repository is needed for this base setup.<\/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 module install php:8.2 -y\nsudo dnf install -y php-mysqlnd php-gd php-mbstring php-opcache php-xml php-curl php-intl php-pecl-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 should begin with <code>PHP 8.2<\/code>, and both services should report <code>active<\/code>. The PHP module command installs the common profile, which includes PHP-FPM and its Apache integration. The <a href=\"https:\/\/www.php.net\/manual\/en\/install.fpm.php\" target=\"_blank\" rel=\"noopener\">PHP-FPM documentation<\/a> explains the process manager used by this layout.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP 8.2.x (cli) (built: ...)\nactive\nactive<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Test execution with a temporary endpoint rather than exposing <code>phpinfo()<\/code>, which can reveal configuration details. The last command removes the file immediately after the request.<\/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 curl request should print <code>PHP OK<\/code>. If it prints PHP source code, PHP-FPM is not connected to Apache; use the troubleshooting checks below before deploying an application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Install and secure MariaDB<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB stores application data, and the local database account created below avoids 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 script is interactive. Remove anonymous accounts, disallow remote root login, remove the test database, and reload the privilege tables. On current MariaDB releases, keeping Unix-socket authentication for the administrative account is a reasonable default; you do not need to force a root password just to complete this guide. See the <a href=\"https:\/\/mariadb.com\/docs\/server\/clients-and-utilities\/deployment-tools\/mariadb-secure-installation\" target=\"_blank\" rel=\"noopener\">official MariaDB security script reference<\/a> for prompt details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a database and a separate user for your application. Replace <code>YOUR_DB_PASSWORD<\/code> with a long, unique password before running the 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>. Keep the real password in your application\u2019s secret store, not in a web-accessible 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, and MariaDB start at boot, Apache accepts its configuration, PHP has the database connector, and the server answers a local request.<\/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\">Expected output includes four <code>active<\/code> lines, three <code>enabled<\/code> lines, <code>Syntax OK<\/code>, the PHP modules, a MariaDB version, and an HTTP success response.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\nactive\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=\"Launch 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\">Launch your LAMP server<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Get root access for an Apache, PHP, and MariaDB stack on AlmaLinux.<\/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-fpm<\/code> or <code>php-pecl-zip<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The PHP stream may not be enabled, metadata may be stale, or the system may not be running the expected AlmaLinux release. Confirm the OS and refresh the native repositories 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 module list php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The list should contain the <code>8.2<\/code> stream on a current AlmaLinux 8.10 system. Do not mix EL9 or EL10 repositories into an EL8 installation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PHP source appears in the browser<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apache is serving the <code>.php<\/code> file as plain text because PHP-FPM or the Apache PHP handler is unavailable. Check the services and Apache configuration, then restart the two 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\">After the restart, recreate the temporary health endpoint and test it with curl. Remove it again when the response is correct.<\/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\">Incorrect permissions or SELinux labels can prevent Apache from reading a file. Restore the standard label and use readable, non-world-writable modes; do not turn off 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<h3 class=\"wp-block-heading\"><code>Access denied for user 'appuser'@'localhost'<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The password entered by the application does not match the account, or the account was created for a different host. Test the credentials through the local connection before changing grants.<\/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 value used instead of <code>YOUR_DB_PASSWORD<\/code>. A result containing <code>1<\/code> confirms that the account can access <code>appdb<\/code> without making MariaDB public.<\/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. Local applications can use <code>localhost<\/code> or the Unix socket.<\/li>\n\n\n<li>Point your domain to the VPS, issue a trusted TLS certificate, and redirect HTTP to HTTPS before accepting logins or personal data.<\/li>\n\n\n<li>Remove temporary health-check files and never store database passwords under <code>\/var\/www\/html<\/code>.<\/li>\n\n\n<li>Schedule AlmaLinux updates and back up both the web root and MariaDB databases before major PHP or application changes.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What does LAMP mean on AlmaLinux 8?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">LAMP stands for Linux, Apache, MariaDB, and PHP. In this setup, <code>httpd<\/code> serves requests, PHP-FPM executes PHP through FastCGI, and MariaDB handles relational data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is PHP 8.2 available from the AlmaLinux 8 repositories?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. AlmaLinux 8.10 updated its AppStream module streams to include PHP 8.2. Enable that stream explicitly so a machine with an older default does not silently install an outdated PHP branch.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need to open port 3306 for WordPress or another website?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. An application on the same VPS can connect to MariaDB over <code>localhost<\/code> without public database access. Only open 3306 for a separate host when you have a specific need and a tightly restricted source address.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I use MySQL instead of MariaDB?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can, but the package names, service behavior, authentication defaults, and security commands change. Choose one database server and follow its own AlmaLinux 8 installation guidance rather than installing both implementations together.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"What does LAMP mean on AlmaLinux 8?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"LAMP stands for Linux, Apache, MariaDB, and PHP. In this setup, `httpd` serves requests, PHP-FPM executes PHP through FastCGI, and MariaDB handles relational data.\"}}, {\"@type\": \"Question\", \"name\": \"Is PHP 8.2 available from the AlmaLinux 8 repositories?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. AlmaLinux 8.10 updated its AppStream module streams to include PHP 8.2. Enable that stream explicitly so a machine with an older default does not silently install an outdated PHP branch.\"}}, {\"@type\": \"Question\", \"name\": \"Do I need to open port 3306 for WordPress or another website?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. An application on the same VPS can connect to MariaDB over `localhost` without public database access. Only open 3306 for a separate host when you have a specific need and a tightly restricted source address.\"}}, {\"@type\": \"Question\", \"name\": \"Can I use MySQL instead of MariaDB?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"You can, but the package names, service behavior, authentication defaults, and security commands change. Choose one database server and follow its own AlmaLinux 8 installation guidance rather than installing both implementations together.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install LAMP stack on AlmaLinux 8 with Apache, PHP 8.2, MariaDB, PHP-FPM, and firewalld, then verify a working web server on a fresh VPS in minutes.","protected":false},"author":1,"featured_media":1174,"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":[94,71,117,73,72],"class_list":["post-1173","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-almalinux-8","tag-apache","tag-lamp-stack","tag-mariadb","tag-php","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1173","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=1173"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1173\/revisions"}],"predecessor-version":[{"id":4187,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1173\/revisions\/4187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1174"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}