# Debian LEMP stack

There is a lot of guides how to configure Nginx, MariaDB and PHP on Linux. A lot of them is outdated. Probably someday this one get out of date too… no wait! This one will be different, always fresh!

No matter what version of Debian you use, your Nginx, MariaDB and PHP (8.1) will be always up to date.

I will not argue my decision about such and no other configuration, I just like Nginx and MariaDB. Rather, I will focus on showing the configuration that will allow us to use the latest versions of each program. Most applications from the official repositories of a given distribution are not in the latest version. Of course, this is due to the desire to maintain stability. Personally, I use the solution described in this article and never complained about errors or instability. However, before you implement such a solution, or try to update an existing infrastructure, first make sure that everything goes smooth in the test environment. The fact that it works for me does not mean that it will also work for you :)

Install necessary packages:

Repositories. It’a all about repositories. Before you set up new repository for your server, you need to know what version of Debian you are using. The codename. To check codename use command below:

Example result of command:

As you now know the codename of your server you can use the codename name in the configuration below.

## Nginx

Edit your source.list for apt and add official Nginx repository. Use your favorite editor. Mine is nano.

change codename. Example for jessie:

Now you can update package list and install latest version of Nginx:

Clean Nginx from official repo is not tweaked as Debian prepared version called nginx-full. You will need to spend some time to configure it.

## PHP

Similar steps like above.

change codename.

Update package list and install PHP 8.1:

You may be interested in additional PHP packages:

Before you install latest MariaDB you need to check for repository on MariaDB repository page.

Go to page, choose your Linux Distribution, Release/Codename and then mirror.

Example results for Debian Buster:

You just need to run commands above, one by one.

Install required package:

Update package list and install MariaDB:

## Extra steps

### SSL

You may be interested to add free Let’s Encrypt certificate, to make communication with your web server secure. Check my guide how to do that: Let’s Encrypt SSL Cert for Nginx

### Nginx configuration

Sometimes after installation or restarting Nginx you can get error like this:

Fix it using this command:

### PHP FPM

If php-fpm (alternative for PHP FastCGI) is your favorite process manager for PHP, edit your website configuration:

and change line with fastcgi_pass parameter:

edit php.ini

change option cgi.fix_pathinfo

If you would like to check your PHP configuration, create info.php file in your www location:
http://example.com/info.php