How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Debian 8


Step 1: install nginx:

sudo apt-get update
sudo apt-get install nginx

Result:

root@v22017054614249197:~# sudo apt-get install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libxslt1.1 nginx-common nginx-full
Suggested packages:
  fcgiwrap nginx-doc
The following NEW packages will be installed:
  libxslt1.1 nginx nginx-common nginx-full
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 823 kB of archives.
After this operation, 1887 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ftp.de.debian.org/debian/ jessie/main libxslt1.1 amd64 1.1.28-2+deb
8u3 [232 kB]
Get:2 http://ftp.de.debian.org/debian/ jessie/main nginx-common all 1.6.2-5+deb8
u4 [88.1 kB]
Get:3 http://ftp.de.debian.org/debian/ jessie/main nginx-full amd64 1.6.2-5+deb8
u4 [430 kB]
Get:4 http://ftp.de.debian.org/debian/ jessie/main nginx all 1.6.2-5+deb8u4 [72.
6 kB]
Fetched 823 kB in 0s (4916 kB/s)
Preconfiguring packages ...
Selecting previously unselected package libxslt1.1:amd64.
(Reading database ... 34464 files and directories currently installed.)
Preparing to unpack .../libxslt1.1_1.1.28-2+deb8u3_amd64.deb ...
Unpacking libxslt1.1:amd64 (1.1.28-2+deb8u3) ...
Selecting previously unselected package nginx-common.
Preparing to unpack .../nginx-common_1.6.2-5+deb8u4_all.deb ...
Unpacking nginx-common (1.6.2-5+deb8u4) ...
Selecting previously unselected package nginx-full.
Preparing to unpack .../nginx-full_1.6.2-5+deb8u4_amd64.deb ...
Unpacking nginx-full (1.6.2-5+deb8u4) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.6.2-5+deb8u4_all.deb ...
Unpacking nginx (1.6.2-5+deb8u4) ...
Processing triggers for systemd (215-17+deb8u7) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libxslt1.1:amd64 (1.1.28-2+deb8u3) ...
Setting up nginx-common (1.6.2-5+deb8u4) ...
Setting up nginx-full (1.6.2-5+deb8u4) ...
Setting up nginx (1.6.2-5+deb8u4) ...
Processing triggers for libc-bin (2.19-18+deb8u9) ...
Processing triggers for systemd (215-17+deb8u7) ...

debian nginx install

Step 2: Install MySQL

sudo apt-get install mysql-server

Step 3: Install php-fpm and php5-mysql

sudo apt-get install php5-fpm php5-mysql

Result:

root@v22017054614249197:~# sudo apt-get install php5-fpm php5-mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
php5-mysql is already the newest version.
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapparmor1 php5-fpm
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 2273 kB of archives.
After this operation, 9275 kB of additional disk space will be used.
Get:1 http://ftp.de.debian.org/debian/ jessie/main libapparmor1 amd64 2.9.0-3 [6
0.3 kB]
Get:2 http://ftp.de.debian.org/debian/ jessie/main php5-fpm amd64 5.6.30+dfsg-0+
deb8u1 [2213 kB]
Fetched 2273 kB in 0s (14.4 MB/s)
Selecting previously unselected package libapparmor1:amd64.
(Reading database ... 34526 files and directories currently installed.)
Preparing to unpack .../libapparmor1_2.9.0-3_amd64.deb ...
Unpacking libapparmor1:amd64 (2.9.0-3) ...
Selecting previously unselected package php5-fpm.
Preparing to unpack .../php5-fpm_5.6.30+dfsg-0+deb8u1_amd64.deb ...
Unpacking php5-fpm (5.6.30+dfsg-0+deb8u1) ...
Processing triggers for systemd (215-17+deb8u7) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libapparmor1:amd64 (2.9.0-3) ...
Setting up php5-fpm (5.6.30+dfsg-0+deb8u1) ...

Creating config file /etc/php5/fpm/php.ini with new version
php5_invoke: Enable module opcache for fpm SAPI
php5_invoke: Enable module mysqli for fpm SAPI
php5_invoke: Enable module mysql for fpm SAPI
php5_invoke: Enable module gd for fpm SAPI
php5_invoke: Enable module readline for fpm SAPI
php5_invoke: Enable module json for fpm SAPI
php5_invoke: Enable module pdo_mysql for fpm SAPI
php5_invoke: Enable module pdo for fpm SAPI
php5_invoke: Enable module curl for fpm SAPI
php5_invoke: Enable module imap for fpm SAPI
Processing triggers for libc-bin (2.19-18+deb8u9) ...
Processing triggers for systemd (215-17+deb8u7) ...

Step 4: Edit file /etc/php5/fpm/php.ini
Find line

;cgi.fix_pathinfo=1

change to

cgi.fix_pathinfo=0

Step 5: Configure Nginx to use our PHP

Example we edit file /etc/nginx/sites-available/default

# Default server configuration
#
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/html;

	# Add index.php to the list if you are using PHP
	index index.php index.html index.htm index.nginx-debian.html;

	server_name localhost;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
	}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}
}

Done!

sudo service php5-fpm restart
sudo service nginx restart

Leave a Reply