{"id":1177,"date":"2026-11-26T09:00:00","date_gmt":"2026-11-26T09:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1177"},"modified":"2026-11-26T09:00:00","modified_gmt":"2026-11-26T09:00:00","slug":"install-lamp-stack-debian-11","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/26\/install-lamp-stack-debian-11\/","title":{"rendered":"How to Install LAMP Stack on Debian 11"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install LAMP stack on Debian 11 and you will have Apache serving web requests, PHP 7.4 running through PHP-FPM, and MariaDB ready for a local application database. Allow about ten minutes for a fresh VPS, including a firewall and a safe PHP test.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Debian 11 is an older release, so use these instructions for an existing Bullseye server and plan a migration to a supported Debian release for a new production deployment.<\/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 11 (Bullseye) 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 configured Debian package repositories.<\/li>\n\n\n<li>A public IPv4 address for testing Apache. A domain is optional during installation but needed for a production TLS certificate.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need a root-access 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 already connected as <code>root<\/code>, remove <code>sudo<\/code> from the commands.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Confirm Bullseye and update packages<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking the release first prevents you from applying Debian 12 or Debian 13 instructions to this PHP 7.4-based system. Updating the package index and installed packages also applies the latest packages available to your configured Bullseye repositories.<\/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 identify Debian GNU\/Linux 11 and <code>bullseye<\/code>; a typical VPS reports <code>x86_64<\/code> for the architecture. The exact package versions can differ from the examples below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Debian GNU\/Linux 11 (bullseye)\"\nVERSION_ID=\"11\"\nVERSION_CODENAME=bullseye\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 server can reboot and reconnect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Apache and configure UFW<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache serves static files and forwards PHP requests later, while UFW keeps the public firewall limited to SSH and web traffic.<\/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 listens on a custom port, allow that port instead of relying only on the <code>OpenSSH<\/code> application profile. The status should show an active firewall with ports 22, 80, and 443 allowed according to your rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test Apache locally before using a browser. A successful response proves the service is listening even if an upstream VPS firewall still blocks the public address.<\/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 7.4 and connect PHP-FPM to Apache<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bullseye\u2019s native PHP metapackages select PHP 7.4, and PHP-FPM executes scripts through FastCGI without loading PHP directly into every Apache worker. The <a href=\"https:\/\/www.php.net\/manual\/en\/install.fpm.php\" target=\"_blank\" rel=\"noopener\">official PHP-FPM documentation<\/a> describes this process manager\u2019s role.<\/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\nphp -v<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first line should begin with <code>PHP 7.4<\/code>. The package <code>php-json<\/code> is not needed separately here because JSON support is included in the PHP 7.4 common package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enable Apache\u2019s FastCGI proxy module and the FPM configuration that matches the installed PHP minor version.<\/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 temporary endpoint that returns a fixed value instead of exposing <code>phpinfo()<\/code>, which can reveal server configuration. The final command removes the file as soon as the request succeeds.<\/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 and secure MariaDB<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB supplies the SQL database, and a user restricted to <code>localhost<\/code> lets the web application 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\">When the security script asks questions, remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables. On MariaDB 10.5, keeping local Unix-socket authentication for the administrative account is fine; the 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> if a prompt differs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a database and a separate login for the application. Replace <code>YOUR_DB_PASSWORD<\/code> with a long, unique password 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 last command should return one row named <code>lampdb<\/code>. Keep the real database password in your application\u2019s secret configuration, never 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 these checks together to confirm that Apache, the matching PHP-FPM unit, and MariaDB are running and enabled at boot. The final requests also prove that Apache accepts its configuration, PHP has the MariaDB connector, and the web server answers locally.<\/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> results, three <code>enabled<\/code> results, <code>Syntax OK<\/code>, the PHP module names, a MariaDB version, and an HTTP success response.<\/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.<\/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>404 Not Found<\/code> or an expired release during <code>apt update<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Debian 11 is an older release and its normal security repositories may no longer be available after the Bullseye support window. For a new deployment, rebuild the VPS with a supported Debian release; do not keep installing security-sensitive software from random mirrors.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If an existing Bullseye server must remain temporarily, inspect the configured entries and use Debian\u2019s official archive instructions for that release. Archived packages do not restore current security support, so schedule the migration before exposing the site to users.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -RInE '(^deb .*bullseye|^deb-src .*bullseye)' \/etc\/apt\/sources.list \/etc\/apt\/sources.list.d 2&gt;\/dev\/null<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><code>Unit php7.4-fpm.service not found<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The FPM package is missing, or the package index does not belong to Bullseye. Confirm the release, install the versioned FPM package, and enable the matching Apache 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 install -y php7.4-fpm\nsudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php7.4-fpm\nsudo systemctl enable --now php7.4-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 handing <code>.php<\/code> files to FPM, or the FPM service failed to start. Check the service log and Apache configuration, then restart after correcting the reported error.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status php7.4-fpm --no-pager\nsudo journalctl -u php7.4-fpm -n 40 --no-pager\nsudo apachectl configtest\nsudo systemctl restart php7.4-fpm apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Recreate the short-lived <code>health.php<\/code> test from Step 3. If PHP source is still shown, check that <code>\/etc\/apache2\/conf-enabled\/php7.4-fpm.conf<\/code> exists and that <code>proxy_fcgi<\/code> is enabled.<\/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 does not match the value used when the account was created, or the account was created for a different host. Test the account through the local socket before changing grants.<\/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 account and update the application configuration 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 MariaDB\u2019s port 3306 closed. A local application can use <code>localhost<\/code> or the Unix socket; if you later need remote access, restrict it to a specific source address and require encrypted connections.<\/li>\n\n\n<li>Point <code>YOUR_DOMAIN<\/code> to the VPS, install a trusted TLS certificate, and redirect HTTP to HTTPS before accepting credentials or personal data.<\/li>\n\n\n<li>Keep SSH protected with keys, disable password login after confirming key access, and review the final UFW rules with the <a href=\"https:\/\/vpslake.com\/ufw-firewall-generator\">VPSLake UFW firewall generator<\/a>.<\/li>\n\n\n<li>Remove test files, back up <code>\/var\/www\/html<\/code> and MariaDB databases, and plan the move from Bullseye to a supported Debian release.<\/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 include on Debian 11?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">LAMP means Linux, Apache, MariaDB, and PHP. This guide uses the <code>apache2<\/code> service, PHP 7.4 through PHP-FPM, and the <code>mariadb<\/code> service with a local application database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is PHP 7.4 the correct PHP version for Bullseye?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Debian 11\u2019s native PHP metapackages resolve to PHP 7.4. If your application requires a newer PHP branch, use a supported Debian release or a carefully maintained, release-compatible package source rather than mixing packages from another Debian version.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I open port 3306 for WordPress or another website?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A website running on the same VPS can connect to MariaDB locally, so it does not need a public database port. Leave 3306 closed unless a separate host genuinely needs access.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why use PHP-FPM instead of <code>libapache2-mod-php<\/code>?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PHP-FPM keeps the interpreter in its own service and lets Apache pass PHP requests through FastCGI. It also makes the active PHP service explicit, which is useful when checking logs or changing PHP versions later.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"What does LAMP include on Debian 11?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"LAMP means Linux, Apache, MariaDB, and PHP. This guide uses the `apache2` service, PHP 7.4 through PHP-FPM, and the `mariadb` service with a local application database.\"}}, {\"@type\": \"Question\", \"name\": \"Is PHP 7.4 the correct PHP version for Bullseye?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Debian 11\u2019s native PHP metapackages resolve to PHP 7.4. If your application requires a newer PHP branch, use a supported Debian release or a carefully maintained, release-compatible package source rather than mixing packages from another Debian version.\"}}, {\"@type\": \"Question\", \"name\": \"Should I open port 3306 for WordPress or another website?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. A website running on the same VPS can connect to MariaDB locally, so it does not need a public database port. Leave 3306 closed unless a separate host genuinely needs access.\"}}, {\"@type\": \"Question\", \"name\": \"Why use PHP-FPM instead of `libapache2-mod-php`?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"PHP-FPM keeps the interpreter in its own service and lets Apache pass PHP requests through FastCGI. It also makes the active PHP service explicit, which is useful when checking logs or changing PHP versions later.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install LAMP stack on Debian 11 with Apache, PHP 7.4-FPM, MariaDB, UFW, and a safe health check, then verify your VPS in about ten minutes today.","protected":false},"author":1,"featured_media":1178,"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,96,117,73,72],"class_list":["post-1177","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-apache","tag-debian-11","tag-lamp-stack","tag-mariadb","tag-php","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1177","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=1177"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1177\/revisions"}],"predecessor-version":[{"id":4222,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1177\/revisions\/4222"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1178"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}