How to Install LAMP Stack on Debian 13 (Step-by-Step)

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.
A polished 3D illustration of a Debian server, web gateway, PHP processor, and database cylinder connected by glowing blue trails.

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.

Prerequisites

  • A 64-bit Debian 13 (Trixie) VPS with at least 1 GB of RAM and 10 GB of free disk space.
  • SSH access as root, or a normal account with working sudo privileges.
  • Outbound Internet access to Debian’s configured package repositories.
  • A public IP address for testing Apache. A domain is optional at first, but you need one for a production TLS certificate.
  • A VPSLake Linux VPS with root access if you need a server for this stack.

The commands use sudo for a non-root account. If you are logged in as root, remove sudo from each command.

Step 1: Confirm Debian 13 and apply updates

Checking the release before installing packages prevents a PHP or service mismatch caused by following instructions for Debian 11 or Debian 12.

grep -E '^(PRETTY_NAME|VERSION_ID|VERSION_CODENAME)=' /etc/os-release
uname -m
sudo apt update
sudo apt full-upgrade -y

The release should show Debian 13 and trixie; a typical 64-bit VPS reports x86_64. Package versions can change as Debian publishes updates.

PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
VERSION_ID="13"
VERSION_CODENAME=trixie
x86_64

If the upgrade installs a new kernel, keep this SSH session open until you know the VPS can reboot and accept a new connection.

Step 2: Install Apache and protect the web ports

Apache handles HTTP requests, while UFW limits public access to SSH and the web services the server actually needs.

sudo apt install -y apache2 apache2-utils curl ufw
sudo systemctl enable --now apache2
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw --force enable
sudo ufw status verbose
sudo systemctl is-active apache2

Add the SSH rule before enabling UFW. If SSH uses a custom port, allow that port instead of relying on the OpenSSH profile. The service check should print active, and UFW should list SSH, HTTP, and HTTPS.

Test Apache locally before testing the public IP. This separates a web-server problem from a provider-level firewall or networking problem.

sudo apachectl configtest
curl -fsSI http://127.0.0.1/
Syntax OK
HTTP/1.1 200 OK
Content-Type: text/html

Step 3: Install PHP 8.4 and connect PHP-FPM to Apache

Debian 13’s native PHP packages select PHP 8.4, and PHP-FPM runs scripts through FastCGI without loading the interpreter directly into Apache workers. The PHP-FPM manual explains the process manager used here.

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
php -v

The version line should start with PHP 8.4. Debian’s php metapackage keeps the command aligned with the release’s supported PHP branch.

Enable Apache’s 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.

PHP_VERSION="$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')"
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf "php${PHP_VERSION}-fpm"
sudo systemctl enable --now "php${PHP_VERSION}-fpm"
sudo systemctl reload apache2

Create a short-lived endpoint that returns a fixed value. It confirms that Apache reaches PHP without publishing the detailed configuration exposed by phpinfo().

printf '%s\n' '<?php echo "PHP OK\\n"; ?>' | sudo tee /var/www/html/health.php > /dev/null
curl -fsS http://127.0.0.1/health.php
sudo rm -f /var/www/html/health.php
PHP OK

Step 4: Install MariaDB and create an application database

MariaDB stores application data, and a database user restricted to localhost lets a site connect without exposing port 3306 to the Internet.

sudo apt install -y mariadb-server mariadb-client
sudo systemctl enable --now mariadb
sudo systemctl is-active mariadb
sudo mariadb-secure-installation

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’s official mariadb-secure-installation reference for the prompt meanings.

Create a database and login for the application. Replace YOUR_DB_PASSWORD with a long, unique secret before running this block.

sudo mariadb <<'SQL'
CREATE DATABASE lampdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'lampuser'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';
GRANT ALL PRIVILEGES ON lampdb.* TO 'lampuser'@'localhost';
FLUSH PRIVILEGES;
SQL
sudo mariadb -e "SHOW DATABASES LIKE 'lampdb';"

The final command should return one row named lampdb. Store the real password in your application’s secret configuration, not inside the public document root.

Verify the LAMP stack

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.

