How to configure LEMP server on Debian 9 Stretch Linux -

The following text will describe a configuration procedure of LEMP server on Debian 9 Stretch Linux. The LEMP stack described by the below guide will consist of:
  • Debian 9 Stretch Linux
  • Nginx Web server
  • MariaDB or MySQL relational database
  • PHP 7 scripting language
Please be aware that our main objective is to configure bare bones LEMP stack on Debian 9 Stretch Linux. From this reason, no security hardening or performance fine-tuning recommendations are included in the article.

Once you have your bare bones, LEMP stack configured, consider a further hardening of your server based on the target deployment environment.

This is a companion discussion topic for the original entry at

Pierre Mitham

Something is wrong here. This command

apt-get install nginx mysql-server php-fpm php-mysql

installs mariadb instead of mysql!

add to that mysql workbench cannot connect to mariadb.

How do you get regular mysql installed?


why mysql login by root, for wordress getting error

Adi Ox

root@xxx:/home/debian# cgi-fcgi -bind -connect /run/php/php7.0-fpm.sock
bash: cgi-fcgi: command not found

FAILED tutorial.

Andrea Arteaga -> Adi Ox

Did you install the libfcgi0ldbl package as explained in the post?

Lubos Rendek Mod -> Adi Ox

Worked for me no problem! :slight_smile:

Randy H

The MySQL flavoured LEMP stack still installs MariaDB. Is there a way to NOT install this garbage?

In both Jessie and Stretch there is also a mariadb-server package which is a MariaDB-specific analog to the mysql-server package. In Jessie this package depends on mariadb-server-10.0 and in Stretch this package depends on mariadb-server-10.1 (the same as the default-mysql-server package).

So, the main repository difference in Debian 9 “Stretch” is that when you install the mysql-server package on Stretch you will get MariaDB 10.1 instead of MySQL, like you would with previous versions of Debian. Note that mysql-server is just an empty transitional meta-package and users are encouraged to install MariaDB using the actual package mariadb-server.

Update: This is a work around to NOT install maria-db:

# echo -e "deb stretch mysql-5.7\ndeb-src stretch mysql-5.7" > /etc/apt/sources.list.d/mysql.list

# wget -O /tmp/RPM-GPG-KEY-mysql
# apt-key add /tmp/RPM-GPG-KEY-mysql
# apt update
# apt install mysql-server

Lubos Rendek Mod → Randy H

your nginx default config is wrong:

this line:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

needs to be
fastcgi_pass unix:/run/php/php7.0-fpm.sock;

Otherwise it will just serve the php as a file and not execute.