<?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>iamtgc &#187; PHP</title>
	<atom:link href="http://iamtgc.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://iamtgc.com</link>
	<description></description>
	<lastBuildDate>Wed, 21 Jul 2010 12:13:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Running a FastCGI Application Server with a Lighttpd Front&#160;End</title>
		<link>http://iamtgc.com/2008/12/18/running-a-fastcgi-application-server-with-a-lighttpd-front-end/</link>
		<comments>http://iamtgc.com/2008/12/18/running-a-fastcgi-application-server-with-a-lighttpd-front-end/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 04:17:11 +0000</pubDate>
		<dc:creator>tgc</dc:creator>
				<category><![CDATA[Lighttpd]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://iamtgc.com/?p=63</guid>
		<description><![CDATA[Running a FastCGI Application Server separately from the Web Server has been an increasingly popular topic. The FastCGI Wikipedia Article states some of the reasons for it - &#8220;This separation allows server and application processes to be restarted independently — an important consideration for busy web sites. It also facilitates per-application security policies — important [...]]]></description>
			<content:encoded><![CDATA[<p>Running a FastCGI Application Server separately from the Web Server has been an increasingly popular topic.  The <a href="http://en.wikipedia.org/wiki/FastCGI">FastCGI Wikipedia Article</a> states some of the reasons for it -</p>
<blockquote><p>&#8220;This separation allows server and application processes to be restarted independently — an important consideration for busy web sites. It also facilitates per-application security policies — important for ISPs and web hosting companies.&#8221;</p></blockquote>
<p>The <a href="http://www.lighttpd.net">lighttpd</a> web server includes the binary spawn-fcgi, which as the name suggests, allows you to spawn FastCGI processes.  This can be done independently of the web server processes.<br />
<span id="more-63"></span><br />
Lighttpd&#8217;s FastCGI module, mod_fastcgi is well documented <a href="http://redmine.lighttpd.net/wiki/1/Docs:ModFastCGI">here</a>, but there are a lot of arguments to sift through and it can be a process of trial and error to get a working configuration.</p>
<p>In this example, we will review how to configure lighttpd and spawn-fcgi on separate servers.  The web server which will run lighttpd and host all html, images, css, etc. files.  The FastCGI server will host all PHP files.</p>
<p>Here is the relevant excerpt from lighttpd.conf on <strong>Server A:</strong> <em>(the server hosting the html, images, css, etc)</em><br />
<code>server.modules = (
                          [ ... ]
                          "mod_fastcgi",
                          [ ... ]
                        )
[ ... ]
$HTTP["host"] =~ "(^|\.)iamtgc\.com$" {
   server.name = "iamtgc.com"
   server.document-root = "/lighttpd/" + server.name
   fastcgi.server         =  ( ".php" =&gt;
                               ((
                                   "host" =&gt; "192.168.25.120",
                                   "port" =&gt; 9999,
                                   "docroot" =&gt; "/php/iamtgc.com",
                                   "check-local" =&gt; "disable"
                               ))
                             )
   accesslog.filename = "/var/log/lighttpd/" + server.name + "-access.log"
}
[ ... ]</code></p>
<p>On <strong>Server B</strong> <em>(where the FastCGI processes are running)</em> you start the FastCGI server like this:<br />
<code># spawn-fcgi -f /usr/local/bin/php-cgi -a 192.168.25.120 -p 9999</code></p>
<p>Note, the php needs to exist in the <strong>docroot</strong> reference above, in this case /php/iamtgc.com.  The bind address (<strong>-a</strong>) and port (<strong>-p</strong>) also correspond to the <strong>host</strong> and <strong>port</strong> variables referenced in lighttpd.conf on Server A.</p>
<p>Also note, php-cgi can be replaced with something like dispatch.fcgi in the case of <a href="http://rubyonrails.org/">Ruby on Rails</a> or a similar fcgi file for <a href="http://www.djangoproject.com/">Django</a> as seen <a href="http://iamtgc.com/2007/07/04/django-on-lighttpd-with-fastcgi/">here</a>.  In both of these cases, other changes would be also required to Server A&#8217;s lighttpd.conf.</p>
]]></content:encoded>
			<wfw:commentRss>http://iamtgc.com/2008/12/18/running-a-fastcgi-application-server-with-a-lighttpd-front-end/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
