{"id":1179,"date":"2026-11-26T13:00:00","date_gmt":"2026-11-26T13:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1179"},"modified":"2026-11-26T13:00:00","modified_gmt":"2026-11-26T13:00:00","slug":"install-lamp-stack-debian-13","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/26\/install-lamp-stack-debian-13\/","title":{"rendered":"How to Install LAMP Stack on Debian 13 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install LAMP stack on Debian 13 and you will have Apache serving web pages, PHP 8.4 processing dynamic requests through PHP-FPM, and MariaDB ready for your application. On a fresh VPS, the setup takes roughly ten minutes and includes a firewall, a local database account, and a safe health check.<\/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 Debian 13 (Trixie) VPS with at least 1 GB of RAM and 10 GB of free disk space.<\/li>\n\n\n<li>SSH access as <code>root<\/code>, or a normal account with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>Outbound Internet access to Debian\u2019s configured package repositories.<\/li>\n\n\n<li>A public IP address for testing Apache. A domain is optional at first, but you need one 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 commands use <code>sudo<\/code> for a non-root 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 Debian 13 and apply updates<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking the release before installing packages prevents a PHP or service mismatch caused by following instructions for Debian 11 or Debian 12.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(PRETTY_NAME|VERSION_ID|VERSION_CODENAME)=' \/etc\/os-release\nuname -m\nsudo apt update\nsudo apt full-upgrade -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release should show Debian 13 and <code>trixie<\/code>; a typical 64-bit VPS reports <code>x86_64<\/code>. Package versions can change as Debian publishes updates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Debian GNU\/Linux 13 (trixie)\"\nVERSION_ID=\"13\"\nVERSION_CODENAME=trixie\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 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 handles HTTP requests, while UFW limits public access to SSH and the web services the server actually needs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y apache2 apache2-utils curl ufw\nsudo systemctl enable --now apache2\nsudo ufw allow OpenSSH\nsudo ufw allow 80\/tcp\nsudo ufw allow 443\/tcp\nsudo ufw --force enable\nsudo ufw status verbose\nsudo systemctl is-active apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the SSH rule before enabling UFW. If SSH uses a custom port, allow that port instead of relying on the <code>OpenSSH<\/code> profile. The service check should print <code>active<\/code>, and UFW should list SSH, HTTP, and HTTPS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test Apache locally before testing the public IP. This separates a web-server problem from a provider-level firewall or networking problem.<\/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\nContent-Type: text\/html<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install PHP 8.4 and connect PHP-FPM to Apache<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Debian 13\u2019s native PHP packages select PHP 8.4, and PHP-FPM runs scripts through FastCGI without loading the interpreter directly into Apache workers. The <a href=\"https:\/\/www.php.net\/manual\/en\/install.fpm.php\" target=\"_blank\" rel=\"noopener\">PHP-FPM manual<\/a> explains the process manager used here.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y php php-cli php-fpm php-mysql php-gd php-mbstring php-curl php-xml php-zip php-opcache php-bcmath\nphp -v<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The version line should start with <code>PHP 8.4<\/code>. Debian\u2019s <code>php<\/code> metapackage keeps the command aligned with the release\u2019s supported PHP branch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enable Apache\u2019s FastCGI modules and the FPM configuration that matches the installed PHP minor version. The variable avoids hard-coding a service name if Debian changes the default patch release.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP_VERSION=\"$(php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;')\"\nsudo a2enmod proxy_fcgi setenvif\nsudo a2enconf \"php${PHP_VERSION}-fpm\"\nsudo systemctl enable --now \"php${PHP_VERSION}-fpm\"\nsudo systemctl reload apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a short-lived endpoint that returns a fixed value. It confirms that Apache reaches PHP without publishing the detailed configuration 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<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 stores application data, and a database user restricted to <code>localhost<\/code> lets a site connect without exposing port 3306 to the Internet.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y mariadb-server mariadb-client\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 program is interactive. Remove anonymous accounts, reject remote root login, remove the test database, and reload the privilege tables when prompted. On a new Debian installation, keeping local administrative access through the Unix socket is appropriate; your application should use its own account. See MariaDB\u2019s <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> for the prompt meanings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a database and login for the 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 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 command should return one row named <code>lampdb<\/code>. Store the real password in your application\u2019s secret configuration, not inside the public document root.<\/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, the matching PHP-FPM unit, and MariaDB are running and enabled at boot. The module query also verifies that PHP can talk to MariaDB.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP_VERSION=\"$(php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;')\"\nsudo systemctl is-active apache2 \"php${PHP_VERSION}-fpm\" mariadb\nsudo systemctl is-enabled apache2 \"php${PHP_VERSION}-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\/\nsudo ufw status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expect three <code>active<\/code> lines, three <code>enabled<\/code> lines, <code>Syntax OK<\/code>, PHP module names, a MariaDB version, an HTTP success response, and an active UFW policy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\nactive\nactive\nenabled\nenabled\nenabled\nSyntax OK\nHTTP\/1.1 200 OK\nStatus: active<\/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\">Debian 13 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 a root-access VPS for Apache, PHP, and MariaDB on Debian 13.<\/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>Unit php8.4-fpm.service not found<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The FPM package is missing, or the server is not using Debian 13 repositories. Confirm the release and package candidate before enabling Apache\u2019s FPM configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(PRETTY_NAME|VERSION_ID|VERSION_CODENAME)=' \/etc\/os-release\nsudo apt update\nsudo apt install -y php8.4-fpm\nsudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.4-fpm\nsudo systemctl enable --now php8.4-fpm\nsudo systemctl reload apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Do not install PHP packages from Debian 11 or Debian 12 repositories on Trixie. Mixed release packages can leave Apache and PHP-FPM unable to start together.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PHP source appears in the browser or Apache returns <code>503 Service Unavailable<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apache is not passing <code>.php<\/code> requests to FPM, or the FPM service failed to start. Inspect the unit log and Apache configuration before restarting.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP_VERSION=\"$(php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;')\"\nsudo systemctl status \"php${PHP_VERSION}-fpm\" --no-pager\nsudo journalctl -u \"php${PHP_VERSION}-fpm\" -n 40 --no-pager\nsudo apachectl configtest\nsudo systemctl restart \"php${PHP_VERSION}-fpm\" apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the test still fails, confirm that <code>\/etc\/apache2\/conf-enabled\/php8.4-fpm.conf<\/code> exists and that <code>proxy_fcgi<\/code> is enabled. Recreate the temporary <code>health.php<\/code> endpoint only long enough to test it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">SSH stops working after enabling UFW<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">UFW may have been enabled before the correct SSH rule was added, or SSH may be listening on a nonstandard port. Use the VPS control panel\u2019s <strong>VPS control panel (Virtualizor) \u2192 VNC console<\/strong> from the VPSLake client area, then allow the actual port.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ss -ltnp | grep ssh\nsudo ufw allow YOUR_SSH_PORT\/tcp\nsudo ufw status numbered<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>YOUR_SSH_PORT<\/code> with the numeric listening port. Keep the current SSH session open and test a second connection before removing any old rule.<\/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 differs from the value used during account creation, or the application is using a different database host. Test the credentials against the local socket before changing privileges.<\/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 the placeholder. If it is wrong, reset it from the administrative socket and update the application configuration too.<\/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 website can use <code>localhost<\/code> or the Unix socket; remote database access should be restricted to a known source address and encrypted.<\/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>Keep SSH key authentication enabled, remove unused UFW rules, and review the final policy with the <a href=\"https:\/\/vpslake.com\/ufw-firewall-generator\">VPSLake UFW firewall generator<\/a>.<\/li>\n\n\n<li>Remove temporary test files, back up <code>\/var\/www\/html<\/code> and the MariaDB databases, and apply Debian 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 Debian 13 use for LAMP?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Debian 13\u2019s native <code>php<\/code> and <code>php-fpm<\/code> metapackages select PHP 8.4. The commands detect the installed minor version when enabling the Apache configuration and systemd unit, so patch updates do not require rewriting the guide.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need <code>libapache2-mod-php<\/code> with PHP-FPM?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. This setup uses Apache\u2019s <code>proxy_fcgi<\/code> module and PHP-FPM, so <code>libapache2-mod-php<\/code> is unnecessary. Keeping one PHP request path avoids conflicts between Apache\u2019s prefork module and the FPM handler.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I open MariaDB port 3306 for a PHP website?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A PHP application on the same VPS connects through <code>localhost<\/code>, so MariaDB does not need a public firewall rule. Only consider remote access for a separate host, and then restrict the source and configure encryption.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I install the stack before I have 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 an Apache virtual host, and issue a TLS certificate 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 Debian 13 use for LAMP?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Debian 13\u2019s native `php` and `php-fpm` metapackages select PHP 8.4. The commands detect the installed minor version when enabling the Apache configuration and systemd unit, so patch updates do not require rewriting the guide.\"}}, {\"@type\": \"Question\", \"name\": \"Do I need `libapache2-mod-php` with PHP-FPM?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. This setup uses Apache\u2019s `proxy_fcgi` module and PHP-FPM, so `libapache2-mod-php` is unnecessary. Keeping one PHP request path avoids conflicts between Apache\u2019s prefork module and the FPM handler.\"}}, {\"@type\": \"Question\", \"name\": \"Should I open MariaDB port 3306 for a PHP website?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. A PHP application on the same VPS connects through `localhost`, so MariaDB does not need a public firewall rule. Only consider remote access for a separate host, and then restrict the source and configure encryption.\"}}, {\"@type\": \"Question\", \"name\": \"Can I install the stack before I have 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 an Apache virtual host, and issue a TLS certificate after DNS points to the server.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install LAMP stack on Debian 13 with Apache, PHP 8.4-FPM, MariaDB, UFW, and a safe health check, then verify your VPS in about ten minutes from SSH.","protected":false},"author":1,"featured_media":1180,"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,98,117,73,72],"class_list":["post-1179","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-apache","tag-debian-13","tag-lamp-stack","tag-mariadb","tag-php","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1179","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=1179"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1179\/revisions"}],"predecessor-version":[{"id":4223,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1179\/revisions\/4223"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1180"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}