Thoughts Improved

Some solemn thoughts, mild humor, and inklings of tech.

Getting Symfony 2 to run with Nginx

, ,

In my last project i made the decision to replace Apache with Nginx. Part of the reason was its a cheap and easy way to get scalability & performance; just install Nginx, configure the rewrites and you're ready to go. The other, and more important reason was, its fun.

So now i have decided to install Symfony 2 with Nginx and PHP FastCGI. Here's the conf file for the site :

server {
	listen 80;
	server_name symfony;
	root /path/to/symfony/web/dir;

	location ~* .(php|phtml) {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_param SCRIPT_FILENAME /path/to/symfony/web/dir$fastcgi_script_name;

		include /etc/nginx/fastcgi_params;
 	}
}



Add this code to your 'sites-enabled' dir, in a new file called 'symfony' (File name doesn't matter to nginx. Its just for you to know which site this is referring to). On my Ubuntu (10.10) system my file resides at :
/etc/nginx/sites-enabled/symfony

On Linux, add an entry for 'symfony' to the '/etc/hosts' file. Ex:
127.0.0.7       symfony


Restart nginx and you're good to go! Access the site at :
http://symfony/

Preferential BiasTHanks

Comments

Anonymous Wednesday, July 27, 2011 12:08:22 PM

Anonyme writes: hosts => 127.0.0.1 ;)

Anonymous Wednesday, August 10, 2011 12:26:26 PM

Anonymous writes: Thanks for sharing the config above! If you like, try the one at http://wiki.nginx.org/Symfony and tell me if it works for you... it has good security and supports pretty URLs.

Anonymous Wednesday, August 10, 2011 12:26:50 PM

Anonymous writes: Thanks for sharing the config above! If you like, try the one at http://wiki.nginx.org/Symfony and tell me if it works for you... it has good security and supports pretty URLs.