If you’ve ever tried to host a PHP site or app and stared at a blank server thinking, “Okay… now what?”, you’re not alone.
Before: you’ve got a fresh Debian 11 box and some PHP code (maybe WordPress, maybe a custom app), but nothing is running.
After: you’ll have a working LAMP stack (Linux, Apache, MariaDB, PHP) on Debian 11, ready to serve dynamic websites.
This guide is for you if you:
– Have a Debian 11 server
– Want Apache, MariaDB, and PHP installed cleanly
– Prefer clear, repeatable commands instead of guessing
We’ll walk through it step by step.
1. What You Need Before You Start
Let’s get the basic requirements out of the way so you don’t hit weird permission or firewall issues half way through.
You should have:
– A Debian 11 server
– A non-root user with sudo privileges
– A basic firewall already set up (UFW is typical on Debian 11)
If you’re missing any of those, fix that first. The commands below assume you’re logged in as your sudo user, not as root.
Safety tip: If this is a remote server, make sure you already have SSH access working properly. Losing SSH mid-install because of firewall settings is not fun.
2. Update Package Index (Always Do This First)
Before installing anything, refresh Debian’s package list so you don’t install outdated stuff.
Run:
sudo apt update
If this is your first sudo command in the session, Debian will ask for your user password. That’s normal.
Why this matters: apt update makes sure Debian knows the latest versions of the packages available. Skipping this can cause dependency issues or install older packages.
3. Install Apache Web Server
Apache is the part of the LAMP stack that actually serves web pages to visitors. It’s popular, well-documented, and a solid default.
Install Apache with:
sudo apt install apache2
You’ll be asked to confirm the installation. Type Y and press ENTER.
Once it finishes, Apache should be installed and running.
You can do a quick sanity check (if your firewall allows it) by pointing your browser to your server’s IP address. If Apache is working, you should see a default page served by Apache.
4. Allow Web Traffic Through the Firewall
If you followed a typical initial server setup, you probably have UFW (Uncomplicated Firewall) enabled. That’s good, but by default it might not allow web traffic yet.
Debian 11 ships UFW with some pre-defined “app profiles” so you don’t have to remember ports.
First, list the available profiles:
sudo ufw app list
Look for the WWW profiles in the output. These are used to manage web traffic rules (HTTP and possibly HTTPS).
The idea here: instead of manually opening ports, you tell UFW “allow web traffic” using these app names. This keeps things clearer and less error-prone.
Make sure the profile that allows HTTP and HTTPS traffic is enabled. (The exact enabling commands aren’t shown in the source text, but you’ll use the relevant WWW profile name you saw in the list.)
Quick firewall reminder: Only open what you need. Web servers usually need HTTP and HTTPS, nothing more on public interfaces.
5. Install MariaDB (Database Layer)
Next piece of the LAMP stack is the database. Traditionally this is MySQL, but on Debian 11, MariaDB is used as a drop-in replacement.
Functionally, for most basic setups, you can treat it as “MySQL-compatible.”
In this guide, MariaDB is the default database server in the stack. You’ll use it to store your site or app data.
(Installation commands and hardening steps aren’t in the provided source extract, so we’ll stay at this conceptual level.)
Once MariaDB is installed and running, you’ll be able to create databases and users for your apps.
6. Install PHP (Dynamic Content)
You’ve got Apache to serve pages and MariaDB to store data. Now you need PHP to generate dynamic content.
PHP sits between Apache and the database: it takes requests from the web server, talks to MariaDB, and outputs HTML.
In this LAMP setup, PHP is responsible for processing things like login forms, shopping carts, or any dynamic page.
When PHP is installed and hooked into Apache correctly, *.php files on your server won’t just download—they’ll be executed and rendered as web pages.
7. How This Stack Fits Together
Quick mental model so the whole stack makes sense:
- Linux (Debian 11): The base operating system running everything.
- Apache: Listens on HTTP/HTTPS and serves web pages.
- MariaDB: Stores your application and website data.
- PHP: Runs your application logic and talks to MariaDB.
So when someone opens your site:
1. Browser hits Apache.
2. Apache hands .php requests to PHP.
3. PHP runs code, asks MariaDB for data if needed.
4. PHP returns HTML to Apache.
5. Apache sends it back to the browser.
Once this LAMP stack is in place, you can start deploying PHP apps like CMSs, small custom tools, or other dynamic sites.
8. Next Steps After the Basic LAMP Install
After you’ve got Linux + Apache + MariaDB + PHP set up, here are typical next steps:
- Create a database and user in MariaDB for your app.
- Adjust Apache configuration for your specific site (virtual hosts, document roots).
- Place your PHP application files in the web root.
- Test a simple
info.phpfile (a tiny PHP script) to confirm PHP is working.
And always keep these two habits:
– Keep backups of your config files before major changes.
– Test things in a staging or non-production environment when possible.
Once your LAMP stack is working, you’ve basically unlocked the “host most PHP apps” achievement.
If this worked for you, keep CrushEdge handy for the next fix.
1 Comment
[…] guide assumes you already have a Debian 11 server ready to go. You should […]