Do you want to host your own website or web app using a Debian server? One of the easiest ways to do that is by setting up a LAMP stack.
LAMP stands for Linux, Apache, MySQL (or MariaDB), and PHP. These tools work together to run websites. It’s a popular setup used by WordPress, Joomla, and many other platforms.
In this guide, I’ll show you how I usually set up a LAMP stack on Debian. I’ll use simple steps, explain why each step matters, and share some personal thoughts to help you avoid problems.
Let’s get started.
What Is a LAMP Stack?
Before we dive in, here’s a quick look at what each part of the LAMP stack does:
- Linux is the operating system. In this case, you’re using Debian.
- Apache is the web server. It shows your website to the world.
- MySQL or MariaDB is the database. It stores your content.
- PHP is the language that runs your website’s code.
These tools work together. They’re free, powerful, and run on millions of servers.
Step 1: Update Your System
The first thing I do on any new server is run updates. This makes sure everything is fresh and secure.
In your terminal, type:
sudo apt update && sudo apt upgrade -y
This checks for the latest software and installs updates.
Step 2: Install Apache
Apache is the most common web server on Linux.
To install it, run:
sudo apt install apache2 -y
After it installs, check if it’s running:
sudo systemctl status apache2
You should see something like “active (running)”.
Now, open a browser and go to your server’s IP address. You should see a page that says “Apache2 Debian Default Page.” That means Apache is working.
Step 3: Install MariaDB (or MySQL)
For the database, I usually use MariaDB. It’s a fork of MySQL and works the same way.
Install it like this:
sudo apt install mariadb-server -y
Start the database service:
sudo systemctl start mariadb
Enable it to start on reboot:
sudo systemctl enable mariadb
Now let’s secure it:
sudo mysql_secure_installation
You’ll be asked a few questions. I suggest answering them like this:
- Set a root password → Yes
- Remove anonymous users → Yes
- Disallow remote root login → Yes
- Remove test database → Yes
- Reload privilege tables → Yes
These changes help protect your data.
Step 4: Install PHP
PHP lets your website connect to the database and run scripts.
Install PHP and some common modules with:
sudo apt install php libapache2-mod-php php-mysql -y
After this, restart Apache:
sudo systemctl restart apache2
Let’s test PHP. Create a file in Apache’s root folder:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Now go to: http://your-server-ip/info.php
You’ll see a purple page showing PHP settings. That means PHP works.
Don’t forget to delete the file when you’re done:
sudo rm /var/www/html/info.php
Step 5: Set File Permissions (Optional but Helpful)
Sometimes you’ll upload files to your server or install something like WordPress. It helps to set the right file permissions.
Here’s a basic setup:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
This gives Apache ownership of your web folder and allows it to read the files.
Step 6: Test Everything Together
Let’s make sure the whole stack is working.
- Apache is serving web pages.
- PHP is processing scripts.
- MariaDB is ready to store data.
You now have a working LAMP stack.
You can now install web apps like WordPress, phpMyAdmin, or build your own site.
Why I Use LAMP on Debian
There are many ways to run a server, but I like LAMP on Debian for a few reasons:
- Debian is stable and doesn’t change too often.
- The LAMP stack is simple and widely used.
- You can find answers online easily if something breaks.
I’ve tried other setups too—like Nginx or newer stacks—but for many small to medium websites, LAMP just works.
Two Handy Lists
What You Should Install:
apache2
for your web servermariadb-server
ormysql-server
for your databasephp
and modules likephp-mysql
- Extra tools like
php-cli
,php-curl
,php-xml
(optional but helpful)
What You Should Remember:
- Always update your system first
- Run
mysql_secure_installation
to lock down your database - Use strong passwords for your MariaDB users
- Restart services after big changes
- Test each part before moving on
Common Mistakes to Avoid
Here are a few things I learned the hard way:
- Skipping the database security step. That’s how hackers get in.
- Using the root account in your apps. Always make a new user and database for each app.
- Not restarting Apache after changing PHP. Changes won’t show up unless you restart.
- Leaving test files like info.php online. That’s a security risk.
Have you run into any of these?
What’s Next?
Now that your LAMP stack is running, what will you build?
You could:
- Install WordPress or Joomla
- Create a custom website using PHP
- Set up a learning project with MySQL
- Try writing your own blog or portfolio
If you get stuck, just search for help using your error message. You’ll almost always find a fix.
Final Thoughts
Setting up a LAMP stack on Debian is a great way to take control of your website or app. It’s free, flexible, and runs well on small or big servers.
Now you have:
- Apache showing web pages
- PHP processing code
- MariaDB storing your data
- Debian holding it all together
It might seem like a lot at first, but after doing it once or twice, it becomes second nature.
What will you build with your new server?