<?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>Rene Bakx</title>
	<atom:link href="http://renebakx.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://renebakx.nl</link>
	<description>about me, me and did i mention me?</description>
	<lastBuildDate>Mon, 23 Aug 2010 08:12:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Twig for drupal, simple usage examples</title>
		<link>http://renebakx.nl/43/twig-for-drupal-example/</link>
		<comments>http://renebakx.nl/43/twig-for-drupal-example/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 15:27:14 +0000</pubDate>
		<dc:creator>Rene</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://renebakx.nl/?p=43</guid>
		<description><![CDATA[As promised  some examples on how to use the twig-for-drupal engine. Part of these examples are written by Rik van der Kemp aka @cursief on twitter After this the usage,and even the need for twig in Drupal will hopefully a bit more clear to you. Twig forces you into writing clean template code instead of [...]]]></description>
			<content:encoded><![CDATA[<p>As promised  some examples on how to use the twig-for-drupal engine. Part of these examples are written by Rik van der Kemp aka<a href="http://twitter.com/cursief" target="_blank"> @cursief </a>on twitter</p>
<p>After this the usage,and even the need for twig in Drupal will hopefully a bit more clear to you. Twig forces you into writing clean template code instead of using php logic because hrmm well you can ;)</p>
<h2><span id="more-43"></span>Twig for readability</h2>
<p>Normally you will write something like this, if you need to write a bunch of links to the screen</p>
<pre class="brush:php">&lt;?php foreach ($links as $link) : ?&gt;
&lt;a href="&lt;?php print $link['href']; ?&gt;" id="&lt;?php print $link['id']; ?&gt;" title="&lt;?php print $link['title']; ?&gt;" target="&lt;?php print $link['target']; ?&gt;"&gt;&lt;?php print $link['description']; ?&gt;&lt;/a&gt;
&lt;?php endforeach; ?&gt;</pre>
<p>Not that hard to read, i admit that.. Now the same block in twig syntax</p>
<pre class="brush:php">
{% for link in links %}
{{link.description}}
{% endfor %}
</pre>
<p>Much easier on the eye, isn&#8217;t it :)<br />
And for practical use, this is my current test block from garland translated into twig</p>
<pre class="brush:ruby">&lt;div id="block-{{block.module}}-{{block.delta}}" class="clear-block block block-{{block.module}}"&gt;
{% if (block.subject) %}
  &lt;h2&gt;{{block.subject}}&lt;/h2&gt;
{% endif %}
  &lt;div class="content"&gt;{{ block.content}}&lt;/div&gt;
&lt;/div&gt;</pre>
<div id="block-{{block.module}}-{{block.delta}}" class="clear-block block block-{{block.module}}">
<h2>Objects in templates</h2>
<p>Since in twig there is no difference between an array of a variable , you can call object methods very easily.<br />
Say you  have a object called sheep defined that looks like this</p>
<pre class="brush:php">&lt;?php
class sheep(){
 function identify(){
	return "blaat";
	}
}
?&gt;</pre>
<p>And you assign this to a block in your drupal installation by using the twig_preprocess_block() implementation of <a href="http://api.drupal.org/api/function/template_preprocess_block/6" target="_blank">template_preprocess_block()</a></p>
<pre class="brush:applescript">&lt;?php
function twig_block_preprocess(&amp;$block){
 $block["sheep"] = new sheep();
}
?&gt;</pre>
</div>
<p>Then in your twigged template, you want the sheep to identify itself by the noise it makes</p>
<pre class="brush:ruby">&lt;h1&gt;Sheep&lt;/h1&gt;
The sheep is recognized by the {{sheep.identify()}} noise it makes.</pre>
<p>Can you see where this is going? Imagine assigning views or form code to your template and simply call them in a much more cleanier and easier to read way, by keeping the logic where it belongs!</p>
<h2>Translating and linking, and debugging.</h2>
<p>By default twig-for-drupal comes with two wrappers for the most used functions in a template, or atleast i think so.</p>
<pre class="brush:ruby">&lt;a href="{%l 'node/12' %}"&gt;{%t 'readmore' %}&lt;/a&gt;
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Produce a translated readmore link to node/12 , and node/12 is nicelly SEO friendly if you are using pathauto.</span></pre>
<p>Currently in the github repository there is also support for the devel module. If enabled, you can use it to either DPR or DPM your variables</p>
<div id="block-{{block.module}}-{{block.delta}}" class="clear-block block block-{{block.module}}">
<pre class="brush:ruby">&lt;div id="block-{{block.module}}-{{block.delta}}" class="clear-block block block-{{block.module}}"&gt;
{% if (block.subject) %}
  &lt;h2&gt;{{block.subject}}&lt;/h2&gt;
{% endif %}
  &lt;div class="content"&gt;{% dpr block %}&lt;/div&gt;
&lt;/div&gt;</pre>
</div>
<p>Please note that Twig removes the spaces between the {% dpr, is just use them to make it more readable.</p>
<h2>Today&#8217;s changes</h2>
<p>After working with the twig engine last week, two of my colleagues wanted to use doctrine generated objects for a D6 project currently in the making, but ran into some issues with the default twig behaviour of putting is_set() function around variables in compiled templates. Which gave some issues with not calling the proper __GET for those objects.</p>
<p>This is changed now, which means that the content of the variable is no longer checked in the compiled template and you NEED to either nicely assign/init everything you use or put a IF statement around it yourself. Later on, when the module to configure the twig engine is done, this will become an on/off option.</p>
<p>An other issue was naming of the cache files, by default with made a file called __TWIG_TEMPLATE__.MD5(&#8216;templatename&#8217;).php.</p>
<p>This is changed into a more easier findable themename_templatename_tpl_html.php file in the /files/twig_cache folder.<br />
Just in case you are left wondering what the *bleep* twig is doing underwater.</p>
<h2>One more thing&#8230;.</h2>
<p>As from now, the engine gives a drupal_set_message warning if fallback mode is being used. So you can see which template&#8217;s you need to twig!</p>
<p>Happy twigging&#8230;.. and grab the latest version from my <a href="github.com/renebakx/twig-for-drupal" target="_blank">github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://renebakx.nl/43/twig-for-drupal-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing, the twig for drupal template engine</title>
		<link>http://renebakx.nl/35/introducing-the-twig-for-drupal-template-engine/</link>
		<comments>http://renebakx.nl/35/introducing-the-twig-for-drupal-template-engine/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 10:33:50 +0000</pubDate>
		<dc:creator>Rene</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://renebakx.nl/?p=35</guid>
		<description><![CDATA[Introducing the twig template engine for drupal, to make the live of those who theme more fun, and at the same time introduces abstraction in display and other logic for those who code. Twig for drupal comes with fallback to tpl.php, and that unique feature is what really makes it easy to start using it.
]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>This project is for those who like me, are getting that strange itching sensation in the neck when reading the amounts of PHP code in drupal tipplephip files. Not for the people who claim PHP is a template language and that a language in a language is a stupid waste of time. For all I care go ahead, and keep rocking the party like it is still 1998. To me PHP has come a long way since then with the usual growing pains, but it has become so much more then just a simple language to make personal home pages and thus a template system is no excessive baggage but a good companion in creating maintenance friendly code!</p>
<p><span id="more-35"></span></p>
<div>So after doing a few projects for my current <a href="http://zicht.nl" target="_blank">employer</a> in drupal, my need was clearly there to create more abstraction between the display logic (aka tpl.php) and processing logic (template.php/modules) I&#8217;am one of those strange breeds that like to put things where they belong, and clearly PHP had no place in the template file itself. Sure it gives great power, to do all sorts of magic there, but for maintenance and reusability it is hell on earth..</div>
<div>So the search began for an alternative template system. Explored the ones already there on <a href="http://drupal.org/project/theme%20engines" target="_blank">drupal</a> site, but they either depend on the simple fact that every single template needed to be converted to their syntax, where unsupported since D5 and/or used very ancient PHP4 code. Tried to use smarty, which I&#8217;am or better was using since 2000, but it had to much overhead, there is no need a third caching layer on that level, drupal is already doing that for us. After reading some of Fabien&#8217;s tweets, and a <a href="http://drm.tweakblogs.net/blog/3538/twig-the-next-generation-template-engine-for-php.html" target="_blank">blog</a> a colleague of mine wrote about twig. I was sold! <a href="http://twig-project.org" target="_blank">Twig</a> was the answer I was searching for, it is lightweight, extendable and provided everything I was looking for in a drupal template language.</div>
<div>And this is it, the first official RC1 release of <a href="http://github.com/renebakx/twig-for-drupal" target="_blank">Twig-for-Drupal,</a> currently only for D6, but I promise to make a D7 version somewhere later this year, after completing the add-on module for this version. In the current state twig-for-drupal is just an other template engine. But with a fallback mode, and that is what makes this template engine a bit special I believe.</div>
<div>You do not NEED to create a tpl.html file for every module that you use, it&#8217;s recommended to do so. But your site won&#8217;t break if the .tpl.html is missing. It simply falls back to default D6 templating, a bit slower since it is going trough the rendering loop twice but still, you can enable a module, work with it and start templating it into twig lingo when you are ready to do so!</div>
<div></div>
<div id="_mcePaste">The above mentioned complementary module will make the job of templating a site easier by introducing a more fine grained template filename hinting system, like for example different template names for build modes, node/page/block names based on context, a system that executes a &lt;template&gt;_method() instead of doing the usual big switch-&gt;case dance in a module_hook_node of template_node() method</div>
<h2></h2>
<h2>Usage</h2>
<div>First of all pull the engine from github, into a folder named twig in your sites/themes/engines or sites/all/themes/engines/.</div>
<div id="_mcePaste">
<pre class="brush:shell">$git clone git://github.com/renebakx/twig-for-drupal.git
$cd twig
$git submodule init
$git submodule update</pre>
</div>
<div id="_mcePaste">Finally open your theme&#8217;s .info file and set the engine from &#8216;phptemplate&#8217; to &#8216;twig&#8217; and presto&#8230;</div>
<div>You are now ready to rock it in Twig and start creating your very own nicely abstracted .tpl.html files.</div>
<h2><strong><br />
Syntax</strong></h2>
<div>Explaining all the nice features of twig would surpass this article, just head over to the official twig site, and read about the powers that twig brings you as <a href="http://www.twig-project.org/book/03-Twig-for-Developers" target="_blank">developer</a> or <a href="http://www.twig-project.org/documentation" target="_blank">themer</a></div>
<div>For this drupal implementation I have created some extra tags that where needed in creating templates for a project currently in development.</div>
<h3></h3>
<h3>Translate or T, the mapper for the the drupal t() method</h3>
<p>usage {%t &#8220;foo&#8221; %} / {%t object.name %} / {%t &#8220;foo&#8221; lang=&#8217;nl&#8217;%} / {%t &#8220;foo&#8221; lang=user.lang %} or any other combination.</p>
<div id="_mcePaste">The only directive that is fixed is &#8216;lang=&#8217; all the parameter can either be a string, or object / array.</div>
<div id="_mcePaste">example :</div>
<pre>{%t 'readmore' lang='nl' %} returns the string Lees meer to your template.</pre>
<h3></h3>
<h3>Link, or L, mapper to the drupal url() method</h3>
<div id="_mcePaste">Same syntax as the T tag, but then returns the link part looped trough the drupal url method.</div>
<div id="_mcePaste">example :</div>
<pre>&lt;a href=”{%l 'node/12'%}”&gt; would return the path to node/12 or /somestory/ if node/12 was a translated trough pathauto.</pre>
<h3></h3>
<h3>DPR and DPM, mapper to devel module dpr() and dpm() methods</h3>
<pre>{%dpr variable %} or {%dpm variable%} where variable can also be an object or array.</pre>
<h3></h3>
<h3>Size filter, mapper to format_size</h3>
<div id="_mcePaste">More as an example on how to use filters,  then really useful, the format_size function from common.inc is implemented. So you can do a thing like</div>
<pre>{{ file.size|size }} to show the user 1.2MB instead of 12582912</pre>
<h2></h2>
<h2>Extending it yourself</h2>
<div id="_mcePaste">For extending it with your own tags or filters, take a look at the lib/Drupal folder. The trick is first to register it with the extension, then write your lexer and node. Twig-for-drupal uses a pear styled autoloading system. And please do share your extensions with the rest of the world, that is what&#8217;s so great about community driven development. Sharing, learning and earning a decent living with it :)</div>
<div>More to come later, but feel free to use it, love it (or hate it&#8230;)</div>
<div>But please stop that ancient discussion that a template engine in php is useless, and that phptemplate is doing a fine job by itself.  It is, just not for me, and some other people using twig for production :)</div>
]]></content:encoded>
			<wfw:commentRss>http://renebakx.nl/35/introducing-the-twig-for-drupal-template-engine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Compiling PHP 5.3.3, with nginx on ubuntu 10.4 for drupal 7</title>
		<link>http://renebakx.nl/22/compiling-php-5-3-3-with-nginx-on-ubuntu-10-4-for-drupal-7/</link>
		<comments>http://renebakx.nl/22/compiling-php-5-3-3-with-nginx-on-ubuntu-10-4-for-drupal-7/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 20:37:16 +0000</pubDate>
		<dc:creator>Rene</dc:creator>
				<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://renebakx.nl/?p=22</guid>
		<description><![CDATA[Introduction Since i made the plan to change from a rather expensive dedicated server to a much cheaper VPS solution, i started thinking about moving away from the sluggish apache2 stack. Fed by the fact that the PHP developers surprised me by suddenly announcing that the support for the php 5.2.x is going into security [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>Since i made the plan to change from a rather expensive dedicated server to a much cheaper VPS solution, i started thinking about moving away from the sluggish apache2 stack. Fed by the fact that the PHP developers surprised me by suddenly announcing that the support for the php 5.2.x is going into security fixes when needed mode, i decided i might as well go all the way then. Moving to <a title="php 5.3.3 release note" href="http://www.php.net/archive/2010.php#id2010-07-22-2" target="_blank">PHP 5.3.3</a> running a much leaner and faster <a title="nginx.org" href="http://nginx.rog" target="_blank">NGINX</a> HTTP server under <a title="ubuntu server" href="http://www.ubuntu.com/server" target="_blank">Ubuntu 10.4 LTS</a> using the new<a title="php-fpm" href="http://php-fpm.org/" target="_blank"> PHP-FPM</a> instead of fastcgi<span id="more-22"></span><span style="font-weight: normal; font-size: 13px;">On that server I am most likely going to run a few sites in<a title="drupal 7 dev" href="http://drupal.org/node/156281" target="_blank"> Drupal 7,</a> i sat down to configure a small development environment under virtual box.</span><span style="font-weight: normal; font-size: 13px;">Downloaded the 64Bit ISO of ubuntu server, installed a basic server without any preconfigured extensions except sshd and mysql-server.</span><span style="font-weight: normal; font-size: 13px;">After installing, updating and such,  had plenty of time reading myself into configuring nginx, compiling php and creating an image cache friendly version of the default nginx setup.</span></p>
<p>(please do note i once again assume the shell user is either root via the sudo bash method, or you need to type sudo in front of most commands)</p>
<h3>Step 1, the easy one</h3>
<div>Installing nginx, did not want to compile it just so i could have a few minor versions newer, and thus i used the one that is in the ubuntu distro.</div>
<div>
<pre class="brush:shell">apt-get install nginx</pre>
</div>
<div>Told you, it was an easy one ;)</div>
<h3>Step 2, compile php 5.3.3 from source</h3>
<pre class="brush:shell">cd /usr/local/source/
wget http://nl3.php.net/get/php-5.3.3.tar.gz/from/nl2.php.net/mirror
tar -xzf php-5.3.3.tar.gz</pre>
<p>Get the rest of the needed libraries and compiler trough apt-get</p>
<pre class="brush:shell">apt-get install autoconf2.13 libssl-dev libcurl4-gnutls-dev libjpeg62-dev libpng12-dev  libmysql++-dev libfreetype6-dev libt1-dev libc-client-dev mysql-client libevent-dev libxml2-dev libtool libmcrypt-dev
cd php-5.3.3
./configure --enable-fpm --with-mcrypt --enable-mbstring --with-openssl --with-mysql --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf  --with-pdo-mysql --with-libxml-dir=/usr/lib --with-mysqli=/usr/bin/mysql_config --with-curl --enable-zip  --enable-sockets --with-zlib --enable-exif --enable-ftp --with-iconv --with-gettext --enable-gd-native-ttf --with-t1lib=/usr --with-freetype-dir=/usr --prefix=/usr/local/php --with-fpm-user=www-data –with-fpm-group=www-data</pre>
<p>As you can see, rather basic version. No SQLite, just GD, MYSQL and some multibyte, crypt stuff etc.<br />
Do note that the<strong> “&#8211;with-fpm-user=www-data –with-fpm-group=www-data”</strong> is different with the latest build of php 5.3.3, previous versions you needed the php-fpm patch, but from this version on it is included as a beta option</p>
<p>No errors occurred, fired up my nespresso machine, and started the compiling of PHP</p>
<pre class="brush:shell">make
make install</pre>
<p>And while you are at it, you could do the make test as well, so the php people receive yet an other compiling log ;))<br />
After compiling and few nespresso&#8217;s (fortissio lungo if you really want to know :)) it was time to copy some files into their appropriate place.<br />
Since it is a dev box, I preferred the development php.ini, you could substitute php.ini.development with php.ini.production if you wanted to</p>
<pre class="brush:shell">cp php.ini-development /usr/local/lib/php/php.ini
chmod 644 /usr/local/php/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults
touch /var/run/php-fpm.pid</pre>
<h3>Step 3, configure nginx and php-fpm</h3>
<p>Starting with php-fpm, I like my PID files in one place, so i altered the /etc/init.d/php-fpm a little by changing</p>
<pre class="brush:shell">php_fpm_PID =${prefix}/var/run/php-fpm.pid into php_fpm_PID=/var/run/php-fpm.pid</pre>
<p>Then a few lines in the /usr/local/etc/php-fpm.conf, which is a rather large file so i just sum up the changes i made assuming you know how to search/replace etc by yourself since you are reading this not so noobisch point and click blogpost anyway.</p>
<pre class="brush:shell">error_log = /var/log/php-fpm.log
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 35</pre>
<p>Next up was configuring nginx, and must warn you upfront. I have NO idea if this is the correct way of doing it. It seemed the most logically way after reading the manual and some posts in the ground-squirrel/nginx.<br />
This is the config chunk i ended up with, and i know that some parts can be moved into a own designated include file, but that is for next time :)<br />
My site is in the /var/www/drupal7 and the log files go into /var/log/</p>
<pre class="brush:shell">server {
listen 80 default;
root /var/www/drupal7/;
index index.php;
access_log /var/log/drupal7_access.log;
error_log /var/log/drupal7_error.log;
# if the file is not physical there, loop trough drupal
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# if the file is not imagecached, create one
location ~ /files/imagecache/ {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
# just send a empty response if the favicon.ico is m.i.a
location = /favicon.ico {
try_files /favicon.ico =204;
}
# hide protected files
location ~*.(.htaccess|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(.php)?|xtmpl)$ {
deny all;
}
# enable robots.txt
location = /robots.txt {}
# hide backup_migrate files
location ~* ^/files/backup_migrate {
deny all;
}
# Allow all files in this location to be downloaded
location ~ ^.*/files/.*$ {}
# setup the php-fpm pass-trough
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}</pre>
<h3>Final step, tested the config files and uploaded drupal7-dev in place</h3>
<pre class="brush:shell">service nginx configtest</pre>
<p>If no errors occurred, start up php-fpm and nginx</p>
<pre class="brush:shell">service php-fpm start
service nginx start</pre>
<p>Upload drupal into the correct, folder do what you normally would do, like copy the settings.php, create a mysql database and in this case remove the .htaccess since it is not needed by nginx.</p>
<p>Point your browser to the correct server, and if all went well you should see a rather familiar picture :)</p>
<p><img class="alignnone size-medium wp-image-30" title="welcome to ubuntu" src="http://renebakx.nl/wp-content/uploads/2010/07/Screen-shot-2010-07-25-at-10.38.42-PM-500x296.png" alt="ubuntu screenshot" width="500" height="296" /></p>
]]></content:encoded>
			<wfw:commentRss>http://renebakx.nl/22/compiling-php-5-3-3-with-nginx-on-ubuntu-10-4-for-drupal-7/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fixing the documentroot with vhost_alias</title>
		<link>http://renebakx.nl/17/fixing-the-documentroot-with-vhost_alias/</link>
		<comments>http://renebakx.nl/17/fixing-the-documentroot-with-vhost_alias/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 10:09:24 +0000</pubDate>
		<dc:creator>Rene</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://renebakx.nl/?p=17</guid>
		<description><![CDATA[A small solution in follow up of the document root issue drm brought up in a previous post. Setting the correct $_SERVER["document_root"] value for your vhost_alias site. The problem is a long ago confirmed yet still not solved bug in apache mod_vhost_alias, however with a little PHP magic it was easy fixable in my local [...]]]></description>
			<content:encoded><![CDATA[<p>A small solution in follow up of the document root issue drm brought up in a <a href="http://renebakx.nl/7/running-a-local-wildcard-dns-server-on-your-mac/">previous</a> post. Setting the correct $_SERVER["document_root"] value for your vhost_alias site.</p>
<p><span id="more-17"></span>The problem is a long ago confirmed yet still not solved bug in apache mod_vhost_alias, however with a little PHP magic it was easy fixable in my local XAMPP configuration using the php_admin_value directive in the vhost configuration.</p>
<h3>Step 1</h3>
<p>Open the <em>httpd_vhosts.conf </em>located in the /Applictions/XAMPP/etc/extra folder and add the following line to the virtual_host definition</p>
<pre class="brush:plain">php_admin_value auto_prepend_file /Applications/XAMPP/xamppfiles/lib/php/fix_docroot.php</pre>
<p>So I ended up with a httpd_vhost configuration looking like this :</p>
<pre class="brush:plain">&lt;VirtualHost *:80&gt;
	ServerName dev.local
	ServerAlias *.dev.local
	ServerAdmin webmaster@localhost
	VirtualDocumentRoot "/Users/rene/Sites/%1"
	VirtualDocumentRoot "/Users/rene/Sites/%-3+/"
	&lt;Directory /Users/rene/Sites/&gt;
		Options Indexes FollowSymLinks
		AllowOverride All
		Order allow,deny
		Allow from all
	&lt;/Directory&gt;
	php_admin_value auto_prepend_file /Applications/XAMPP/xamppfiles/lib/php/fix_docroot.php
&lt;/Virtualhost&gt;</pre>
<h3>Step 2</h3>
<p>Next up is creating a small php str_replace function in fix_docroot.php , which is loaded and executed at every request.</p>
<p>Open up your favorite code editor, and create a file called<em> fix_docroot.php </em>at <em>/Applications/XAMPP/xamppfiles/lib/php/ </em>and paste the following chunk of code in it.</p>
<pre class="brush:php">&lt;?php
$_SERVER["ORG_DOCUMENT_ROOT"] = $_SERVER["DOCUMENT_ROOT"];
$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["SCRIPT_NAME"], '',$_SERVER["SCRIPT_FILENAME"]);
?&gt;</pre>
<p>Save it, restart apache and the values should be set correctly, with the old value still available in $_SERVER["ORG_DOCUMENT_ROOT"] just in case it is needed for something.</p>
]]></content:encoded>
			<wfw:commentRss>http://renebakx.nl/17/fixing-the-documentroot-with-vhost_alias/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running a local wildcard DNS server on your mac</title>
		<link>http://renebakx.nl/7/running-a-local-wildcard-dns-server-on-your-mac/</link>
		<comments>http://renebakx.nl/7/running-a-local-wildcard-dns-server-on-your-mac/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 07:04:48 +0000</pubDate>
		<dc:creator>Rene</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://renebakx.dev.local/?p=7</guid>
		<description><![CDATA[Ever since I&#8217;am using my macbook pro with XAMPP as my primary development workhorse, i&#8217;ve been playing around with the hosts file every single time I started a new project. Until last week, where i suddenly realized that it was a rather stupid practice. After all i&#8217;am running a system that comes preinstalled with named. [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I&#8217;am using my macbook pro with <a href="http://www.apachefriends.org/en/xampp-macosx.html" target="_blank">XAMPP</a> as my primary development workhorse, i&#8217;ve been playing around with the hosts file every single time I started a new project. Until last week, where i suddenly realized that it was a rather stupid practice. After all i&#8217;am running a system that comes preinstalled with named. Yeah i know, a bit late&#8230; But still, sat down for a few minutes to (re-)read about zone files and how to get an wildcard DNS server up and running.</p>
<p>The goal was to have *.dev.local pointing to 127.0.0.1 so i only needed to add/alter my apache vhosts.conf to fit my project needs.</p>
<p><span id="more-7"></span></p>
<h6>small hint upfront, # means a single line in your shell followed by a enter, and keep the terminal opened till the end.</h6>
<h3>Step 1</h3>
<p>Open your terminal and use the &#8216;sudo bash&#8217; command to become the super user, not really needed but I do hate typing sudo before every command. After becoming root, generate a new <strong>rndc.key</strong></p>
<pre class="brush:shell">#su -
#rndc-confgen -a -c /etc/rndc.key</pre>
<h3>Step 2</h3>
<p>Creating the actual zone file for your  .dev.local segment. I&#8217;am using textmate as editor on my mac, but you can use any other you like. If your OSX installation is still virgin, substitute <em>mate</em> with <em>nano</em> in the following lines</p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">#mate /var/named/db.dev.local</span></p>
<p>An empty file should be opened, now drop the zone config in it and save it.</p>
<pre class="brush:plain">dev.local. 7200    IN       SOA     dev.local. root.dev.local. (
					2008031801 ;    Serial
					15      ; Refresh every 15 minutes
					3600    ; Retry every hour
					3000000 ; Expire after a month+
					86400 ) ; Minimum ttl of 1 day
dev.local. IN      NS      dev.local.
dev.local. IN      MX      10 dev.local.
dev.local. IN      A       127.0.0.1
*.dev.local.	IN      A       127.0.0.1</pre>
<p>Please note the trailing dot  after the local! If you want your wildcard DNS to be something else, feel free to substitute it with something else. But keep in mind the trailing dot!</p>
<h3>Step 3</h3>
<p>Adding the zone to your named config</p>
<pre class="brush:shell">#mate /etc/named.conf</pre>
<p>Locate a section that starts with &#8216;zone &#8220;0.0.127.&#8217; and insert the  pointer to the freshly created zone file in between the 0.0.127 and logging zone.</p>
<pre class="brush:plain">added "/etc/named.conf"
zone "dev.local" IN {
        type master;
        file "/var/named/db.dev.local";
};</pre>
<pre class="brush:plain">So you end up with a zone file looking a bit like this</pre>
<pre class="brush:plain">
<pre class="brush:plain">zone "." IN {
        type hint;
        file "named.ca";
};

zone "localhost" IN {
        type master;
        file "localhost.zone";
        allow-update { none; };
};

zone "0.0.127.in-addr.arpa" IN {
        type master;
        file "named.local";
        allow-update { none; };
};

zone "dev.local" IN {
        type master;
        file "/var/named/db.dev.local";
};

logging {
        category default {
                _default_log;
        };

        channel _default_log  {
                file "/Library/Logs/named.log";
                severity info;
                print-time yes;
        };
};</pre>
</pre>
<h3>Step 4</h3>
<p>Firing the whole shabam up :)</p>
<p>Test if the config is right</p>
<pre class="brush:as3">#named-checkconf /etc/named.conf</pre>
<p>If it returns an error, solve it with logic. Most likely a typing error :)</p>
<p>Check if the zone is created correctly</p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">#named-checkzone dev.local /var/named/db.dev.local</span></p>
<p>that should return something simular to this</p>
<blockquote>
<div id="_mcePaste">/var/named/db.dev.local:7: using RFC1035 TTL semantics</div>
<div id="_mcePaste">zone dev.local/IN: loaded serial 2008031801</div>
<div id="_mcePaste">OK</div>
</blockquote>
<p>Once again if it fails, fix it using logic. Check for typing errors, first time i forgot one  those dreaded trailing dots</p>
<p>Finally adding it to your mac&#8217;s startup list, purely for convenience. If you are a memory freak feel free to start the named server only when needed, but i&#8217;am lazy and do not want to be bothered with it every single time i reboot. Which is about 4 times a year ;)</p>
<pre class="brush:plain">#launchctl load -w /System/Library/LaunchDaemons/org.isc.named.plist</pre>
<h3>Step 5</h3>
<p>The last part, tell your DNS config to use your local DNS before checking the big net for your domain.</p>
<p>Flush your systems DNS cache</p>
<pre class="brush:plain">#dscacheutil -flushcache</pre>
<p>You can safely close the super user shell now, we are done using our superpowers. Keep the shell open, cause the final test is done in a normal user shell.</p>
<p>Open your system preferences,and click network,  then advanced button.<br />
If needed add 127.0.0.1 to your server list with the + on left  and drag it to the top of the list. The other two DNS entries are pointers i created to <a title="openDNS" href="http://www.opendns.com/" target="_blank">opendns</a> because my ISP is not that good at running fast responding DNS servers.</p>
<p><a href="http://renebakx.nl/wp-content/uploads/2010/06/Screen-shot-2010-06-12-at-7.45.05-AM.png"><img class="alignnone size-medium wp-image-9" title="OSX DNS config" src="http://renebakx.nl/wp-content/uploads/2010/06/Screen-shot-2010-06-12-at-7.45.05-AM-300x234.png" alt="OSX DNS config" /></a></p>
<p>Do not set the search domain to the same name as your wildcard dns name, or you will end up looking at your local web server for every failed DNS lookup ;)</p>
<p>After pressing the OK button a few times, the final step is testing if it actually works</p>
<h3>Final step</h3>
<p>Testing if your new zone is dig&#8217;able</p>
<pre class="brush:plain">#dig myzone.dev.local</pre>
<p>where  <em>myzone</em> can be anything you want, cause well hey we are running a wildcard DNS here. The response should look a bit like this :</p>
<blockquote><p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">; &lt;&lt;&gt;&gt; DiG 9.6.0-APPLE-P2 &lt;&lt;&gt;&gt; myzone.dev.local</span></p>
<pre class="brush:plain">;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 53590
;; flags: qraa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;myzone.dev.local.			IN	A
;; ANSWER SECTION:
myzone.dev.local.		7200	IN	A	127.0.0.1
;; AUTHORITY SECTION:
dev.local.		7200	IN	NS	dev.local.
;; ADDITIONAL SECTION:
dev.local.		7200	IN	A	127.0.0.1
;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Jun 12 08:37:11 2010
;; MSG SIZE  rcvd: 77</pre>
</blockquote>
<h3>Bonus section, enabling the vhost in xampp</h3>
<p>I&#8217;am assuming you did a basic installation of xampp by dropping the package into the Applications folder like instructed</p>
<blockquote><p>Using the finder browse to /Applications/XAMPP/etc  and open the file called HTTPD.CONF in your favorite text editor.<br />
Locate the two commented lines for the virtual host, somewhere at the bottom around line number 469<br />
# Virtual hosts<br />
#Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf</p></blockquote>
<div>And remove the # before the Include and save the file.</div>
<div>Browse one level deeper into the XAMPP folder to /Applications/XAMPP/etc/extra and open the http-vhosts.conf file in the above mentioned favorite text editor and remove all the contents. Replace it with this</div>
<div>
<pre class="brush:plain">NameVirtualHost *:80

&lt;VirtualHost *:80&gt;
    DocumentRoot "/Users/rene/Sites/renebakx.nl"
    ServerName renebakx.dev.local
	&lt;Directory /Users/rene/Sites/renebakx.nl&gt;
	AllowOverride ALL
	&lt;/directory&gt;
&lt;/VirtualHost&gt;</pre>
</div>
<div>First part tells apache to listen to port 80, next block defines a virtual host that points to the mac default Sites folder, which i personally find more convenient to use then the docroot in XAMPP, for the renebakx.dev.local site.</div>
<div>Repeat only the &lt;VirtualHost&#8230;..&gt;&lt;/VirtualHost&gt; part for every other wildcard domain you need to setup.</div>
<div>(for more advanced features of the virtualhost directive, consult the <a title="Apache 2 manual" href="http://httpd.apache.org/docs/2.0/vhosts/">apache2</a> manual.</div>
<div>Restart the apache server using the xampp control application and point your browser to the freshly created site :)</div>
<h3>Rik&#8217;s bonus part</h3>
<p>Like mention below in the comments by Rik, using the vhost_alias module it&#8217;s even easier<del datetime="2010-06-13T11:28:01+00:00">However there is a small downside to it. I personally like my development folders named a bit like the site i&#8217;am working on. For example the contents of this site is in the &#8220;renebakx.nl&#8221; folder. vhost_alias uses the dot to calculate offsets in alias names. If you can live with the fact that your subdomain can not contain a dot, or you don&#8217;t mind replacing a dot with a dash. Feel free to swap the above mentioned vhost directives with something like this.</del></p>
<p>Boy was I wrong :) You can use multiple VirtualDocumentRoot rules. I ended up with a vhost configuration like this</p>
<pre class="brush:shell">&lt;VirtualHost *:80&gt;
	ServerName dev.local
	ServerAlias *.dev.local
	ServerAdmin webmaster@localhost
	VirtualDocumentRoot "/Users/rene/Sites/%1"
	VirtualDocumentRoot "/Users/rene/Sites/%-3+/"
	&lt;Directory /Users/rene/Sites/&gt;
		Options Indexes FollowSymLinks
		AllowOverride All
		Order allow,deny
		Allow from all
	&lt;/Directory&gt;
&lt;/Virtualhost&gt;</pre>
<p>As you can see, this point <em>whatever.dev.local</em> to &#8216;/Users/rene/Sites/whatever&#8217; and<em> somesite.nl.dev.local </em>points to &#8216;/Users/rene/Sites/somesite.nl&#8217;</p>
<p><strong>Now how awesome is that? :D</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://renebakx.nl/7/running-a-local-wildcard-dns-server-on-your-mac/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
