TNS
VOXPOP
Do You Resent AI?
If you’re a developer, do you resent generative AI’s ability to write code?
Yes, because I spent a lot of time learning how to code.
0%
Yes, because I fear that employers will replace me and/or my peers with it.
0%
Yes, because too much investment is going to AI at the expense of other needs.
0%
No, because it makes too many programming mistakes.
0%
No, because it can’t replace what I do.
0%
No, because it is a tool that will help me be more productive.
0%
No, I am a highly evolved being and resent nothing.
0%
I don’t think much about AI.
0%
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
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:


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:


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:


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:


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:


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:


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


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:


When that completes, secure the installation with the command:


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:


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


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).

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.

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.