Skip to content

Instantly share code, notes, and snippets.

@DmitryMyadzelets
Created May 15, 2015 17:45
Show Gist options
  • Save DmitryMyadzelets/d2726fd49afad8a33f84 to your computer and use it in GitHub Desktop.
Save DmitryMyadzelets/d2726fd49afad8a33f84 to your computer and use it in GitHub Desktop.
Minimal setup of nginx and PHP locally

Minimal setup of nginx and PHP locally

nginx

Install and start nginx:

sudo apt-get update
sudo apt-get install nginx
sudo /etc/init.d/nginx start

Check it out:

http://localhost/

Or, if remotely, get you IP and check it out:

curl http://icanhazip.com

PHP

sudo apt-get install php5-fpm

Open file /etc/php5/fpm/php.ini, find and set:

cgi.fix_pathinfo=0

Save it, then apply changes by:

sudo service php5-fpm restart

Open file /etc/nginx/sites-available/default, find the server config

server {
		...
		root /usr/share/nginx/www;
		index index.html index.htm;

Add index.php:

		index index.php index.html index.htm;

Uncomment some lines related to PHP, and add fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;:

location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
#       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
#       # With php5-cgi alone:
#       fastcgi_pass 127.0.0.1:9000;
#       # With php5-fpm:
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
}

Save, and restart nginx:

sudo service nginx restart

Create a php file in the server's root with the content:

<?php
	phpinfo();
?>

Check the file looks correctly on your server, then delete it.

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