<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>i cant think &#187; setup</title>
	<atom:link href="http://wan.pengganas.net/tag/setup/feed/" rel="self" type="application/rss+xml" />
	<link>http://wan.pengganas.net</link>
	<description>a personal blog belong to mohammad azwan bin ali. you can find his writing about his life, thoughts , linux tips &#38; tricks, programming and many more</description>
	<lastBuildDate>Sat, 28 Aug 2010 22:04:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>ubuntu 9.10 nginx + php5</title>
		<link>http://wan.pengganas.net/entry/ubuntu-9-10-nginx-php5/</link>
		<comments>http://wan.pengganas.net/entry/ubuntu-9-10-nginx-php5/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 04:40:03 +0000</pubDate>
		<dc:creator>azwan ali</dc:creator>
				<category><![CDATA[tips & tricks]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://wan.pengganas.net/?p=587</guid>
		<description><![CDATA[a simple nginx + php5 web server setup 1. first we download all neccessary packages sudo apt-get install nginx php5-cgi php5-mysql spawn-fcgi 2. add php-fastcgi init script sudo nano /etc/init.d/php-fastcgi cut and paste this script #!/bin/bash FAST_CGI=&#34;/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php-cgi&#34; case &#34;$1&#34; in start&#41; $FAST_CGI ;; stop&#41; killall [...]]]></description>
			<content:encoded><![CDATA[<p>a simple nginx + php5 web server setup</p>
<p>1. first we download all neccessary packages<br />
<strong>sudo apt-get install nginx php5-cgi php5-mysql spawn-fcgi</strong></p>
<p>2. add php-fastcgi init script<br />
<strong>sudo nano /etc/init.d/php-fastcgi</strong><br />
cut and paste this script</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re3">#!/bin/bash</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re2">FAST_CGI=</span><span class="st0">&quot;/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php-cgi&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">case</span> <span class="st0">&quot;$1&quot;</span> <span class="kw1">in</span></div>
</li>
<li class="li1">
<div class="de1">start<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="re1">$FAST_CGI</span></div>
</li>
<li class="li1">
<div class="de1">;;</div>
</li>
<li class="li1">
<div class="de1">stop<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">killall</span> <span class="nu0">-9</span> php-cgi</div>
</li>
<li class="li1">
<div class="de1">;;</div>
</li>
<li class="li2">
<div class="de2">restart<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">killall</span> <span class="nu0">-9</span> php-cgi</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">sleep</span> <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$FAST_CGI</span></div>
</li>
<li class="li1">
<div class="de1">;;</div>
</li>
<li class="li2">
<div class="de2">*<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;Usage: php-fastcgi {start|stop|restart}&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">exit</span> <span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">;;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">esac</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw3">exit</span> <span class="nu0">0</span>;</div>
</li>
</ol>
</div>
<p>3. configuring nginx to enable php. not that in this how-to i'm going to use /var/www/ as default web server directory<br />
<strong>sudo nano /etc/nginx/sites-enabled/default</strong><br />
<span id="more-587"></span><br />
modify root directory to /var/www and insert index.php as default index page</p>
<pre>
root   /var/www/;
location / {
               index  index.php index.html index.htm;
}
</pre>
<p>enable php support throught php-fastcgi</p>
<pre>
location ~ \.php$ {
                #check if php file exist before passing to php fastcgi
                if (!-e $document_root/$document_uri) { return 404;break; }
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include /etc/nginx/fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
</pre>
<p>since we are using same default directory as apache, you need to  comment out this line too</p>
<pre>
location ~ /\.ht {
deny  all;
}
</pre>
<p>save your file</p>
<p>4. testing your server<br />
write &lt;?php phpinfo(); ?&gt; into /var/www/phpinfo.php<br />
restart nginx and php-fastcgi service<br />
<strong>/etc/init.d/nginx restart</strong><br />
<strong>/etc/init.d/php-fastcgi restart</strong></p>
<p>browser to http://localhost/phpinfo.php and you should see a phpinfo page</p>
<p>5. addtional note<br />
if you're lazy to type 2 command everytime you want start/stop nginx + php service your can edit your <strong>/etc/init.d/nginx</strong> script by embedding <strong>/etc/init.d/php-fastcgi</strong> command inside it. just make sure you know what are you doing.<br />
if you have phpmyadmin installed from package you can simply link it to nginx by creating a symlink</p>
<p><strong>sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin</strong></p>
<p>don't forget to read how to use rewrite rule at http://nginx.org/en/docs/http/converting_rewrite_rules.html</p>
<p>good luck <img src='http://wan.pengganas.net/smilies/biggrin.gif' alt='&#58;&#68;' class='wp-smiley' title='&#58;&#68;' /></p>
]]></content:encoded>
			<wfw:commentRss>http://wan.pengganas.net/entry/ubuntu-9-10-nginx-php5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
