Home
About
Blog
Media Gallery

Debian, NGINX and PHP-FPM


My notes for setting up NGINX and PHP, and a few extras, on Debian 9.


Installation (adjust as needed with extra/less stuff)
# apt-get update; apt-get upgrade
# apt-get install nginx php-fpm php-sqlite3 php-gd php-imagick php-curl python3-certbot-nginx

If you need to remove Apache/mod_php first (and letsencrypt/certbot if used)
# certbot delete (to remove/clean up existing certificates first.)
# apt-get remove certbot* php* Apache2*; apt-get purge certbot* php* Apache2*


Todo/Notes
Example settings:
pm = dynamic
pm.max_children = 25
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500


That's pretty much it. Below is an example configuration file for a website.

server {
	server_name example.com;
	root /home/www/public_www/example.com;
	index index.php index.html;

	location / {
		try_files $uri $uri/ =404;
		error_page 404  /missing.html;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
		(NOTE: Check /etc/php/<version>/fpm/pool.d/www.conf for correct path).
	}

	access_log /var/log/nginx/example.com.access.log;
	error_log /var/log/nginx/example.com.error.log;

	listen [::]:443 ssl ipv6only=on; # managed by Certbot
	listen 443 ssl; # managed by Certbot
	ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
	ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
	include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
	ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
	if ($host = example.com) {
		return 301 https://$host$request_uri;
	} # managed by Certbot
	listen 80;
	listen [::]:80;
	server_name example.com;
	return 404; # managed by Certbot
}


Original Post: Jan 28th, '22 15:31 CET.
Updated: Jan 28th, '22 15:33 CET.

Tags: GNU/Linux