How to Install LAMP Stack on Debian 13 (Trixie)

A LAMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MariaDB database, and dynamic content is processed by PHP.

Update Debian 13

apt update && apt -y upgrade

Install MariaDB Database Server

To get started with MariaDB installation, follow the below steps:

apt install -y mariadb-server mariadb-client

Check the status of mariaDB database server

systemctl status mariadb

Output:

root@server:~# systemctl status mariadb
● mariadb.service - MariaDB 11.8.2 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: >
     Active: active (running) since Tue 2025-08-05 10:54:26 EDT; 15s ago
 Invocation: 1ff07ff0bcdd4a97aa4dd7d67809330c
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 12069 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /va>
    Process: 12071 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] &&>
    Process: 12140 ExecStartPost=/bin/rm -f /run/mysqld/wsrep-start-position (c>
    Process: 12142 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0>
   Main PID: 12123 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 13 (limit: 46545)
     Memory: 124.9M (peak: 129.4M)
        CPU: 5.891s
     CGroup: /system.slice/mariadb.service
             └─12123 /usr/sbin/mariadbd

Run the command below to secure your database server manually:

mysql -u root

Inside the MariaDB shell:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_secure_password';
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DROP DATABASE IF EXISTS test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
FLUSH PRIVILEGES;
EXIT;

You can log in as your root user and set up a regular user and a database.

mysql -u root -p

Inside the MariaDB shell:

CREATE DATABASE exampledb;
CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY 'securepassword';
GRANT ALL PRIVILEGES ON exampledb.* TO 'exampleuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Install Apache Web Server

Apache is one of the most commonly used web servers. You can install it by running the below command:

apt install -y apache2 apache2-utils

Output:

root@server:~# apt install -y apache2 apache2-utils
The following package was automatically installed and is no longer required:
  linux-image-6.12.33+deb13-amd64
Use 'apt autoremove' to remove it.

Installing:
  apache2  apache2-utils

Installing dependencies:
  apache2-bin              libaprutil1t64  libnghttp3-9         libssh2-1t64
  apache2-data             libcurl4t64     librtmp1             ssl-cert
  libapr1t64               libldap-common  libsasl2-2
  libaprutil1-dbd-sqlite3  libldap2        libsasl2-modules
  libaprutil1-ldap         liblua5.4-0     libsasl2-modules-db

Suggested packages:
  apache2-doc              libsasl2-modules-gssapi-mit
  apache2-suexec-pristine  | libsasl2-modules-gssapi-heimdal
  | apache2-suexec-custom  libsasl2-modules-ldap
  ufw                      libsasl2-modules-otp
  www-browser              libsasl2-modules-sql

Summary:
  Upgrading: 0, Installing: 19, Removing: 0, Not Upgrading: 0
  Download size: 3,522 kB
  Space needed: 11.6 MB / 18.1 GB available

Check apache build and version:

apache2 -v

Output:

root@server:~# apache2 -v
Server version: Apache/2.4.65 (Debian)
Server built:   2025-07-29T17:52:31

Check service status:

systemctl status apache2

Output:

root@server:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: >
     Active: active (running) since Tue 2025-08-05 10:56:37 EDT; 1min 44s ago
 Invocation: 297ee38aea624c1fb386e71bca079b18
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 12881 (apache2)
      Tasks: 55 (limit: 7052)
     Memory: 5.1M (peak: 5.5M)
        CPU: 150ms
     CGroup: /system.slice/apache2.service
             ├─12881 /usr/sbin/apache2 -k start
             ├─12883 /usr/sbin/apache2 -k start
             └─12884 /usr/sbin/apache2 -k start

Enable/allow HTTP and HTTPS ports ( 80/443 ):

To enable HTTP and HTTPS, install UFW firewall:

apt install ufw -y

Output:

root@server:~# apt install ufw -y
The following package was automatically installed and is no longer required:
  linux-image-6.12.33+deb13-amd64
Use 'apt autoremove' to remove it.

Installing:
  ufw

Installing dependencies:
  iptables  libip4tc2  libip6tc2  libnetfilter-conntrack3  libnfnetlink0

Suggested packages:
  firewalld  rsyslog

Summary:
  Upgrading: 0, Installing: 6, Removing: 0, Not Upgrading: 0
  Download size: 627 kB
  Space needed: 3,678 kB / 18.1 GB available

Enable HTTP, HTTPS, and SSH:

ufw allow http
ufw allow https
ufw allow ssh

Enable and reload UFW:

ufw enable
ufw reload

Output:

root@server:~# ufw enable
    ufw reload
Firewall is active and enabled on system startup
Firewall reloaded

Restart and enable apache:

systemctl reload apache2
systemctl enable apache2

Open your server IP in the browser:

http://<server_IP>

Example:

images

Install PHP

Follow the below steps to install PHP on the server:

apt install -y php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath

Output:

root@server:~#     apt install -y php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
Note, selecting 'php8.4-common' instead of 'php-pdo'
The following package was automatically installed and is no longer required:
  linux-image-6.12.33+deb13-amd64
Use 'apt autoremove' to remove it.

Installing:
  libapache2-mod-php  php-cli   php-gd        php-mysql  php-zip
  php                 php-curl  php-json      php-pear   php8.4-common
  php-bcmath          php-fpm   php-mbstring  php-xml

Installing dependencies:
  fontconfig-config      libheif-plugin-aomenc    libxslt1.1
  fonts-dejavu-core      libheif-plugin-dav1d     libyuv0
  fonts-dejavu-mono      libheif-plugin-libde265  libzip5
  libabsl20240722        libheif-plugin-x265      php-common
  libaom3                libheif1                 php8.4
  libapache2-mod-php8.4  libimagequant0           php8.4-bcmath
  libargon2-1            libjbig0                 php8.4-cli
  libavif16              libjpeg62-turbo          php8.4-curl
  libdav1d7              liblerc4                 php8.4-fpm
  libde265-0             libonig5                 php8.4-gd
  libdeflate0            librav1e0.7              php8.4-mbstring
  libfontconfig1         libsharpyuv0             php8.4-mysql
  libgav1-1              libsodium23              php8.4-opcache
  libgcrypt20            libsvtav1enc2            php8.4-readline
  libgd3                 libtiff6                 php8.4-xml
  libgomp1               libwebp7                 php8.4-zip
  libgpg-error-l10n      libx265-215
  libgpg-error0          libxpm4

Suggested packages:
  rng-tools                 libheif-plugin-jpegenc  libheif-plugin-rav1e
  libgd-tools               libheif-plugin-j2kdec   libheif-plugin-svtenc
  libheif-plugin-ffmpegdec  libheif-plugin-j2kenc
  libheif-plugin-jpegdec    libheif-plugin-kvazaar

Summary:
  Upgrading: 0, Installing: 66, Removing: 0, Not Upgrading: 0
  Download size: 22.8 MB
  Space needed: 95.4 MB / 18.1 GB available

Enable PHP module and restart apache:

a2enmod php8.4
systemctl restart apache2

Output:

root@server:~#  a2enmod php8.4
    systemctl restart apache2
Considering dependency mpm_prefork for php8.4:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php8.4:
Module php8.4 already enabled

Confirm PHP version:

php -v

Output:

root@server:~#  php -v
PHP 8.4.10 (cli) (built: Jul  3 2025 12:35:27) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.10, Copyright (c), by Zend Technologies

In order to test the PHP is working on the server, we will create a small file:

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

To view the PHP info on your browser:

http://<server_ip>/info.php

Example:

images

Once you confirmed PHP is installed and working, remove the info.php file for security:

rm /var/www/html/info.php

Done! This concludes our topic of installing LAMP Stack on a Debian 13 (Trixie) system.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS