<?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>IT Know-It-All &#187; mod_fcgid</title>
	<atom:link href="http://itkia.com/tag/mod_fcgid/feed/" rel="self" type="application/rss+xml" />
	<link>http://itkia.com</link>
	<description>Applications, OS, Networking, Data</description>
	<lastBuildDate>Mon, 02 Apr 2012 15:00:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Ubuntu Lucid and mod_fcgid Upload Corruption</title>
		<link>http://itkia.com/ubuntu-lucid-and-mod_fcgid-upload-corruption/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ubuntu-lucid-and-mod_fcgid-upload-corruption</link>
		<comments>http://itkia.com/ubuntu-lucid-and-mod_fcgid-upload-corruption/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 07:44:46 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mod_fcgid]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=274</guid>
		<description><![CDATA[Ubuntu Lucid 10.04 LTS and I just aren&#8217;t getting along well so far. In past Linux upgrades I was able to keep my data and config files (after checking config files against new versions for any major changes), and the &#8230; <a href="http://itkia.com/ubuntu-lucid-and-mod_fcgid-upload-corruption/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ubuntu Lucid 10.04 LTS and I just aren&#8217;t getting along well so far. In past Linux upgrades I was able to keep my data and config files (after checking config files against new versions for any major changes), and the upgraded system and applications behaved the same way. This hasn&#8217;t been the case for <a href="http://itkia.com/upgrade-hell/">my Lucid LTS upgrade</a>.</p>
<p>I have mod_fcgid for my PHP sites, and after my Lucid upgrade I noticed that PHP uploads such as images, photos and documents were being corrupted quite frequently, and it was happening on both WordPress and Simple Machines Forum (SMF). I spent a lot of time troubleshooting it to no avail. I was about to give up and either roll back to Hardy LTS or put PHP on Windows and run my sites there when I stumbled across this bug report: <a href="https://bugs.launchpad.net/ubuntu/+source/libapache2-mod-fcgid/+bug/573591">Uploads greater than 64 kilobytes corrupted when using Apache mod_fcgid</a></p>
<p>Lucid LTS&#8217;s mod_fcgid has this bug, and to automatically get the patch you have to have security.ubuntu.com in your /etc/apt/sources.list, for example:</p>
<blockquote><p>deb http://security.ubuntu.com/ubuntu lucid-security universe</p></blockquote>
<p>Then run updates and upgrades.</p>
<p>I suppose it&#8217;s partially my fault for not having security there in the first place, but I thought the security patches would eventually show up on the distribution mirrors. Apparently not yet. And also this seems more like a bug fix than a security issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/ubuntu-lucid-and-mod_fcgid-upload-corruption/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrade Hell</title>
		<link>http://itkia.com/upgrade-hell/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=upgrade-hell</link>
		<comments>http://itkia.com/upgrade-hell/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 18:18:16 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mod_fcgid]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=257</guid>
		<description><![CDATA[I&#8217;ve had an eventful couple of months revolving around wanting to move this web server from a hosted VPS to my home and both the old and new environments running into upgrade troubles. The hosted VPS was an old stable &#8230; <a href="http://itkia.com/upgrade-hell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had an eventful couple of months revolving around wanting to move this web server from a hosted VPS to my home and both the old and new environments running into upgrade troubles.</p>
<p>The hosted VPS was an old stable Debian version running under Virtuozzo with a 2.4 kernel. For years it has been running flawlessly. During a recent upgrade it started installing a new glibc and other programs relying on a 2.6 kernel. I guess my old Debian stable went out of support, but I&#8217;m surprised it tried going 2.6. Of course I have no control over the kernel, so I was in a bad spot. The critical services were still running, so I kept them running. (I am pretty sure most services would fail upon restart.) I had some problems with mismatched libraries failing, but overall the web server, DNS servers and sites kept running. Since I was planning on migrating to my home server anyway, I decided to keep it limping along while I prepared my home server environment.</p>
<p>My home environment was a Hardy 8.04 LTS Ubuntu server running OpenVZ containers. This has been stable for at least a couple of years, but in anticipation of moving my web server into a container there I decided to upgrade to Lucid 10.04 LTS. My mistake was not previewing major changes that would affect me. Each one probably deserves its own blog, so I&#8217;ll summarize here for now.</p>
<p>OpenVZ deprecated, <a href="https://help.ubuntu.com/community/LXC">LXC </a>is the new paravirtualization component. Good news: it&#8217;s in the main kernel tree. Bad news: it&#8217;s different enough from OpenVZ to introduce a new learning curve, and the documentation and support tools are immature as of mid-2011.</p>
<p>mod_fcgid behaves differently: On my small VPS I had apache and mod_fcgid configured for optimal efficiency in a small RAM footprint, but the same configuration options caused failures on the new mod_fcgid. The short story is that <a href="http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html">mod_fcgid became an Apache project</a> in 2009, and they&#8217;ve made some changes. They&#8217;re actually decent changes, but they don&#8217;t work with my old config options when trying to minimize process count and RAM usage. mod_fcgid will now by default avoid closing the first three processes for <strong>each </strong>class, &#8220;class&#8221; being defined in my case as the php file called in the URL. Since RAM is not an issue on the home server I removed my process count constraints, but I intend to toy with the settings until I can get it like I used to have it: one to four php_cgi processes handling all php requests.</p>
<p>SysV init -&gt; Upstart init: Lucid init is a hybrid between the new Upstart init and the old Sys V init. In many ways I like this, and when installing Ubuntu packages this wouldn&#8217;t really be an issue, but inside the LXC containers it has thrown me for a few loops because Upstart keys on events that may not happen inside a container the same way they do on the host. The good news is that in-container init scripts and service starts that key on filesystem mounting and network interface availability can be changed to &#8220;start on startup&#8221; since you can assume a container will have its filesystem and network set up before the init system is called. In particular you might want to be sure that /etc/init/rc-sysinit.conf is changed to &#8220;start on startup&#8221; inside LXC containers, and I had to do the same for /etc/init/mysql.conf .</p>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/upgrade-hell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Externally Spawned FastCGI for Apache a Pain</title>
		<link>http://itkia.com/externally-spawned-fastcgi-for-apache-a-pain/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=externally-spawned-fastcgi-for-apache-a-pain</link>
		<comments>http://itkia.com/externally-spawned-fastcgi-for-apache-a-pain/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 02:10:29 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_fastcgi]]></category>
		<category><![CDATA[mod_fcgid]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=62</guid>
		<description><![CDATA[Apache mod_fastcgi can use an external fastcgi server, but mingled code and content is problematic. <a href="http://itkia.com/externally-spawned-fastcgi-for-apache-a-pain/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>I haven&#8217;t yet converted my real web server from Apache/mod_fcgid to Apache/mod_fastgi with an externally spawned FastCGI process. It is doable and works fine, but it is a pain to configure it how I want it to work.</p>
<p>I&#8217;m not sure I can blame Apache or FastCGI. It actually makes sense how they are doing it. However, I tend to install PHP software packages like Drupal, Simple Machines Forum, Mambo/Joomla, Gallery2, WordPress and so forth. Generally these applications are built with Apache/mod_php in mind and take some tweaking to make work on other setups. But I don&#8217;t want to tweak, especially if I have to do it periodically when upgrading.</p>
<p>I switched from lighttpd/ModFastCGI to Apache/mod_php/Squid because I was tired of fiddling with lighttpd rewrites to make pretty urls for Drupal and SMF which include ready-made Apache pretty rewrite rules.</p>
<p>Apache/mod_fcgid has worked pretty well so far, and with the AddHandler directive it behaves like mod_php: Any .php files under the document root will be parsed by the PHP interpreter. The downside is that any caching&#8211;like APC&#8211;is not shared across the PHP processes.</p>
<p>So I wanted to spawn my own PHP FastCGI process with several child processes sharing a cache like I did with lighttpd and then have Apache use it. That works, but the mod_fastcgi FastCgiExternalServer directive behaves much like a ScriptAlias directive: if you specify a folder, anything under that folder will be processed by the FastCGI server, so you can&#8217;t easily mix static files with PHP script files. I tried hacking my way around this with various combinations of symlinks, aliases, handlers and rewrites, and I even got a couple of the combinations to work, but I would have to make changes to each Apache virtual host (or enforce a strict naming scheme for my vhosts), and if I missed something it would be too easy to accidentally serve up the source of a .php file.</p>
<p>Now if I were making an application from scratch it would be fine to put the PHP files in a script folder and the static files elsewhere, and I could alter premade software like that with rather simple aliases, but I would have to do it for every installed instance and then re-tweak every time I updated the software. No thanks.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/externally-spawned-fastcgi-for-apache-a-pain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>External FastCGI With Apache</title>
		<link>http://itkia.com/external-fastcgi-with-apache/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=external-fastcgi-with-apache</link>
		<comments>http://itkia.com/external-fastcgi-with-apache/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 13:52:37 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_fastcgi]]></category>
		<category><![CDATA[mod_fcgid]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=59</guid>
		<description><![CDATA[Example of Apache mod_fastcgi connecting to external server using FastCgiExternalServer directive. <a href="http://itkia.com/external-fastcgi-with-apache/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>I was able to spawn a separate PHP FastCGI server with children and have Apache connect to it. It was trickier than I thought. The big benefit is that one shared APC cache can serve all the PHP child processes and being able to use a multithreaded Apache without worrying about whether my PHP dependencies are thread safe.</p>
<p>The trick isn&#8217;t getting it working, but getting it working the way I wanted. I want &#8220;.php&#8221; files to be processed by the FastCGI server and have the other files sent by Apache. Without some tricky configuration, Apache&#8217;s mod_fastcgi can only send specified file requests or specified directories&#8211;plus all their contents&#8211;to the external FastCGI server.</p>
<p>But I am getting ahead of myself. Let me back up to my old lighttpd setup: I had lighttpd installed, and a script that launced several php-cgi processes and listened on a network socket. Lighttpd would connect to the php-cgi processes and let them handle PHP processing. Apache can do this, too, but it was hard for me to easily find out how online.</p>
<p>As it turns out, the <a href="http://redmine.lighttpd.net/projects/spawn-fcgi">spawn-fcgi</a> program from lighttpd that I used to start the FastCGI server is now a project on its own. Supposedly the mod_fastcgi developers have a launcher program, too, but I couldn&#8217;t easily find it, and I was already familiar with spawn-fcgi and was happy to see it&#8217;s being maintained. I downloaded the source package from the site, extracted it and then did the usual &#8220;./compile&#8221;, &#8220;make&#8221; and &#8220;sudo make install&#8221;. So now I have /usr/local/bin/spawn-fcgi installed.</p>
<p>There is some good info on <a href="http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModFastCGI">lighttpd&#8217;s ModFastCGI documentation site</a> on launching a PHP server with spawn-fcgi and various helper scripts. I modified one slightly to make it use a unix socket instead of a network tcp socket:</p>
<pre>#!/bin/bash

## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/usr/local/bin/spawn-fcgi"

## ABSOLUTE path to the PHP binary
FCGIPROGRAM="/usr/bin/php-cgi"

## TCP port to which to bind on localhost
FCGIPORT="1026"

## bind to unix domain socket
FCGISOCKET="/tmp/php.sock"

## number of PHP children to spawn
PHP_FCGI_CHILDREN=4

## maximum number of requests a single PHP process can serve before it is restarted
PHP_FCGI_MAX_REQUESTS=1000

## IP addresses from which PHP should access server connections
FCGI_WEB_SERVER_ADDRS="127.0.0.1"

# allowed environment variables, separated by spaces
ALLOWED_ENV="ORACLE_HOME PATH USER"

## if this script is run as root, switch to the following user
USERID=www-data
GROUPID=www-data

################## no config below this line

if test x$PHP_FCGI_CHILDREN = x; then
  PHP_FCGI_CHILDREN=5
fi

export PHP_FCGI_MAX_REQUESTS
export FCGI_WEB_SERVER_ADDRS

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"

### This if-then-else is for opening a network TCP port
#if test x$UID = x0; then
#  EX="$SPAWNFCGI -n -p $FCGIPORT -f $FCGIPROGRAM -u $USERID -g $GROUPID -C $PHP_FCGI_CHILDREN"
#else
#  EX="$SPAWNFCGI -n -p $FCGIPORT -f $FCGIPROGRAM -C $PHP_FCGI_CHILDREN"
#fi

### This if-then-else is for opening a unix socket
if test x$UID = x0; then
  EX="$SPAWNFCGI -n -s $FCGISOCKET -f $FCGIPROGRAM -u $USERID -g $GROUPID -C $PHP_FCGI_CHILDREN"
else
  EX="$SPAWNFCGI -n -s $FCGISOCKET -f $FCGIPROGRAM -C $PHP_FCGI_CHILDREN"
fi

# copy the allowed environment variables
E=

for i in $ALLOWED_ENV; do
  E="$E $i=${!i}"
done

# clean the environment and set up a new one
exec env - $E $EX</pre>
<p>In the above script I had to use /bin/bash instead of Ubuntu&#8217;s default /bin/sh as it uses some of bash&#8217;s features. Also note that with spawn-fcgi you can have a network tcp socket or a unix socket, but not both. On my test server I just simply ran the above script as root; it won&#8217;t restart itself if the VPS is restarted or if the script crashes. I have daemontools on my real server, and I&#8217;ll use that to start and monitor the launcher script. The link to lighttpd&#8217;s site has other startup scripts worht looking at.</p>
<p>You can&#8217;t use mod_fcgid to connect to the externally spawned FastCGI process. It can only launch and manage the processes itself. So I loaded mod_fastcgi and used the FastCgiExternalServer directive:</p>
<pre>&lt;IfModule mod_fastcgi.c&gt;
  FastCgiExternalServer /srv/www/site/fcgi -socket /tmp/php.sock
&lt;/IfModule&gt;</pre>
<p>That tells Apache that any request under the /srv/www/site/fcgi directory gets passed to the FastCGI process with a unix socket at /tmp/php.sock. Unfortunately there is not an simple configuration to have it just run php files, and the FastCGI server may not know what to do with static files like pictures or .css files.</p>
<p>There is a good <a href="http://whocares.de/fastcgiexternalserver-demystified/all/1/">article explaining the FastCgiExternalServer directive</a>. Its solution to having just the .php files be handled by the external server involve adding a handler, assigning an action to the handler pointing to a nonexistent script and then aliasing the nonexistent script back to a folder symlinked to the original directory. The only way I could find to simplify that was to use a ReWriteRule. In either case we need to unfortunately modify the configuration for each vhost to make it work.</p>
<p>I have several vhosts under /srv/www/. Following the articles example I created a symlink /srv/fcgi pointing to /srv/www . Then I modified my mod_fastcgi configuration as such:</p>
<pre>&lt;IfModule mod_fastcgi.c&gt;
  FastCgiExternalServer /srv/fcgi -socket /tmp/php.sock
  ReWriteEngine On
  ReWriteCond %{DOCUMENT_ROOT} ^/srv/www/(.*)
  ReWriteRule ^/(.*\.php(3|4)?(\?.*)?)$ /srv/fcgi/%1/$1
&lt;/IfModule&gt;</pre>
<p>Now the external FastCGI server is invoked whenever a file under /srv/fcgi is accessed, but /srv/fcgi is just a symlink to /srv/www. Instead of the above article&#8217;s gyrations I figured out the above rewrite rules that will rewrite any request for a .php file to /srv/fcgi/(rest-of-document-root)/(request_URL) . So in effect the rewrite points back to the original file, but through a symlink that makes Apache use the FastCGI server to process it. The ReWriteCond shown doesn&#8217;t actually make a decision; it is giving me a reference to use when constructing my rewritten path name.</p>
<p>Now I have to modify my vhosts. Rewrite rules don&#8217;t carry over to vhosts by default. For each VirtualHost section I have to add the following which allows the server rewrite rules inherit to the vhost:</p>
<pre>ReWriteEngine On
ReWriteOptions Inherit</pre>
<p>Alternately I could just put the rewrite rules in each VirtualHost section. In fact I may need to if I have other rewrite rules for pretty URLs.</p>
<p>With FastCGI&#8211;whether externally spawned or managed by mod_fcgid or mod_fastcgi&#8211;you also need ExecCGI enabled in the Options directive.</p>
<p>I used Apache benchmark and verified that all the child proceses are being used concurrently. And now the APC cache is shared among all the child processes.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/external-fastcgi-with-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multithreaded Apache In Small VPS</title>
		<link>http://itkia.com/multithreaded-apache-in-small-vps/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=multithreaded-apache-in-small-vps</link>
		<comments>http://itkia.com/multithreaded-apache-in-small-vps/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 22:48:39 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_fcgid]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=57</guid>
		<description><![CDATA[My detailed report configuring multithreaded Apache mod_fcgid for PHP with limited resources. <a href="http://itkia.com/multithreaded-apache-in-small-vps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p><strong>July 2011 Note: mod_fcgid has changed its behavior in opening and closing processes since I wrote this article. <a href="http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html">mod_fcgid is now an Apache project</a>, and limiting it to 4 processes with the configuration I have below caused me problems when I migrated to a server with the newer mod_fcgid. mod_fcgid now opens a new process for each &#8220;class&#8221; which for our php purposes means each .php file location requested by a URL, and it tries to keep 3 processes open for each class by default. Since I limited the max processes to 4, it will not close enough idle processes to allow new classes to open processes, and the pages fail. I think this may be fixable with settings, but I had other upgrade frustrations during the migration and am not now constrained by a small VPS, so I haven&#8217;t yet been motivated to figure out how to get the newer mod_fcgid to operate well in a small VPS.</strong></p>
<p>My best-performing small VPS setup was with lighttpd and FastCGI PHP, but I got tired of trying to make rewrites work in lighttpd and switched to a two-process prefork Apache with mod_php and Squid as a web accelerator. That worked pretty well, but not as fast as lighttpd and FastCGI. What I really want is a multithreaded Apache and a FastCGI PHP that will fit in my small, cheap VPS.</p>
<p>I had tried Apache&#8217;s worker MPM and FastCGI before, but at the time both Apache and the PHP FastCGI process bloated and took up all my RAM despite my settings. Recently I decided to try again and was able to find out how to make it work.</p>
<p>Under Linux, by default each thread is assigned 8MB of stack memory, so an Apache process with 25 threads would try to take up 25*8=200MB of RAM!!! Plus the size of the Apache parent process, plus anything else that runs on my VPS. Not going to work in my small VPS. However, each thread doesn&#8217;t really need that much RAM. In fact, 128k is working fine for me so far. Apache 2.2 has a new directive ThreadStackSize for the worker MPM, and I set mine to &#8220;ThreadStackSize 131072&#8243;, and now I can have two Apache processes with 25 threads each taking up about 25MB worth of privvmpages. Another way to accomplish this is add &#8220;ulimit -s 128&#8243; to the Apache startup scripts. For Apache 2.0 you have to do it this way. Since I am using Apache 2.2 I didn&#8217;t have to use ulimit, but when I was testing the effects of changing the stack size I used this script which worked as a temporary measure:</p>
<pre>#!/bin/sh

ulimit -s 128
/usr/sbin/invoke-rc.d apache2 restart</pre>
<p>My 25 MB RAM usage above is without mod_php, though. Google searches lead to conflicting information about whether PHP is thread safe, so I want to use FastCGI. My problem with Apache FastCGI before was that it spawned several times as many PHP processes as I thought I had told it to. I was using mod_fcgid and pointing it to the same FastCGI PHP wrapper script that I had used for lighttpd. But that script set PHP to launch child processes, and I have since learned that mod_fcgid does not multiplex and therefore will not use the child processes. Instead it launches as many processes as it sees fit, and my configuration had each of those launching 4 children. No wonder my RAM got chewed up so quickly. So now I am letting mod_fcgid call /usr/bin/php-cgi directly:</p>
<pre>&lt;IfModule mod_fcgid.c&gt;
        AddHandler fcgid-script .fcgi .php
        # Where to look for the php.ini file?
        DefaultInitEnv PHPRC        "/etc/php5/cgi"
        # Maximum requests a process should handle before it is terminated
        MaxRequestsPerProcess       1000
        # Maximum number of PHP processes
        MaxProcessCount             4
        # Number of seconds of idle time before a php-cgi process is terminated
        IPCCommTimeout              120
        IdleTimeout                 120
        #Or use this if you use the file above
        FCGIWrapper /usr/bin/php-cgi .php
&lt;/IfModule&gt;</pre>
<p>Unfortunately, since each PHP processes is launched separately, any caching such as eAccelerator or APC will not be shared across each process. And each process uses up another X MB of RAM for the cache. So if I&#8217;m using APC with the default 30 MB cache and have 4 FastCGI PHP processes going, my APC caches are taking up 120 MB all by themselves! At the moment this is exactly what I&#8217;m doing, because I&#8217;ve moved up from a 256 MB VPS to a 390 MB VPS, and my total memory usage seems to be hovering near 256 MB when all processes are running. However, when PHP processes aren&#8217;t needed, mod_fcgid will kill them off to save memory, so most of the time I&#8217;m using much less RAM. I will see if I can set up the FastCGI processes like I did with lighttpd and then connect to it from Apache. I think it&#8217;s doable, but I haven&#8217;t tried yet.</p>
<p>I like using the worker MPM and FastCGI better than using the prefork MPM, mod_php and Squid. First of all the log files are a lot easier to parse. Apache (as I have it configured) can handle 50 concurrent static requests including 4 concurrent PHP requests, and I was able to enable KeepAlives again so my sites feel more responsive. With prefork Apache and Squid I could see a row of GIF smileys load up left-to-right when posting a reply in one of my forums. Now it happens so fast I can&#8217;t see it anymore. If I can get the PHP cache&#8211;previously eAccelerator, but I just switched to APC&#8211;to share itself across all my PHP processes then the overal RAM usage will be much lower, and I&#8217;ll be able to have more PHP processes.</p>
<p>And I like the new setup better than lighttpd because I can use the Apache rewrite rules provided by software programs like Drupal and SMF rather than try to translate them into lighttpd rewrites.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/multithreaded-apache-in-small-vps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

