<?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; Linux</title>
	<atom:link href="http://itkia.com/category/linux/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>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>
		<item>
		<title>Using Squid To Cache Apt Updates For Debian And Ubuntu</title>
		<link>http://itkia.com/using-squid-to-cache-apt-updates-for-debian-and-ubuntu/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-squid-to-cache-apt-updates-for-debian-and-ubuntu</link>
		<comments>http://itkia.com/using-squid-to-cache-apt-updates-for-debian-and-ubuntu/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 22:20:44 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=55</guid>
		<description><![CDATA[My detailed experience successfully configuring Squid to cache apt updates <a href="http://itkia.com/using-squid-to-cache-apt-updates-for-debian-and-ubuntu/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>I run several Debian-based Linux machines and virtual machines at home and periodically install or reinstall one to test something. They all need updates—and mostly the same updates—so I wanted to cache the updates locally rather than download them several times when I upgrade.</p>
<p>There is an apt-proxy package, and although I can&#8217;t recall the problems with it I remember deciding it was not going to work well for me. I could rsync the entire package archive, but that&#8217;s just wasteful. I finally decided on setting up a <a href="http://www.squid-cache.org/">Squid proxy</a> dedicated—by intent, not controls—to caching deb packages from Debian and Ubuntu archives. And rpm&#8217;s and such if I should use other distro&#8217;s.</p>
<p>So I set up Squid and looked through the configuration options. Squid is by default set up to be most efficient at getting cache hits. I wanted to be sure it doesn&#8217;t expire the seldom-accessed large deb files to make room for tiny files, so I changed the <a href="http://www.squid-cache.org/Doc/config/cache_replacement_policy/">cache replacement policy</a> to LFUDA to optimize byte hit rate. I also increased the <a href="http://www.squid-cache.org/Doc/config/maximum_object_size/">maximum object size</a> to 100 megabytes from the default 4096 kilobytes. In a typical Squid cache the larger files aren&#8217;t cached because they often aren&#8217;t requested as often as smaller files by web surfers, however my cache&#8217;s purpose is to save these large files locally for updating several machines.</p>
<p>Now I needed to make my machines use the proxy for apt. For that I just added a code snippet to each /etc/apt/apt.conf, or in my cases I just slipped this file named jimproxy into /etc/apt/apt.conf.d/ :</p>
<pre>Acquire {
        Retries "0";
        HTTP {
                Proxy "http://address-or-URL-of-squid-proxy.example.tld:3128/";
        };
};</pre>
<p>Now when I run apt or aptitude or any manager that uses apt, they will use my Squid proxy to obtain the distribution packages.</p>
<p>This worked quite well, but I recently noticed some problems. The issue appeared to be that there were missing deb files from the archives, but what really was happening was that new Package.bz2 lists were on the archives, but my Squid cache was serving older lists it had cached. It listed some older packages which were no longer there. So my &#8220;apt-get update&#8221; would read an old package list and then &#8220;apt-get -u upgrade&#8221; wouldn&#8217;t find those older packages. So I need to tell Squid to be sure to check for new package lists. To do that I changed the <a href="http://www.squid-cache.org/Doc/config/refresh_pattern/">refresh pattern</a> option for &#8220;refresh-ims&#8221;. Voilà, it works properly now.</p>
<p>Squid.conf lines before:</p>
<pre># maximum_object_size 4096 KB
# cache_replacement_policy lru
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern .               0       20%     4320</pre>
<p>Squid.conf lines after:</p>
<pre>maximum_object_size 100 MB
cache_replacement_policy heap LFUDA
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern .               0       20%     4320 refresh-ims</pre>
<p>I turned on refresh-ims for everything, but I probably would have been fine with turning it on for just the frequently-changing files as shown in the following code. But in my case I don&#8217;t think turning it on for all files will adversely affect things.</p>
<pre>maximum_object_size 100 MB
cache_replacement_policy heap LFUDA
refresh_pattern ^ftp:          1440    20%     10080
refresh_pattern ^gopher:       1440    0%      1440
refresh_pattern Packages\.bz2$ 0       20%     4320 refresh-ims
refresh_pattern Sources\.bz2$  0       20%     4320 refresh-ims
refresh_pattern Release\.gpg$  0       20%     4320 refresh-ims
refresh_pattern Release$       0       20%     4320 refresh-ims
refresh_pattern .              0       20%     4320</pre>
</div>
<p>You may also be interested in <a href="http://itkia.com/2008-update-on-running-drupal-on-a-small-vps/">using Squid in web accelerator mode in a small VPS</a> to boost performance.</p>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/using-squid-to-cache-apt-updates-for-debian-and-ubuntu/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>2008 Update on Running Drupal on a Small VPS</title>
		<link>http://itkia.com/2008-update-on-running-drupal-on-a-small-vps/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=2008-update-on-running-drupal-on-a-small-vps</link>
		<comments>http://itkia.com/2008-update-on-running-drupal-on-a-small-vps/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 22:26:05 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=53</guid>
		<description><![CDATA[Using Squid as a web accelerator to improve Apache mod_php efficiency with limited resources. <a href="http://itkia.com/2008-update-on-running-drupal-on-a-small-vps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>For a year or two I was successfully running Drupal with lighttpd and fastcgi. Lighttpd is very efficient, and having 4 fastcgi PHP processes let me limit the memory php used while keeping my small sites responsive enough. But redirects and URL rewriting are done differently, and it was tricky at times to get it to work the way I wanted with Drupal. I eventually got tired of wrestling with rewrites and redirects with every new non-Drupal php-based app I wanted to try, so I started thinking about how to make Apache work for a small site.</p>
<p>Now I am running Apache2/mod_php with a <a href="http://www.squid-cache.org/">Squid</a> front-end cache. If you&#8217;re not familiar with Squid, in brief it is a web proxy that caches web requests. It is often used to speed up clients but can be reversed to cache requests on the server end in web accelerator mode. Apache uses more RAM than lighttpd/fastcgi, and Squid uses RAM for itself and the cache, so I had to cut back two 2 Apache processes.</p>
<p>That may sound like too little, but here&#8217;s how it works well: the threads aren&#8217;t stuck delivering a request to a slow remote client because the local Squid cache accepts the request locally and then delivers it to the client freeing up the Apache process to handle the next request. 2 processes can handle my traffic because they can quickly deliver their payload to the cache and move on, and Squid can handle the delivery over the network to the client.</p>
<p>Of course sometimes the processes get hung up on slow MySQL queries or slow PHP queries, so occasionally I had delays. In particular I got rid of my RSS requests, because the Apache process had to wait while requesting RSS feeds from other sites, and sometimes that got slow or even timed out leaving just one Apache process handling requests, and if it stumbled on something then I&#8217;d have client requests waiting in line not getting served. So I got rid of my news feeds. Note that I am talking about my web site pulling feeds from other sites; of course I can offer RSS feeds for my Drupal blog with no such PHP delays. I also strive to keep my MySQL running smoothly, but everyone should do that, anyway.</p>
<p>The downside of using Squid is logging. Since Squid is my front-end web server I have Apache listen on 127.0.0.1:80, and Squid accesses it there. So my Apache log files show all requests coming from 127.0.0.1, and many static page or image requests don&#8217;t come through because Squid has them cached. However I configured Squid to log in Apache log format and just use those logs instead.</p>
<p>Of course dynamic content from Drupal has the nocache header, so Squid isn&#8217;t caching the dynamic content for future requests, but it still frees up Apache while delivering it to the client. It does cache the static files like images, style sheets and javascript files, so the Apache threads mostly focus on dynamic content only.</p>
<p>Another way I keep memory usage down is with <a href="http://eaccelerator.net/">eaccelerator</a>. It caches PHP scripts so they don&#8217;t have to recompile every time they&#8217;re run. This can save memory in addition to processor time. After changing Drupal or any of my scripts I usually delete the cache and click around my sites to force all the php to run so eaccelerator will cache it. Then I restart my php processes (Apache2 in the case of Apache/mod-php or the fastcgi server if using fastcgi) to lower their memory usage. After that the cached scripts should run and the PHP processes shouldn&#8217;t bloat as much. Note that every time PHP is updated eaccelerator must be recompiled. In older PHP versions it would crash if you didn&#8217;t, but now it just silently (except for a log entry) fails to cache your scripts if you forget to recompile after a PHP update.</p>
<p>With lighttpd/fastcgi I was able to run 4 PHP processes (memory_limit from 8MB &#8211; 16MB), lighttpd, MySQL and Exim (my mail daemon) in a 256mb VPS with good speed. With Apache2/mod_php I am running 2 Apache2/mod_php processes, Squid (8 MB cache memory), MySQL and Exim in a 256mb VPS. Having only two processes forces me to watch for slow requests like a hawk, but Squid takes care of slow clients. I still ran into memory problems occasionally, but now I have a 384mb VPS and haven&#8217;t had a privvm failure yet.</p>
<p>You may also be interested in <a href="http://itkia.com/using-squid-to-cache-apt-updates-for-debian-and-ubuntu/">Using Squid To Cache Apt Updates</a>.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/2008-update-on-running-drupal-on-a-small-vps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VPS and Sneaky CPU Problems</title>
		<link>http://itkia.com/vps-and-sneaky-cpu-problems/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vps-and-sneaky-cpu-problems</link>
		<comments>http://itkia.com/vps-and-sneaky-cpu-problems/#comments</comments>
		<pubDate>Tue, 17 Oct 2006 03:09:45 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=51</guid>
		<description><![CDATA[My scheduled backup processes made web apps unresponsive. <a href="http://itkia.com/vps-and-sneaky-cpu-problems/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>While trying to find the perfect balance to make my sites run well out of my small VPS I noticed that my CPU usage was spiking. Unlike memory issues the Virtuozzo Power Panel didn&#8217;t issue a QoS alert for CPU overages. Apparently when you use too much CPU you just don&#8217;t get cycles for a while. Due to the spiky nature of CPU usage you don&#8217;t see the problem unless you catch it near the top of a spike.</p>
<p>I realized that my backup processes were helping to spike the CPU. I have a cron job to a mysql dump, and I have a remote machine regularly ssh/rsync in to copy files off. ssh and rsync use quite a bit of CPU. I should&#8217;ve realized that would happen, but &#8220;duhhhh&#8221;. I changed all my nonessential scripts to &#8220;nice&#8221; the commands. rsync was a bit tricky to get &#8220;nice&#8221;d, but I found the answers via Googling. What&#8217;s interesting is that Virtuozzo doesn&#8217;t seem to count the nice&#8217;d processes against the VPS&#8217;s CPU usage. They used spare host cycles apparently, and there are tons of spare host cycles. I think I actually sped my backups up with &#8220;nice&#8221;.</p>
<p>It&#8217;s tempting to try to run services nice&#8217;d, because I seem to get more &#8220;spare&#8221; cpu cycles than I get normal ones, but I have a feeling that will cause one problem or another down the line.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/vps-and-sneaky-cpu-problems/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Drupal and Small VPSes: Resource Issues</title>
		<link>http://itkia.com/drupal-and-small-vpses-resource-issues/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=drupal-and-small-vpses-resource-issues</link>
		<comments>http://itkia.com/drupal-and-small-vpses-resource-issues/#comments</comments>
		<pubDate>Sat, 14 Oct 2006 03:00:26 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://itkia.com/2006/10/drupal-and-small-vpses-resource-issues/</guid>
		<description><![CDATA[Switched to lighttpd and fastcgi to improve PHP website performance. <a href="http://itkia.com/drupal-and-small-vpses-resource-issues/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>I never did upgrade my VPS RAM. Part of it is laziness, but part of it is that I keep thinking my web server doesn&#8217;t do enough and isn&#8217;t busy enough for 256mb to not be enough.</p>
<p>I&#8217;m using mod_php for drupal and CivicSpace on several sites. I&#8217;m running Apache 2 with the prefork MLM. The problem with this setup and limited resources is that the running Apache processes bloat to handle the biggest PHP script they&#8217;ve run. To counter that I reduced the number of Apache processes. Per earlier blogs, I also deleted unused drupal modules and all my sites work fine under a PHP memory limit of 12mb. Between those two things I&#8217;ve kept my memory issues at bay.</p>
<p>However, running only 4 Apache proceses is causing problems, too. If a PHP script is slow to complete due to business or MySQL slowness, then that thread can&#8217;t handle any more requests.</p>
<p>Using the Apache worker MLM would relieve both the sustained memory bloat issues (memory can be released upon completing the PHP script) and the concurrent connection issues (no problem to make a new thread to handle a new request), but then you have all that PHP &amp; thread stuff to worry about.</p>
<p>I started looking into another solution that I&#8217;m going to try: FastCGI. With FastCGI you take mod_php out of the web server and run a persistent PHP (or other language) interpreter. The web server passes requests to the persistent interpreter. In PHP&#8217;s case, the php-cgi program will spawn multiple child processes to handle requests. I got this working on my home server and it works fine. Now the web server (I also switched to lighttp, but Apache can do FastCGI, too) can handle tons of requests with little resource usage and pass off the PHP scripts to the persistent php-cgi group. Sure, I can still overload my php-cgi group, but at least I can keep servicing small requests while PHP is jammed up. And I&#8217;m not servicing small requests with fat processes. But the biggie is now I can seperately manage my web server resources and my PHP resources for better fine tuning.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/drupal-and-small-vpses-resource-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shared and Concurrent Drupal Sites with Symlinking</title>
		<link>http://itkia.com/shared-and-concurrent-drupal-sites-with-symlinking/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shared-and-concurrent-drupal-sites-with-symlinking</link>
		<comments>http://itkia.com/shared-and-concurrent-drupal-sites-with-symlinking/#comments</comments>
		<pubDate>Sat, 22 Apr 2006 19:45:08 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[civicspace]]></category>
		<category><![CDATA[drupal]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=44</guid>
		<description><![CDATA[One shared Drupal, several sites with private data. <a href="http://itkia.com/shared-and-concurrent-drupal-sites-with-symlinking/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>I&#8217;m currently running Drupal 4.6.6, Drupal 4.7 RC3 and CivicSpace 0.8.3 . I preferred to have one set of source files, but I wanted each site (Apache vhost) to have its own root folder.</p>
<p>So, with some symlink magic, here&#8217;s what I do. Each version of Drupal has its own directory under my servers web root. I have the following directories and symlinks:</p>
<ul>
<li>drupal-4.6.6</li>
<li>drupal-4.7.0-rc3</li>
<li>civicspace-0.8.3</li>
</ul>
<ul>
<li>drupal-4.6 -&gt; drupal-4.6.6</li>
<li>drupal-4.7 -&gt; drupal-4.7.0-rc3</li>
<li>civicspace -&gt; civicspace-0.8.3</li>
</ul>
<p>Each vhost has its own DocumentRoot with the following symlinks, substituting drupal-4.6 or civicspace for drupal-4.7 as appropriate:</p>
<ul>
<li>cron.php -&gt; ../drupal-4.7/cron.php</li>
<li>database -&gt; ../drupal-4.7/database</li>
<li>includes -&gt; ../drupal-4.7/includes</li>
<li>index.php -&gt; ../drupal-4.7/index.php</li>
<li>misc -&gt; ../drupal-4.7/misc</li>
<li>modules -&gt; ../drupal-4.7/modules</li>
<li>scripts -&gt; ../drupal-4.7/scripts</li>
<li>sites -&gt; ../drupal-4.7/sites</li>
<li>themes -&gt; ../drupal-4.7/themes</li>
<li>update.php -&gt; ../drupal-4.7/update.php</li>
<li>xmlrpc.php -&gt; ../drupal-4.7/xmlrpc.php</li>
</ul>
<p>Each vhost gets its own files/ directory, robots.txt, .htaccess and favicon.ico files.</p>
<p>Now, when the next version (e.g. 4.7.1) is released I can unpack the files, copy the sites folder from the previous version, and then update the version symlink (drupal-4.7 -&gt; drupal-4.7.1) and run the update.php script.</p>
<p>If I want to change a particular site from Drupal 4.6 or CivicSpace 0.8.3 to Drupal 4.7 I update the symlinks in the DocumentRoot to point to the 4.7 series, copy the appropriate site config file over and run the update.php script.</p>
<p>This is working well so far, but in my recent &#8220;Memory Hogging&#8221; blog I mention that having too many modules installed (even if not activated) make the admin/modules screen take up tons of RAM. My sites have different modules needs, so I think I&#8217;m going to give each vhost its own modules directory and then symlink the modules under that. This way I&#8217;ll have only one module version per drupal version in my filesystem and be able to remove modules I know don&#8217;t need from individual sites.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/shared-and-concurrent-drupal-sites-with-symlinking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memory Hogging</title>
		<link>http://itkia.com/memory-hogging/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=memory-hogging</link>
		<comments>http://itkia.com/memory-hogging/#comments</comments>
		<pubDate>Sat, 22 Apr 2006 19:25:59 +0000</pubDate>
		<dc:creator>IT Know-It-All</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://itkia.com/?p=42</guid>
		<description><![CDATA[Drupal module admin page loads inactive modules bloating limited RAM. <a href="http://itkia.com/memory-hogging/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>I&#8217;ve been hitting the limit of my VPS&#8217;s (virtual private server) 256mb RAM limit since installing CivicSpace, and I keep adjusting the php limit to try to avoid having forked processes fail, but then CivicSpace will fail on certain admin pages.</p>
<p>I now understand that when looking at the module activate/deactivate page it loads *every* module installed, even if it&#8217;s not activated. (For other pages it only loads activated modules.) Since CivicSpace includes so many modules, this almost guarantees I&#8217;m going to run out of php memory if I have the limit set at 20mb or 16mb, and that&#8217;s about the same range where I bump my head on the server privvmpages limit given my current configuration.</p>
<p>I don&#8217;t think I&#8217;ve had this problem with Drupal yet, but I probably will as I keep adding modules.</p>
<p>As a temporary fix I&#8217;m going to remove modules that aren&#8217;t used and aren&#8217;t likely to be used. For a more permanent fix I&#8217;m going to pay more to get a higher RAM configuration. Instead of just picking 384mb or 512mb I&#8217;d like to look into how I want Apache, MySQL and PHP tuned and figure out how much RAM should be dedicated to each. I might also setup my own test box and run stress tests on Drupal with various configurations. Then I&#8217;ll know my RAM target.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://itkia.com/memory-hogging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

