VOOZH about

URL: https://thenewstack.io/install-a-full-lamp-stack-on-a-debian-server/

⇱ Install a Full LAMP Stack on a Debian Server - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-05-19 06:00:22
Install a Full LAMP Stack on a Debian Server
Linux / Operations

Install a Full LAMP Stack on a Debian Server

The Debian Linux distro makes for a great LAMP server, the software stack that has powered internet websites for decades.
May 19th, 2024 6:00am by Jack Wallen
👁 Featued image for: Install a Full LAMP Stack on a Debian Server
Logo courtesy of Debian.

Anyone in the know will tell you that Debian makes an outstanding server operating system. It’s one of the most stable operating systems available, is highly secure and offers all of the tools and apps you need. Whether you’re a small business, an enterprise company, or a development team from one to 100, Debian has something to offer.

Like many Linux distributions, Debian makes for a great LAMP server.

You know LAMP: Linux, Apache (web server), MySQL, PHP. It’s the software stack that has powered the internet for decades.

There is one change of note, in that many users have opted to drop the MySQL option in favor of MariaDB. Why is that, you ask? Simple. MariaDB is more scalable, faster and more secure than Oracle’s MySQL. I’m going to walk you through the installation using MariaDB because I also find this database server to be easier to use.

With that said, let’s get to work.

What You’ll Need

The only things you’ll need for this are a running instance of Debian with a network connection (I’m using version 12, “Bookworm“) and a user with sudo privileges.

Sudo Privileges

Before we get into the installation, you’re going to want to give a standard user sudo privileges. Why? When you install Debian, you get the opportunity to create a new user, but you cannot assign that user as an administrator. A lot of tutorials will tell you to change to the root user (with su –), but I’ve always avoided that because it could lead to security issues. I’m one of those Linux users who will avoid using root at all costs.

So, to make this change, you have to first change to the root user with the command:

su -

With the – in the above command, you do not gain access to root’s $PATH, and since commands like usermod are only accessible to root’s path, you need to use the – option.

Once you’ve successfully authenticated and are at the root user bash prompt, issue the following command to add your user to the sudo group:

usermod -aG sudo USER

Where USER is the username in question.

Once you’ve done that, exit out of root with the exit command and then either log out and log back in (if your server has a GUI), or exit from your SSH session and log back in.

You’re now ready to install the LAMP stack.

Installing Apache

The first thing we’ll do is install Apache. For that, issue the command:

sudo apt-get install apache2 -y

You might run into a situation where you are prompted to insert a CD. If that happens, it means the default sources were not added to the sources.list file. Should that occur, open the necessary file with:

sudo nano /etc/apt/sources.list

You might find only a single line in that file that starts with cdrom. Comment that line out (by adding a # to the beginning) and then paste the following:

deb https://ftp.debian.org/debian/ bookworm contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm contrib main non-free non-free-firmware

deb https://ftp.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware

deb https://ftp.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware

deb https://ftp.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware

deb https://security.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware
# deb-src https://security.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware

Save and close the file. Run apt-get update and the apache2 installation command will work.

Install Uncomplicated Firewall

You may or may not have ufw installed by default (depending on how you installed Debian). To install it, issue the command:

sudo apt-get install ufw -y

Once that’s installed, allow HTTP traffic with the command:

sudo ufw allow in "WWW Full"

If you open a web browser and point it to http://SERVER (Where SERVER is the IP address of your Debian server), you should see the Apache welcome page.

Install MariaDB

Next, we’ll install the database portion of the stack with the command:

sudo apt-get install mariadb-server -y

When that completes, secure the installation with the command:

sudo mysql_secure_installation

Yes, the above command uses mysql, but it is correct.

You’ll first be asked for the current root password. Since that hasn’t been set, hit Enter on your keyboard and type “n” when asked if you want to switch to unix_socet authentication. After that, you’ll be prompted to type/verify a new (strong/secure) password for the root user. Answer “y” to the remaining questions.

Installing PHP

The final piece of the puzzle is PHP, which is installed with the command:

sudo apt-get install php libapache2-mod-php php-mysql -y

Let’s verify PHP is installed and working. To do that, create a new file with:

sudo nano /var/www/html/info.php

In that file, paste the following:

Save and close the file. Point your browser to http://SERVER/info.php (where SERVER is the IP address of your Debian server) and you should see a listing of the PHP version and a list of other important information (Figure 1).

👁 Image

Figure 1: The site of this page means Apache and PHP are working as expected.

Congratulations, you’ve just built your first LAMP server using Debian. You can now start building websites and even use it for serving up web apps (with a bit more work, of course). We’ll be coming back to Debian in future tutorials, but with this base knowledge, there’s no limit to what you can do with this open source operating system.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
The Linux Foundation and Oracle are sponsors of The New Stack. 
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.