Skip to content

Instantly share code, notes, and snippets.

@jpalala
Last active November 2, 2018 15:41
Show Gist options
  • Save jpalala/5116839c03a68826d43b1346427fefd0 to your computer and use it in GitHub Desktop.
Save jpalala/5116839c03a68826d43b1346427fefd0 to your computer and use it in GitHub Desktop.
lemp-setup on debian

from: https://tecadmin.net/install-php-debian-9-stretch/

  1. Update everything on the system:
  • sudo apt update && sudo apt upgrade
  1. Install some required apt stuff
  • sudo apt-get install apt-transport-https lsb-release ca-certificates
  1. Import gpg keys from sury.org
  • sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
  1. Add to the apt sources.list
  • echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
  1. Re update your system
  • sudo apt update
  1. You can now Install!!
  • sudo apt install -y php7.2 php7.2-cli php7.2-common php7.2-curl php7.2-mbstring php7.2-mysql php7.2-xml php7.2-fpm
  1. Install nginx and setup the apprpriate nginx config file
  • sudo apt install nginx
  1. laravel nginx config file:
server {
	listen 80;
	#listen [::]:80 default_server;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/public; ## todo check this

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

	server_name example.com;

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

	# pass PHP scripts to FastCGI server
	#
	#location ~ \.php$ {
	#	include snippets/fastcgi-php.conf;
	#
	#	# With php-fpm (or other unix sockets):
	#	fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
	#	# With php-cgi (or other tcp sockets):
	#	fastcgi_pass 127.0.0.1:9000;
	#}

location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock; ## todo: make sure to install php7.2-fpm!
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

	location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)$ {
      expires 1M;
      access_log off;
      add_header Cache-Control "public";
    }
location ~* \.(?:css|js)$ {
      expires 7d;
      access_log off;
      add_header Cache-Control "public";
    }
location ~ /\.ht {
        deny  all;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment