<?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; Linux</title>
	<atom:link href="http://www.sebastian.himberger.de/blog/tag/linux/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>Thu, 08 Jul 2010 17:05:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Updating a broken SME 7.1 Server to version 7.4</title>
		<link>http://www.sebastian.himberger.de/blog/2009/10/23/updating-a-broken-sme-7-1-server-to-version-74/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/10/23/updating-a-broken-sme-7-1-server-to-version-74/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 03:06:49 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SME]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=542</guid>
		<description><![CDATA[The SME Server is a great Linux distribution for small to medium sized businesses. I&#8217;ve been doing some emergency sysadmin stuff quite a while ago and encountered the upgrade-hell from 7.1 to version 7.4. Since updating the operating system from 7.1 to 7.4 wasn&#8217;t easy I decided to write a quick blog post to save [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-555" style="border: none; float: left; margin: 4px;" title="The SME Logo" src="http://www.sebastian.himberger.de/blog/wp-content/uploads/2009/10/sme-logo.png" alt="The SME Logo" width="150" height="141" />The <a title="SME Server website" href="http://wiki.contribs.org/Main_Page" target="_blank">SME Server</a> is a great Linux distribution for small to medium sized businesses. I&#8217;ve been doing some emergency sysadmin stuff quite a while ago and encountered the upgrade-hell from 7.1 to version 7.4. Since updating the operating system from 7.1 to 7.4 wasn&#8217;t easy I decided to write a quick blog post to save you from tinkering.</p>
<p><span id="more-542"></span></p>
<p>Updating the SME in general is pretty straighforward but if the customer made modifications to the <em>yum</em> configuration it can quickly turn into a nightmare. Luckily there <a title="Upgrading from 7.1 Tutorial" href="http://wiki.contribs.org/Updating_from_SME_7.1.x_or_earlier#Yum_Update" target="_blank">is a tutorial available in the SME Wiki</a> which can help you to get started. Unfortunately the yum installation was completly broken so I had to update the packages by hand. I pulled the packages from the SME repository at and installed them via</p>
<pre class="terminal">export SME_MIRROR_URL="http://mirror.jvsnet.ro/sme/releases/7/smeos/i386/SME/RPMS"

wget $SME_MIRROR_URL/dialog-1.0.20040731-3.i386.rpm
wget $SME_MIRROR_URL/python-sqlite-1.1.7-1.2.1.i386.rpm
wget $SME_MIRROR_URL/yum-metadata-parser-1.0-8.el4.centos.i386.rpm
wget $SME_MIRROR_URL/e-smith-formmagick-2.0.0-1.el4.sme.noarch.rpm
wget $SME_MIRROR_URL/smeserver-yum-2.0.0-4.el4.sme.noarch.rpm
wget $SME_MIRROR_URL/yum-plugin-fastestmirror-0.2.4-3.c4.noarch.rpm
wget $SME_MIRROR_URL/e-smith-lib-2.0.0-1.el4.sme.noarch.rpm
wget $SME_MIRROR_URL/sqlite-3.3.6-2.i386.rpm
wget $SME_MIRROR_URL/yum-plugin-installonlyn-0.91-1.el4.sme.noarch.rpm
wget $SME_MIRROR_URL/perl-CGI-FormMagick-0.92-16.el4.sme.noarch.rpm
wget $SME_MIRROR_URL/yum-2.4.3-4.el4.centos.noarch.rpm

rpm -Uvh --nodeps --force *.rpm</pre>
<p>You maybe have to adjust this mirror url. This is why I factored it out into a seperate variable.</p>
<p>After this you should reset your <em>yum</em> repositories and clean the <em>yum</em> cache.</p>
<pre class="terminal">cd /home/e-smith/db/
mv yum_repositories yum_repositories.po
/etc/e-smith/events/actions/initialize-default-databases
signal-event yum-modify
yum clean all</pre>
<p>After doing so, issue the following commands to let <em>SME</em> rewrite it&#8217;s config.</p>
<pre class="terminal">signal-event post-upgrade; signal-event reboot</pre>
<p>Now you can update <em>yum</em> through yum itself (I know this sounds strange but this second update helps to get all the GPG keys for the repositories right).</p>
<pre class="terminal">yum update yum
signal-event post-upgrade; signal-event reboot</pre>
<p>Now you can proceed with a normal update to get the whole system up to 7.4. I had to do this following process twice because the updates seem to have pulled in some new dependencies which in turn have to get updated.</p>
<pre class="terminal">yum update yum
signal-event post-upgrade; signal-event reboot</pre>
<p>That&#8217;s it. I&#8217;m sure there might be an easier way but at least these are the steps the helped me get the system up to date. If you have questions just leave me a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/10/23/updating-a-broken-sme-7-1-server-to-version-74/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing PHP / PECL ImageMagick extension on 1&amp;1 managed server</title>
		<link>http://www.sebastian.himberger.de/blog/2009/09/26/installing-php-pecl-imagemagick-extension-on-11-managed-server/</link>
		<comments>http://www.sebastian.himberger.de/blog/2009/09/26/installing-php-pecl-imagemagick-extension-on-11-managed-server/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 03:42:16 +0000</pubDate>
		<dc:creator>Sebastian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[1und1]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PECL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.sebastian.himberger.de/blog/?p=477</guid>
		<description><![CDATA[I once had to install a custom PHP extension on a 1&#38;1 managed server. In this case the company had already purchased a managed server which was running the corporate website. They wanted to install an extranet-like webapplication which needed the ImageMagick PHP extension. In the following post I will outlike how I compiled and [...]]]></description>
			<content:encoded><![CDATA[<p>I once had to install a custom PHP extension on a <a title="1&amp;1 website" href="http://www.oneandone.com" target="_blank">1&amp;1</a> managed server. In this case the company had already purchased a managed server which was running the corporate website. They wanted to install an extranet-like webapplication which needed the <a title="ImageMagick extension" href="http://us3.php.net/manual/en/book.imagick.php">ImageMagick PHP extension</a>. In the following post I will outlike how I compiled and installed this extension on the managed server without having administrative access.</p>
<p><span id="more-477"></span></p>
<h3>Preparation</h3>
<p>To make the approach more modular we will use an environment variable pointing to our htdocs directory. I will call this variable $HTDOCS.</p>
<pre class="terminal">export HTDOCS=/kunden/homepages/.../htdocs</pre>
<p>We can check if everything is correct by changing into the htdocs directory.</p>
<pre class="terminal">cd $HTDOCS</pre>
<p>We will now create two directories:</p>
<ul>
<li><em>$HTDOCS/linux-src</em>: To hold all the data we need to compile the extensionn</li>
<li><em>$HTDOCS/linux</em>: To hold all the compiled data</li>
</ul>
<p>This setup allows us to delete the linux-src directory after we finished compiling the extension and save some diskspace.</p>
<pre class="terminal">mkdir -p $HTDOCS/linux-src
mkdir -p $HTDOCS/linux</pre>
<p>Now we will download the required sourcecode into our working directory:</p>
<pre class="terminal">mkdir -p $HTDOCS/linux-src/download
cd $HTDOCS/linux-src/download
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz
wget ftp://ftp.remotesensing.org/pub/libtiff/tiff-3.8.2.tar.gz
wget http://us3.php.net/get/php-5.2.10.tar.gz/from/us.php.net/mirror</pre>
<p><strong>Note:</strong> The URLs to the latest versions may change over time. You will have to adjust them and also watch for changed file names in the following steps. Also be sure to use the PHP version currently active on your managed server.</p>
<h3>Extracting the sourcecode</h3>
<p>Now create a folder for the extracted sourcecode and extract the source archives:</p>
<pre class="terminal">mkdir -p $HTDOCS/linux-src/extracted/imagick
mkdir -p $HTDOCS/linux-src/extracted/php-imagick
mkdir -p $HTDOCS/linux-src/extracted/libtiff
mkdir -p $HTDOCS/linux-src/extracted/php5

cd $HTDOCS/linux-src/extracted/imagick &amp;&amp; tar xfz $HTDOCS/linux-src/download/ImageMagick.tar.gz
cd $HTDOCS/linux-src/extracted/php-imagick &amp;&amp; tar xfz $HTDOCS/linux-src/download/imagick-2.3.0.tgz
cd $HTDOCS/linux-src/extracted/libtiff &amp;&amp; tar xfz $HTDOCS/linux-src/download/tiff-3.8.2.tar.gz
cd $HTDOCS/linux-src/extracted/php5 &amp;&amp; tar xfz $HTDOCS/linux-src/download/php-5.2.10.tar.gz</pre>
<h3>Building delegate libraries</h3>
<p>ImageMagick uses different delegate libraries for certain formats. We have to build these first so they can be incorporated into our ImageMagick build. In this case we will only use libtiff to allow the usage of the TIFF image format.</p>
<h4>Building libtiff from source</h4>
<p>Building libtiff is pretty straightforward. Simply use the following commands inside the extracted source archive:</p>
<pre class="terminal">./configure --prefix=$HTDOCS/linux/
make
make install</pre>
<h3>Building ImageMagick from source</h3>
<p>Change into the extracted source directory and type in the following:</p>
<pre class="terminal">./configure --without-perl --prefix=$HTDOCS/linux \
  CPPFLAGS="-I$HTDOCS/linux/include" LDFLAGS="-L$HTDOCS/linux/lib/"
make
make install</pre>
<p>You can type the following command to test the compiled ImageMagick.</p>
<pre class="terminal">make check</pre>
<p>After ImageMagick is built we can now go on and create the PHP extension.</p>
<h3>Building the ImageMagick PHP extenstion</h3>
<p>To compile the extension we have to have a PHP development environment in place. To create one we&#8217;ll simply compile and install PHP (this sounds more scary than it is).</p>
<h4>Building PHP from source</h4>
<p>Change into the extracted PHP archive and type in the following:</p>
<pre class="terminal">./configure --prefix=$HTDOCS/linux
make
make test
make install</pre>
<p>The <em>make test</em> target will run the PHP test suite. You can expect some tests to fail but if the number of failing tests is overwhelming you should get suspicious.</p>
<h4>Building the ImageMagick PECL extension</h4>
<p>Change into the extracted source archive and type in the following:</p>
<pre class="terminal">phpize --clean
phpize
./configure --prefix=$HTDOCS/linux --with-php-config=/usr/bin/php-config5 --with-imagick=$HTDOCS/linux</pre>
<p>The configure script should go through. Unfortunately it seems that the prefix and paths will not be set correctly in the <em>Makefile</em>. We will have to adjust this and replace the /usr/local paths with the path to our $HTDOCS/linux</p>
<pre class="terminal">echo "$HTDOCS/linux" | sed -e 's/\//\\\//g' &gt; htdocs_pattern &amp;&amp; \
  export HTDOCS_PATTERN=`cat htdocs_pattern` &amp;&amp; rm htdocs_pattern
perl -pi -e "s/\/usr\/local/$HTDOCS_PATTERN/g" Makefile</pre>
<p><strong>Note</strong>: The above command looks a bit freaky and is a bit of a quick hack. What it basically does it is escaping the slashes (/) in the <em>$HTDOCS</em> path and writing this to a file. Then exporting the content of the file to an environment variable and deleting the file. After this PERL is used to replace all <em>/usr/local</em> paths in the <em>Makefile</em> to <em>$HTDOCS/linux</em></p>
<p>After that we are good to go and can build the extension:</p>
<pre class="terminal">./configure --prefix=$HTDOCS/linux
make
make install</pre>
<p>Now the extension should be build successfully and is placed in the directory <em>$HTDOCS/linux/somepath</em> (the <em>make install</em> will tell you the extact path) . The last thing we have to do is activating the extension.</p>
<h3>Activating the extension</h3>
<p>To activate the extension for a certain folder, create a file named php.ini (for example in the $HTDOCS directory) with the following content inside the folder:</p>
<pre class="file">extension_dir=$HTDOCS/linux/somepath
extension=imagick.so</pre>
<p>Also don&#8217;t forget to activate PHP 5 with using a <em>.htaccess</em> file:</p>
<pre class="file">AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php</pre>
<p>That&#8217;s all. If you have any questions feel free to comment. I hope this helps some of you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sebastian.himberger.de/blog/2009/09/26/installing-php-pecl-imagemagick-extension-on-11-managed-server/feed/</wfw:commentRss>
		<slash:comments>2</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 is that [...]]]></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 (even PHP-internal) [...]]]></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>
