<?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>Thoughts Electrique &#187; Server</title>
	<atom:link href="http://www.sebastian.himberger.de/blog/tag/server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sebastian.himberger.de/blog</link>
	<description>Sebastian Himbergers blog about technology and software development</description>
	<lastBuildDate>Sat, 16 Jul 2011 22:48:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Custom php.ini and URL rewriting in Plesk 9 with fastcgi</title>
		<link>http://www.sebastian.himberger.de/blog/2009/03/19/custom-phpini-and-url-rewriting-in-plesk-9-with-fastcgi/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/03/19/custom-phpini-and-url-rewriting-in-plesk-9-with-fastcgi/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 17:43:42 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=366</guid>
		<description><![CDATA[For a current hosting server I&#8217;m using the Plesk control panel 9.0.1 for Ubuntu 8.04. Since version 9 Plesk allows the usage of Postfix as an MTA and PHP via FastCGI. This is very nice and much more secure than the old model using mod_php. The Problem One problem with the current Plesk version (as [...]]]></description>
			<content:encoded><![CDATA[<p>For a current hosting server I&#8217;m using the <a title="Official Plesk website" href="http://www.parallels.com/de/products/plesk/" target="_blank">Plesk control panel 9.0.1</a> for Ubuntu 8.04. Since version 9 Plesk allows the usage of <a title="Postfix website" href="http://www.postfix.org/" target="_blank">Postfix</a> as an <a title="Mail Transfer Agent explain at Wikipedia" href="http://en.wikipedia.org/wiki/Mail_Transfer_Agent" target="_blank">MTA</a> and PHP via <a title="FastCGI website" href="http://www.fastcgi.com/" target="_blank">FastCGI</a>. This is very nice and much more secure than the old model using mod_php.</p>
<h3>The Problem</h3>
<p>One problem with the current Plesk version (as with most Plesk versions :/) is that it has some nasty bugs. For example mod_rewrite doesn&#8217;t work with the FastCGI configuration. The problem is that the generated virtual host configuration has a small but important problem. The generated host looks something like this:</p>
<pre class="file">&lt;VirtualHost 88.198.164.10:80&gt;
  ServerName   playground.himberger.de:80
  ServerAlias  www.playground.himberger.de

  &lt;IfModule mod_fcgid.c&gt;
    &lt;Files ~ (\.php)&gt;
      SetHandler fcgid-script
      FCGIWrapper /usr/bin/php5-cgi .php
<strong>      Options ExecCGI</strong>
      allow from all
    &lt;/Files&gt;
  &lt;/IfModule&gt;
&lt;/VirtualHost&gt;</pre>
<p>The issue with this configuration is the line &#8220;<strong>Options ExecCGI</strong>&#8220;. This line enables the execution of CGI scripts for this particular directory but overrides all the Options set earlier. These are in parts needed for mod_rewrite. To fix this the line should be &#8220;<strong>Options +ExecCGI</strong>&#8220;. Sadly changing the configuration doesn&#8217;t help because at the next opportunity Plesk will regenerate the config file and your change is gone.</p>
<p>Luckily there is a way around this&#8230;</p>
<p><span id="more-366"></span></p>
<h3>Enable mod_rewrite (the solution)</h3>
<p>Luckily Plesk allows you to append a custom configuration to the virtual host by creating a file <em>vhost.conf</em> in the <em>${yourvhost}/conf</em> directory. By putting the following config in your <em>vhost.conf</em> you can take back the overwritten Options (don&#8217;t forget to restart the Apache HTTPD).</p>
<pre class="file">&lt;Directory "/var/www/vhosts/${yourvhost}/httpdocs"&gt;
  &lt;Files ~ (\.php)&gt;
    Options All
  &lt;/Files&gt;
&lt;/Directory&gt;</pre>
<p>You have to be very specific (using the enclosing Directory directive) to cause the current setting to be overridden.</p>
<p>With this knowledge at hand we can do some other nice tricks.</p>
<h3>Using a custom php.ini with fastcgi</h3>
<p>Since we are now able to override the Plesk generated configuration we can also alter the fastcgi command and for example specify a custom php.ini:</p>
<pre class="file">&lt;Directory "/var/www/vhosts/${yourvhost}/httpdocs"&gt;
  &lt;Files ~ (\.php)&gt;
   <strong> FCGIWrapper "/usr/bin/php5-cgi -c /etc/phpconfigs/${yourvhost}"  .php</strong>
    Options All
  &lt;/Files&gt;
&lt;/Directory&gt;</pre>
<p>The <strong><strong>FCGIWrapper</strong></strong> command will use the directory specified with the <em>-c</em> parameter for it&#8217;s php configuration. Simply put your php.ini in this directory and it will automatically be picked up. This way you can easily use a per customer PHP configuration with fastcgi and Plesk.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/03/19/custom-phpini-and-url-rewriting-in-plesk-9-with-fastcgi/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Static IPs and default route on 1und1 CentOS 5 Servers</title>
		<link>http://www.sebastian.himberger.de/blog/2009/03/11/static-ips-and-default-route-on-1und1-centos-5-servers/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/03/11/static-ips-and-default-route-on-1und1-centos-5-servers/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 22:10:19 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[1und1]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=358</guid>
		<description><![CDATA[I&#8217;ve been experiencing some serverdowns at a client who uses 1und1 CentOS 5 Servers. After some investigation I discovered that cronjobs were still running although the server appeared to be down. Checking the syslogs showed me a bunch of failed DHCP requests which remebered me of the fact that 1und1 uses DHCP to configure the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been experiencing some serverdowns at a client who uses <a title="1und1 german website" href="http://www.1und1.de" target="_blank">1und1</a> <a title="Official CentOS website" href="http://www.centos.org/" target="_blank">CentOS </a>5 Servers. After some investigation I discovered that cronjobs were still running although the server appeared to be down. Checking the syslogs showed me a bunch of failed DHCP requests which remebered me of the fact that <strong>1und1 uses DHCP to configure the server machines</strong>. I don&#8217;t think this is a good idea so I changed the setup to static IPs.</p>
<p>Since 1und1 puts every server behind a dedicated firewall the setup is not as easy as you think. I&#8217;ll document it here because It may be useful for other people and certainly for myself after a couple of months.</p>
<h3>Configure a static IP address</h3>
<p>Open the file <em>/etc/sysconfig/network-scripts/ifcfg-eth0</em> and edit it to look like the following:</p>
<pre class="file">DEVICE=eth0
BOOTPROTO=none
TYPE=Ethernet
ONBOOT=yes
HWADDR=$YOURMACADDRESS
NETMASK=255.255.255.255
IPADDR=$YOURIP
GATEWAY=10.255.255.1</pre>
<p>Save the file.</p>
<h3>Configure static routes</h3>
<p>This is the tricky part. Configuring a default gateway using the <em>GATEWAY=</em> setting is not enough. You have to setup the routes yourself. To do so create a new file <em>/etc/sysconfig/network-scripts/route-eth0 </em>with the following contents:</p>
<pre class="file">10.255.255.1 dev eth0
default via 10.255.255.1 dev eth0</pre>
<p>Now you only have to reload the networking configuration via</p>
<pre class="terminal">service network reload</pre>
<p>and you are done!</p>
<p><a title="Tutorial for CentOS4" href="http://webui.sourcelabs.com/centos/mail/user/threads/How_to_create_static_routes_on_startup_with_CentOS4%253F.meta" target="_blank">This post</a> helped me a lot with the solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/03/11/static-ips-and-default-route-on-1und1-centos-5-servers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I&#8217;m choosing Tomcat (again)</title>
		<link>http://www.sebastian.himberger.de/blog/2009/02/26/im-choosing-tomcat-again/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/02/26/im-choosing-tomcat-again/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 20:46:12 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Opinionated]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=347</guid>
		<description><![CDATA[As you may remember from my last blogpost I&#8217;m currently setting up a new hosting Server. Since this server will also host some OpenCms and JEE sites I need to set up a Servlet Container. In almost all of my projects until today Tomcat was successfully used for this purpose. Be it stand alone or [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-348 alignleft" style="margin: 5px; float: left;" title="Tomcat from Shrek" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2009/02/tomcat-300x225.jpg" alt="" width="200" height="150" />As you may remember from my last blogpost I&#8217;m currently setting up a new hosting Server. Since this server will also host some <a title="OpenCms website" href="http://www.opencms.org" target="_blank">OpenCms</a> and JEE sites I need to set up a Servlet Container. In almost all of my projects until today <a title="Tomcat website" href="http://tomcat.apache.org" target="_blank">Tomcat</a> was successfully used for this purpose. Be it stand alone or embedded in a JEE application server (e.g. JBoss).</p>
<p>I must admit that I always had some kind of a love-hate relationship with Tomcat. The classloader had some bad issues when reloading a webapplication too often and often killed the complete server. Taking down all of the other webapplications too. Although this has gotten a lot better recently it&#8217;s still bothering me a bit.</p>
<p>Since I had some time after my last project I started investigating other open source alternatives. I often heard of Jetty, praised for it&#8217;s speed and simplicity, it seemed like a great alternative and I played around with it a bit. I really liked it since it was simple to use and easy to deploy but as I started to google for things like performance measurements or how to use it with a security manager I didn&#8217;t really found a lot of documentation (compared to Tomcat) and the performance doesn&#8217;t really doesn&#8217;t seem to differ from Tomcats.</p>
<p>So I&#8217;m once again going the Tomcat route. It has a big community and is even used in military and government organizations. It&#8217;s really not a technology decision (although I think Tomcat is solid) but more political thinking.</p>
<p>It will also save me some time which I can invest in trying out other technologies. <em>Meow&#8230;</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/02/26/im-choosing-tomcat-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing a host using the Shoreline firewall / Shorewall</title>
		<link>http://www.sebastian.himberger.de/blog/2009/02/25/securing-a-host-using-the-shoreline-firewall-shorewall/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/02/25/securing-a-host-using-the-shoreline-firewall-shorewall/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 13:03:04 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Shorewall]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=337</guid>
		<description><![CDATA[Since I&#8217;m currently setting up a new server for hosting purposes I want to share some of my favourite sysadmin tools and practices. The first featured tool is the shoreline firewall or shorewall. You can find the project at: http://www.shorewall.net/ Shorewall basically is a set of nice configuration files for iptables. Another benefit of shorewall [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;m currently setting up a new server for hosting purposes I want to share some of my favourite sysadmin tools and practices.</p>
<p>The first featured tool is the <em>shoreline firewall</em> or <em>shorewall</em>. You can find the project at: <a title="Shorewall website" href="http://www.shorewall.net/" target="_blank">http://www.shorewall.net/</a></p>
<p>Shorewall basically is a set of nice configuration files for <a title="Definition at Wikipedia" href="http://en.wikipedia.org/wiki/Iptables" target="_blank">iptables</a>. Another benefit of shorewall is that it has no runtime part. You just fire up the tool, it configures your iptables and quits. This reduces the load and increases security. Additionally to the technical features there is one thing that makes shorewall really stand out: It has extensive, well-written and understandable documentation. You rarely find a use-case which is not already described in the documentation.</p>
<p>Read on to find out how to set up shorewall in minutes.</p>
<p><span id="more-337"></span></p>
<h3>Setting up shorewall</h3>
<p>In this section I will describe how to secure a single server directly connected to the internet. There is no hardware firewall or DMZ involved.</p>
<p>First you have to install shorewall on your server. Since I use Ubuntu 8.04 there is already a prepackaged version in the repository.</p>
<pre class="terminal">aptitude install shorewall</pre>
<p>Then you have to copy some of the example configuration files to your /etc/shorewall directory.</p>
<pre class="terminal">cp -prv /usr/share/doc/shorewall-common/default-config/rules /etc/shorewall
cp -prv /usr/share/doc/shorewall-common/default-config/zones /etc/shorewall
cp -prv /usr/share/doc/shorewall-common/default-config/modules /etc/shorewall
cp -prv /usr/share/doc/shorewall-common/default-config/interfaces /etc/shorewall
cp -prv /usr/share/doc/shorewall-common/default-config/policy /etc/shorewall</pre>
<p>To understand the meaning I will first give a very short explanation of the shorewall terminology (the terms are pretty standard): Shorewall sees the network as a collection of <strong>zones</strong> (your local network, the internet, the firewall host itself, &#8230;). Network <strong>interfaces </strong>(eth0, eth1, &#8230;)<strong> </strong>are connected to the <strong>zones</strong> and allow traffic to move in and out. If traffic want&#8217;s to move between zones the firewall checks the configured <strong>rules</strong> wether there is a rule allowing or denying the traffic flow. If there is no rule for the specific case it applies a <strong>policy</strong> (default rule).</p>
<p>With this in mind the filenames should be straightforward to understand. The <strong>modules </strong>file loads shorewall specific modules (for example enables the ftp connection tracking). You don&#8217;t have to modify the modules file for a basic setup.</p>
<p>Lets first define the zones in the <strong>zones </strong>file.</p>
<pre class="file">###############################################################################
#ZONE   TYPE            OPTIONS         IN                      OUT
#                                       OPTIONS                 OPTIONS
fw      firewall
net     ipv4
#LAST LINE - ADD YOUR ENTRIES ABOVE THIS ONE - DO NOT REMOVE</pre>
<p>As you can see there are only two zones defined: The internet (net) and the server itself (fw).</p>
<p>We now connect the network interfaces to the zones using the <strong>interfaces </strong>file.</p>
<pre class="file">###############################################################################
#ZONE   INTERFACE       BROADCAST       OPTIONS
net     eth0            detect          norfc1918
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE</pre>
<p>That&#8217;s it. If you have more interfaces you of course have to connect these to the zones too. But if this is the case it&#8217;s very likely that you are striving for a more complex configuration anyway.</p>
<p>After defining the traffic sources we will now implement the default policy using the <strong>policy </strong>file.</p>
<pre class="file">###############################################################################
#SOURCE         DEST            POLICY          LOG             LIMIT:BURST
#                                               LEVEL
fw              net             ACCEPT
net             fw              DROP
all             all             DROP
#LAST LINE -- DO NOT REMOVE</pre>
<p>This policy allows the firewall to access all internet services and drops all incoming connections silently. Since this is not very useful for a server we now allow public access to some specific services by defining some rules in the <strong>rules </strong>file.</p>
<pre class="file">#############################################################################
#ACTION         SOURCE          DEST            PROTO   DEST    SOURCE
#                                                       PORT    PORT(S)
#SECTION ESTABLISHED
#SECTION RELATED
SECTION NEW
ACCEPT          net             fw              icmp    echo-request
ACCEPT          net             fw              tcp     22
ACCEPT          net             fw              tcp     80
ACCEPT          net             fw              tcp     443
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE</pre>
<p>As cou can see we allowed our server to reply to pings, incoming SSH connections and to serve up websites through HTTP and HTTPS.</p>
<p><strong>In Ubuntu you now have to set the <em>startup </em>variable in <em>/etc/default/shorewall</em> to <em>1</em> and run <em>/etc/init.d/shorewall start</em>. Be sure to check that everything works as expected before you close your SSH session!.</strong></p>
<p>That&#8217;s it. <a title="Shorewall website" href="http://www.shorewall.net/" target="_blank">Visit the shorewall website for more information</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/02/25/securing-a-host-using-the-shoreline-firewall-shorewall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Runkit with PHP on Linux (Debian Etch)</title>
		<link>http://www.sebastian.himberger.de/blog/2008/11/23/runkit-with-php-on-linux-debian-etch/</link>
		<comments>http://www.sebastian.himberger.de/blog/2008/11/23/runkit-with-php-on-linux-debian-etch/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 20:26:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PECL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Runkit]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=19</guid>
		<description><![CDATA[The forbidden fruit I recently discovered runkit for PHP and thought it could be a solution for a few problems I ran into during my work on various projects. At heart runkit allows you do to stuff with PHP you shouldn&#8217;t, but eventually want to, do. In my case this is basically Sandboxing and redefining [...]]]></description>
			<content:encoded><![CDATA[<h3>The forbidden fruit</h3>
<p>I recently discovered <a title="runkit PHP extension" href="http://de.php.net/runkit" target="_blank">runkit </a>for PHP and thought it could be a solution for a few problems I ran into during my work on various projects.</p>
<p>At heart runkit allows you do to stuff with PHP you shouldn&#8217;t, but eventually want to, do. In my case this is basically <a href="http://en.wikipedia.org/wiki/Sandbox_(computer_security)" target="_blank">Sandboxing</a> and redefining (even PHP-internal) functions. It really adds some cool stuff to your PHP toolbox. Have a look at the <a href="http://en.php.net/runkit" target="_blank">function reference</a> for the complete list.</p>
<p>Sadly enough the runkit PECL package does not work on Debian Etch (because Etch uses PHP 5.2.0+) so I had to build the package myself. Read on to find out how to build and install runkit on Debian etch and things to keep in mind when using runkit.</p>
<p><strong>Important:</strong> If you are unsure of using runkit have a look at The sections <em>The Caveat</em> and <em>Final Remarks</em> before you walk through the hassle of installing it.</p>
<p><span id="more-19"></span></p>
<h3>Install &amp; Configure runkit</h3>
<h4>Obtain the sources from the runkit CVS</h4>
<p>Obtaining the sources is pretty easy. Just open a terminal and enter the following commands (leave the password empty when prompted for it)</p>
<pre class="terminal">cvs -d:pserver:cvsread@cvs.php.net:/repository login
cvs -d:pserver:cvsread@cvs.php.net:/repository co pecl/runkit</pre>
<p>This will checkout the runkit codebase into your current working directory.</p>
<h4>Building the Debian package from the PECL source</h4>
<p>You need some tools for building the package so I installed them using aptitude.</p>
<pre class="terminal">sudo aptitude install dh-make-php php5-dev</pre>
<p>Then I created a kind of fake PECL package from the CVS sources to use it with the <a title="dh-make-pecl manual (I know.. it's Ubuntu)" href="http://manpages.ubuntu.com/manpages/intrepid/man1/dh-make-pecl.html" target="_blank">dh-make-pecl</a> tool. dh-make-pecl is a Debian tool which helps you building .deb from a PECL package. The PECL package is just a .tar.gz archive having the following structure:</p>
<div id="attachment_185" class="wp-caption alignnone" style="width: 193px"><a href="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/11/runkit-pecl-package.png"><img class="size-full wp-image-185" title="The runkit PECL package structure" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/11/runkit-pecl-package.png" alt="The runkit PECL package structure" width="183" height="361" /></a><p class="wp-caption-text">The runkit PECL package structure</p></div>
<p>I assembled this package by using simple mv and mkdir inside the CVS then I used tar to create the archive. I called it <em>runkit-cvs-&lt;date&gt;.tar.gz</em> but the name is basically irrelevant.</p>
<pre class="terminal">mkdir -p package/runkit-0.9
mv pecl/runkit/package*xml package/
mv pecl/runkit/* package/runkit-0.9/
cd package/; tar cfz ../runkit-cvs-`date +%Y%m%d%H%M`.tar.gz *; cd ..</pre>
<p>After I had the fake PECL package I could start creating the .deb from it. This was fairly simple.</p>
<pre class="terminal">dh-make-pecl --only 5 runkit-cvs*tar.gz
cd php-runkit-0.9
dpkg-buildpackage -rfakeroot</pre>
<p><em>dpkg-buildpackage</em> puts the created .deb parallel to the <em>php-runkit-0.9</em> directory. The <em>&#8211;only 5</em> parameter requests the dh-make-pecl command to only create a Debian source package for the PHP 5 module. Have a look at the manual for more information.</p>
<h4>Installing the package</h4>
<p>Installing runkit is now just a matter of typing <em>sudo aptitude install php5-runkit_0.9-1_i386.deb</em> and letting APT do it&#8217;s work. After that you have to create a configuration file under <em>/etc/php5/apache2/conf.d</em> called <em>runkit.ini</em> with the following contents:</p>
<pre class="file">extension=runkit.so

# comment out the following line to disable the overloading
# of PHP internal functions.
runkit.internal_override=1</pre>
<p>After that restart your Apache server and you are done with the installation. You can check if runkit was installed sucessfull by just creating a <em>phpinfo()</em> file and look if runkit is listed in the modules section.</p>
<div id="attachment_186" class="wp-caption alignnone" style="width: 510px"><a href="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/11/runkit-phpinfo.png"><img class="size-full wp-image-186" title="The runkit phpinfo() section" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2008/11/runkit-phpinfo.png" alt="The runkit phpinfo() section" width="500" height="124" /></a><p class="wp-caption-text">The runkit phpinfo() section</p></div>
<h3>The Caveat (Renaming PHP internal functions)</h3>
<p>I was quite happy to have all this stuff running but as we all know nothing is less predictable than solutions in information technology (apart from visiting relatives appearing out of nowhere). My first little project was to add some logging to the PHP built in <em>mail()</em> function. This may be useful to track down the spam sending contact form one of your customers build for his website on your server. I wrote a small script for testing purposes and just threw it in my public_html directory.</p>
<pre class="file">// Simple function to ouput a log message
function do_log($message) {
  echo 'LOG:'.$message;
}
// Wrapper for the PHP mail() function.
// Logs the mail parameters.
function logging_mail($to, $subject, $message, $headers = null, $params = null) {
  do_log('Sending mail to '.$to.' by '.__FILE__);
  php_mail($to, $subject, $message, $headers, $params);
}

// Interchange the built in function with my own
runkit_function_rename('mail','php_mail');
runkit_function_rename('logging_mail','mail');

mail('mymail@nodomain.xyz','Subject','message');</pre>
<p>It all seemed nice and logical but when I first opened my webbrowser and accessed the page I got a blank screen. My Apache error log revealed a <em>child pid 10051 exit signal Segmentation fault (11)</em> and commenting out the <em>mail()</em> and a quick page refresh even added a <em><strong>Fatal error</strong>:  Cannot redeclare do_log()</em> to the table. This looks really bad. It seems that renaming PHP internal functions and replacing them doesn&#8217;t work with runkit and the resulting crash of the PHP interpreter left the library of this interpreter in a corrupted state (user-defined functions where not removed because the script didn&#8217;t exit properly).</p>
<p>So as always: The part of a library you really need has a nasty bug. Although renaming user defined functions works great with runkit the part I really wanted doesn&#8217;t work out of the box.</p>
<p>I already have a solution in mind but this will be the topic of another blog post.</p>
<h3>Final remarks</h3>
<p>Runkit in theory is really great stuff. The problem with this library in realty is that it&#8217;s still beta (even after several years) and doesn&#8217;t seem to be actively maintained. Just a short look at the CVS repository and the bugtracker revealed that there hasn&#8217;t been much activety in the last year or so. This is a pitty because having the additional flexibilty that runkit provides really would be a killer feature for PHP developers. Other scripting languages (Python, Groovy and more) already bring these features to the table natively which allows you to write extremly elegant code.</p>
<p>If you are willing to dig into this extension prepare to do some work and be eventually disappointed because the solution you had in mind won&#8217;t work because of bugs. If you are willing to take this risk and invest some time and energy go for it. Maybe future versions of PHP will make runkit obsolete or a good-willing developer will take care of the bugs. Till then runkit remains black magic, it can make you incredibly powerful but also is a serious risk for your mental stability.</p>
<h3>More information</h3>
<ul>
<li><a title="An alternative way to build runkit" href="http://gabriel.e-radical.ro/blog1.php/2008/09/25/runkit" target="_blank">http://gabriel.e-radical.ro/blog1.php/2008/09/25/runkit</a> &#8211; An alternative way to build runkit</li>
<li><a title="Runkit function reference" href="http://en.php.net/runkit" target="_blank">http://en.php.net/runkit</a> &#8211; The runkit function reference</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2008/11/23/runkit-with-php-on-linux-debian-etch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

