Debian is one of the best Linux server distributions, and LAMP is one of the most common ways to host a website. Together, they make a perfect match. It’s very simple to get LAMP up and running on Debian 10 using packages right out of the default repositories.
In this tutorial you will learn:
- How to Set Up MariaDB
- How to Install PHP
- How to Install Apache
- How to Test Your Server
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Debian 10 Buster |
Software | Apache, MariaDB, and PHP |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Set Up MariaDB
MariaDB is a fork of MySQL, and it can serve as a drop-in replacement for it. Debian and other Linux distributions have opted to use MariaDB as the default MySQL option in recent years because MariaDB is an independent project, while MySQL is controlled by Oracle.
The first thing you’ll need on your LAMP server is that MariaDB database because the other components of the server rely on it. Thankfully, the database requires only minimal setup to get running.
Install MariaDB
Begin by installing MariaDB from the Debian repositories. It’s broken into server and client components. For this, you’ll need both.
$ sudo apt install mariadb-server mariadb-client
Set Up The Database
Now that you have the MariaDB packages, you’ll need to set up a basic database for your web application to use. A database like this will work for a WordPress install.
MariaDB comes with a convenient utility to secure your database automatically. Run that before you do anything else.
$ sudo mysql_secure_installation
Run through the script. Start by creating a new root password prompted. From there, just answer “yes” to each question. They remove extra junk and set up secure defaults for your server.
Start by logging in to MariaDB via the mysql
command as root.
# mysql -u root -p
After you’re signed in, create a new database to work with. You can name it whatever you like.
CREATE DATABASE newdb;
Then, create a new user to access the database. Using root for anything but administrative tasks is a security risk and a terrible idea.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'userpassword';
For that user to be able to work with the database, you need to grant it privileges on the DB. Since this user is going to be your general purpose user, grant it all privileges.
GRANT ALL PRIVILEGES ON newdb.* TO 'username'@'localhost';
You’re all set up. Flush the privileges and exit the database.
FLUSH PRIVILEGES; \q
Install PHP
PHP is the next part of the LAMP server you’ll need. This one doesn’t take much setup. You only need to install it. Apache will handle actually running it when you start the server up.
$ sudo apt install php php-mysql
Install Apache
Finally, you’re ready to set up Apache, the actual web server. For a basic LAMP server, this is as simple as installing Apache itself and the Apache PHP module. Debian systems automatically start up any service they install, so Apache will be running right after the install completes.
$ sudo apt install apache2 libapache2-mod-php
You can see that your server is, in fact, running by opening your browser and entering localhost
in the address bar. You should be greeted by Debian’s default Apache page.
Test Your Server
Apache looks for an index file in /var/www/html
to serve first. That can be either index.html
or index.php
, but it’ll go with the HTML one first, if they’re both there. Delete the existing index.html
, and create either a new index.php
file.
Open the file, and place the following line of PHP inside.
<?php phpinfo(); ?>
Refresh the localhost
tab. This time, you should see a big table loaded with information about PHP on your server. This page proves that your server can run and serve PHP code.
You’re done. Your server is ready to start serving PHP. You can actually install WordPress on it right now. However, if you wan a simple way to manage your database, you can install PHPMyAdmin to provide you with a graphical web-based way to access and manage MariaDB.
Note: There currently isn’t a phpmyadmin package in Buster yet, but there is one in both Stretch and Sid. You can either wait or use Apt pinning to get it from either other release.
# sudo apt install phpmyadmin
Now, you can navigate to localhost/phpmyadmin
, and you’ll arrive at a login screen that you can use to sign in to the database user account that you set up before, and start working on your database.
Conslusion
Your server is now serving PHP. You can easily manage it, and you’ll receive regular security updated and bugfixes from the Debian repos. You may want to implement additional security, like a firewall, if you plan on hosting with the server online, but everything else is in place.