{"id":1189,"date":"2026-11-27T18:00:00","date_gmt":"2026-11-27T18:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1189"},"modified":"2026-11-27T18:00:00","modified_gmt":"2026-11-27T18:00:00","slug":"install-lamp-stack-debian-12","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/27\/install-lamp-stack-debian-12\/","title":{"rendered":"How to Install LAMP Stack on Debian 12 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install LAMP stack on Debian 12 and you will have Apache serving web requests, PHP 8.2 processing dynamic pages through PHP-FPM, and MariaDB ready for application data. A fresh VPS takes about ten minutes to configure, including a firewall and a temporary health check.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide uses Debian 12 Bookworm&#8217;s native packages and keeps the database on the local server. You can add a domain and HTTPS after the basic stack is responding.<\/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 12 (Bookworm) 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 the Debian package repositories and a public IP address for testing Apache.<\/li>\n\n\n<li>A domain is optional during installation, 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 connected 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 12 and update the server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Confirming the release first prevents package and service mismatches, while a full upgrade applies current Bookworm security updates before you expose a web server.<\/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 report Debian 12 and <code>bookworm<\/code>; <code>x86_64<\/code> is the usual architecture for a 64-bit VPS. Package patch versions can differ as Debian publishes updates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Debian GNU\/Linux 12 (bookworm)\"\nVERSION_ID=\"12\"\nVERSION_CODENAME=bookworm\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 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 allow web traffic<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache handles HTTP requests, and UFW limits the public surface to SSH plus the HTTP and HTTPS ports needed by a website.<\/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 apachectl configtest\nsudo systemctl is-active apache2\nsudo ufw status verbose<\/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> application profile. The checks should show <code>Syntax OK<\/code>, an <code>active<\/code> Apache service, and an active firewall with SSH, HTTP, and HTTPS rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test the web server locally. This distinguishes an Apache problem from a provider-level firewall or routing problem when you later test the public IP.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -fsSI http:\/\/127.0.0.1\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>HTTP\/1.1 200 OK\nContent-Type: text\/html<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install PHP 8.2-FPM and connect it to Apache<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Debian 12 provides PHP 8.2, and PHP-FPM runs PHP through FastCGI so Apache does not need the older embedded PHP module. The <a href=\"https:\/\/www.php.net\/manual\/en\/install.fpm.php\" target=\"_blank\" rel=\"noopener\">PHP-FPM manual<\/a> documents the process manager used by this setup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install PHP and the extensions commonly required by database-backed applications.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y php8.2-cli php8.2-fpm php8.2-mysql php8.2-gd php8.2-mbstring php8.2-curl php8.2-xml php8.2-zip php8.2-opcache php8.2-bcmath\nphp -v<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The version line should begin with <code>PHP 8.2<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP 8.2.x (cli) (built: ...)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable Apache&#8217;s FastCGI support, activate the PHP-FPM configuration, and start the matching service at boot.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.2-fpm\nsudo systemctl enable --now php8.2-fpm\nsudo systemctl reload apache2\nsudo systemctl is-active php8.2-fpm<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final line should print <code>active<\/code>. Create a short-lived endpoint that returns a fixed string rather than exposing the detailed server information produced 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 secure the database server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB stores application data, while a separate 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 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 script is interactive. If this is a new installation, press Enter when it asks for an empty current root password if appropriate, remove anonymous users, reject remote root login, remove the test database, and reload the privilege tables. MariaDB explains these prompts 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>; local Unix-socket authentication for the administrative account is normal on modern MariaDB.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create an application database and a least-privilege login. Replace <code>YOUR_DB_PASSWORD<\/code> with a long, unique password before running this block, and keep the real secret out of the public document root.<\/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 a row named <code>lampdb<\/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 these checks after the installation to confirm that Apache, PHP-FPM, and MariaDB are running, enabled at boot, and connected through the expected PHP modules.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl is-active apache2 php8.2-fpm mariadb\nsudo systemctl is-enabled apache2 php8.2-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 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 12.<\/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>Unable to locate package php8.2-fpm<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The APT index is stale, or the server is not actually using Debian 12 repositories. Check the release and repository codename before trying to install packages from another Debian version.<\/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\napt-cache policy php8.2-fpm\nsudo apt install -y php8.2-fpm<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Do not mix Debian 11, Debian 12, and Debian 13 repositories. Mixed PHP libraries can leave both Apache and FPM unable to start.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>Unit php8.2-fpm.service not found<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PHP-FPM was not installed, or the package installation stopped with an error. Install the versioned FPM package, enable its Apache configuration, and start the service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y php8.2-fpm\nsudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.2-fpm\nsudo systemctl enable --now php8.2-fpm\nsudo systemctl reload apache2<\/code><\/pre>\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 forwarding PHP files to FPM, or the FPM unit failed to start. Inspect the service log and Apache configuration before restarting both services.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status php8.2-fpm --no-pager\nsudo journalctl -u php8.2-fpm -n 40 --no-pager\nsudo apachectl configtest\nsudo systemctl restart php8.2-fpm apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm that <code>\/etc\/apache2\/conf-enabled\/php8.2-fpm.conf<\/code> exists and that <code>proxy_fcgi<\/code> is enabled. Recreate the temporary <code>health.php<\/code> test only long enough to check the result, then remove 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\">The firewall may have been enabled before the right SSH rule was added, or SSH may listen on a nonstandard port. Use <strong>VPS control panel (Virtualizor) \u2192 VNC console<\/strong> from the VPSLake client area to recover console access, 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 port shown by <code>ss<\/code>. Keep the current session open and test a second SSH connection before removing any old rule.<\/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. A local PHP application can use <code>localhost<\/code> or the Unix socket; remote database access should be limited to a known source address and encrypted.<\/li>\n\n\n<li>Point <code>YOUR_DOMAIN<\/code> to the VPS, configure an Apache virtual host, and install a trusted TLS certificate before accepting credentials or personal data.<\/li>\n\n\n<li>Keep SSH key authentication enabled, remove unused UFW rules, and review the 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 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 12 use for LAMP?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Debian 12&#8217;s native PHP packages provide PHP 8.2. This guide names the 8.2 packages and service explicitly so Apache uses the same PHP-FPM branch that the VPS is running.<\/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. Apache passes PHP requests through <code>proxy_fcgi<\/code> to the <code>php8.2-fpm<\/code> service, so the embedded Apache PHP module is not needed. Keeping one request path also makes service logs and failures easier to diagnose.<\/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 website on the same VPS connects locally, so MariaDB does not need a public firewall rule. Only consider remote connections for a separate host, and restrict the source address instead of opening the port globally.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I install this stack 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 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 12 use for LAMP?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Debian 12's native PHP packages provide PHP 8.2. This guide names the 8.2 packages and service explicitly so Apache uses the same PHP-FPM branch that the VPS is running.\"}}, {\"@type\": \"Question\", \"name\": \"Do I need `libapache2-mod-php` with PHP-FPM?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Apache passes PHP requests through `proxy_fcgi` to the `php8.2-fpm` service, so the embedded Apache PHP module is not needed. Keeping one request path also makes service logs and failures easier to diagnose.\"}}, {\"@type\": \"Question\", \"name\": \"Should I open MariaDB port 3306 for a PHP website?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. A website on the same VPS connects locally, so MariaDB does not need a public firewall rule. Only consider remote connections for a separate host, and restrict the source address instead of opening the port globally.\"}}, {\"@type\": \"Question\", \"name\": \"Can I install this stack 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 issue a TLS certificate after DNS points to the server.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install LAMP stack on Debian 12 with Apache, PHP 8.2-FPM, MariaDB, UFW, and a safe PHP check for a production-ready VPS in about ten minutes.","protected":false},"author":1,"featured_media":1190,"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,97,117,73,72],"class_list":["post-1189","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-apache","tag-debian-12","tag-lamp-stack","tag-mariadb","tag-php","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1189","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=1189"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1189\/revisions"}],"predecessor-version":[{"id":4243,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1189\/revisions\/4243"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1190"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}