PHP_VERSION="$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')"
sudo systemctl is-active apache2 "php${PHP_VERSION}-fpm" mariadb
sudo systemctl is-enabled apache2 "php${PHP_VERSION}-fpm" mariadb
sudo apachectl configtest
php -m | grep -E 'mysqli|mysqlnd|PDO|mbstring|xml'
sudo mariadb -e "SELECT VERSION();"
curl -fsSI http://127.0.0.1/
sudo ufw status

Expect three active lines, three enabled lines, Syntax OK, PHP module names, a MariaDB version, an HTTP success response, and an active UFW policy.

active
active
active
enabled
enabled
enabled
Syntax OK
HTTP/1.1 200 OK
Status: active

Troubleshooting

Unit php8.4-fpm.service not found

The FPM package is missing, or the server is not using Debian 13 repositories. Confirm the release and package candidate before enabling Apache’s FPM configuration.

grep -E '^(PRETTY_NAME|VERSION_ID|VERSION_CODENAME)=' /etc/os-release
sudo apt update
sudo apt install -y php8.4-fpm
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo systemctl enable --now php8.4-fpm
sudo systemctl reload apache2

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.

PHP source appears in the browser or Apache returns 503 Service Unavailable

Apache is not passing .php requests to FPM, or the FPM service failed to start. Inspect the unit log and Apache configuration before restarting.

PHP_VERSION="$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')"
sudo systemctl status "php${PHP_VERSION}-fpm" --no-pager
sudo journalctl -u "php${PHP_VERSION}-fpm" -n 40 --no-pager
sudo apachectl configtest
sudo systemctl restart "php${PHP_VERSION}-fpm" apache2

If the test still fails, confirm that /etc/apache2/conf-enabled/php8.4-fpm.conf exists and that proxy_fcgi is enabled. Recreate the temporary health.php endpoint only long enough to test it.

SSH stops working after enabling UFW

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’s VPS control panel (Virtualizor) → VNC console from the VPSLake client area, then allow the actual port.

sudo ss -ltnp | grep ssh
sudo ufw allow YOUR_SSH_PORT/tcp
sudo ufw status numbered

Replace YOUR_SSH_PORT with the numeric listening port. Keep the current SSH session open and test a second connection before removing any old rule.

Access denied for user 'lampuser'@'localhost'

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.

mariadb -u lampuser -p lampdb -e "SELECT 1;"

Enter the real password, not the placeholder. If it is wrong, reset it from the administrative socket and update the application configuration too.

sudo mariadb -e "ALTER USER 'lampuser'@'localhost' IDENTIFIED BY 'NEW_DB_PASSWORD';"

Hardening

  • Keep port 3306 closed. A local website can use localhost or the Unix socket; remote database access should be restricted to a known source address and encrypted.
  • Point YOUR_DOMAIN to the VPS, install a trusted TLS certificate, and redirect HTTP to HTTPS before collecting credentials or personal data.
  • Keep SSH key authentication enabled, remove unused UFW rules, and review the final policy with the VPSLake UFW firewall generator.
  • Remove temporary test files, back up /var/www/html and the MariaDB databases, and apply Debian security updates regularly.

FAQ

Which PHP version does Debian 13 use for LAMP?

Debian 13’s 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.

Do I need libapache2-mod-php with PHP-FPM?

No. This setup uses Apache’s proxy_fcgi module and PHP-FPM, so libapache2-mod-php is unnecessary. Keeping one PHP request path avoids conflicts between Apache’s prefork module and the FPM handler.

Should I open MariaDB port 3306 for a PHP website?

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.

Can I install the stack before I have a domain name?

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.

Samrat Ghosh
Written by

Samrat Ghosh

Founder & Infrastructure Engineer

Samrat Ghosh is the founder of VPSLake, where he builds and runs the remote desktop and VPS hosting infrastructure the company is built on. He writes hands-on guides about RDP, Windows Server, VPS management and secure remote access - the practical documentation he wishes had…

Previous Article

How to Install LAMP Stack on Debian 11

Next Article

Stop Windows Update Restarting Your VPS Safely

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