<?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>mFabrik - mobile sites, apps, HTML5 and CMS software development &#187; apache</title>
	<atom:link href="http://blog.mfabrik.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mfabrik.com</link>
	<description>Freedom delivered.</description>
	<lastBuildDate>Wed, 03 Aug 2011 09:47:41 +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>Sticky session load balancing with Apache and mod_balancer on Ubuntu Linux</title>
		<link>http://blog.mfabrik.com/2011/04/15/sticky-session-load-balancing-with-apache-and-mod_balancer-on-ubuntu-linux/</link>
		<comments>http://blog.mfabrik.com/2011/04/15/sticky-session-load-balancing-with-apache-and-mod_balancer-on-ubuntu-linux/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 08:19:25 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[plone]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[balancer]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[mod_balancer]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[sticky]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=1223</guid>
		<description><![CDATA[Apache 2.2 can do load balancing with sticky sessions. However, there is a catch. You need to use mod_headers module to set a cookie based on the chosen balancer member for the first request and then route the subsequent requests to this client. Use cases You are running a backend servers behind Apache You need [...]]]></description>
			<content:encoded><![CDATA[<p>Apache 2.2 can do load balancing with sticky sessions. However, there is a catch. You need to use mod_headers module to set a cookie based on the chosen balancer member for the first request and then route the subsequent requests to this client.</p>
<p>Use cases</p>
<ul>
<li>You are running a backend servers behind Apache</li>
<li>You need to make sure that the users are served from the same backend every time: the backend itself caches or stores user specific data and this data is not shared across the backends. <a href="http://stackoverflow.com/questions/5650716/are-sticky-sessions-needed-when-load-balancing-plone-3-3-5/5656295#5656295">For example, Plone 3 may have issues with content item creation if sticky sessions are not used</a>.</li>
</ul>
<p>The method described here works in every situation and does not rely on client IP address, etc. The only downside is that if one balancer member goes down all subsequent requests for it will die. So this method can be only used for load balancing, not for high availability (I am not sure if BALANCER_ROUTE_CHANGED environment variable is set when a balancer member is lost and would redirect the clients to a new balancer member).</p>
<p>This requests were tested on Ubuntu Linux, but may as well work in other environments.</p>
<h2>Setting route configution in virtual host</h2>
<p>Create a balancer</p>
<pre>&lt;Proxy balancer://yourlb&gt;
 BalancerMember http://127.0.0.1:13001/ route=1
 BalancerMember http://127.0.0.1:13002/ route=2
 BalancerMember http://127.0.0.1:13003/ route=3
 BalancerMember http://127.0.0.1:13004/ route=4
&lt;/Proxy&gt;</pre>
<p>Set the cookie using mod_headers. Note that the cookie must be in format [session name].[route id] (the dot is required). It seems to be possible to leave session name empty.</p>
<pre>Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED</pre>
<p>Make ProxyPass  follow the cookie (Zope virtual host monster style with HTTPS)</p>
<pre>ProxyPass / balancer://lbsits/http://localhost/VirtualHostBase/https/yoursite.org:443/yourplonesiteid/VirtualHostRoot/ stickysession=ROUTEID</pre>
<p><em>Note: Hard restart is required. apache2ctl graceful is not enough to make new balancer rules effective.<br />
</em></p>
<h2>Testing</h2>
<p>Use wget</p>
<pre>wget -S https://yoursite.org/</pre>
<p>See that Set-Cookie: ROUTE_ID is present and it contains a valid value (is not empty)</p>
<pre>HTTP/1.1 200 OK
 Date: Wed, 13 Apr 2011 15:21:52 GMT
 Server: Zope/(Zope 2.10.9-final, python 2.4.5, linux2) ZServer/1.1 Plone/3.3.3
 Content-Length: 23197
 Expires: Sat, 01 Jan 2000 00:00:00 GMT
 Content-Type: text/html;charset=utf-8
 Content-Language: en
 Set-Cookie: I18N_LANGUAGE="en"; Path=/
 Set-Cookie: ROUTEID=.1; path=/</pre>
<h2>More info</h2>
<ul>
<li><a href="http://blog.mfabrik.com/2011/03/21/session-affinity-sticky-with-nginx-load-balancing/">Sticky sessions with Nginx</a></li>
<li><a href="http://httpd.apache.org/docs/trunk/mod/mod_proxy_balancer.html#example">mod_proxy_balancer example</a></li>
<li><a href="http://collective-docs.plone.org/hosting/apache.html">Misc. Apache docs for Plone</a></li>
</ul>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/04/15/sticky-session-load-balancing-with-apache-and-mod_balancer-on-ubuntu-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copy/move phpBB3 forum from a server to another computer (Ubuntu/Linux)</title>
		<link>http://blog.mfabrik.com/2011/03/30/copymove-phpbb3-forum-from-a-server-to-another-computer-ubuntulinux/</link>
		<comments>http://blog.mfabrik.com/2011/03/30/copymove-phpbb3-forum-from-a-server-to-another-computer-ubuntulinux/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 13:40:11 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache2ctl]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[hosts]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[move]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[phpbb]]></category>
		<category><![CDATA[phpbb3]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=1179</guid>
		<description><![CDATA[Here are short instructions what you need to do in order to move / copy phpBB3 forum. Prerequisites What you need in order to benefit from these instructions Basic UNIX command-line knowledge SSH access to the server MySQL access to the database LAMP stack ready on the new server These instructions have been tested on [...]]]></description>
			<content:encoded><![CDATA[<p>Here are short instructions what you need to do in order to move / copy phpBB3 forum.</p>
<h2>Prerequisites</h2>
<p>What you need in order to benefit from these instructions</p>
<ul>
<li>Basic UNIX command-line knowledge</li>
<li>SSH access to the server</li>
<li>MySQL access to the database</li>
<li>LAMP stack ready on the new server</li>
</ul>
<p>These instructions have been tested on Ubuntu/Debian/Linux but they should work in other environments too.</p>
<h2>Write down database access information</h2>
<p>Get password from config.php file on the old server:</p>
<pre>cd /var/www/phpBB3
cat config.php</pre>
<p>Write down database name, username and password.</p>
<h2>Copy files</h2>
<p>Use rsync to remotely copy forum files to a new computer. On new computer, in /var/www folder</p>
<pre>rsync -av --compress-level=9 user@oldserver.com:/var/www/phpBB3 .</pre>
<h2>Dump and copy database</h2>
<p>Execute the following command on the new server. It takes SSH connection to the old server and dumps phpBB3 database to the new server over the SSH connection.</p>
<pre>ssh user@oldserver.com -C -o CompressionLevel=9 mysqldump -u databaseuser --password=databasepassword --skip-lock-tables --add-drop-table databasename &gt; phpbb3.sql</pre>
<h2>Create a new database</h2>
<p>Use the old access information from config.php to create a database with identical access information on the new server. You need a MySQL root access to create new databases.</p>
<pre>mysql -uroot -p</pre>
<p>Create database and grant access to phpBB3 user for it.</p>
<pre>mysql&gt; create database databasename;</pre>
<pre>mysql&gt; GRANT ALL ON databasename.* TO 'databaseuser'@'localhost' identified by 'databasepassword';</pre>
<p>Load the database on the new server from the dump file:</p>
<pre>mysql&gt; connect databasename;</pre>
<pre>mysql&gt; source phpbb3.sql</pre>
<h2>Configure Apache virtualhost for the new server</h2>
<p>The last step is to set-up Apache virtual host on the new server, so you can access the phpBB3 using a domain name. Note that this doesn&#8217;t need to be a real domain name, but you can spoof the domain name using /etc/hosts file on your local workstation.</p>
<p>Add file <em>/etc/apache2/sites-enabled/phpbb3.conf</em> (or pick a filename based on forum name if you host multiple forums)</p>
<pre>&lt;VirtualHost *&gt;
 ServerName yourdomainname.com

 DocumentRoot /var/www/phpBB3
 &lt;Directory /&gt;
   Options FollowSymLinks
   AllowOverride None
 &lt;/Directory&gt;

&lt;/VirtualHost&gt;</pre>
<p>Note that &lt;virtualhost *&gt; may change depending on how Apache has been set up to listen IP addresses and ports. Also if you are using a shared hosting package or VPS you might need to use the server control panel (cPanel) to do this step.</p>
<p>Then check if your new config file is ok and restart Apache:</p>
<pre>apache2ctl configtest
apache2ctl graceful</pre>
<h2>Hosts spoofing trick</h2>
<p>If you are not having a DNS server of your own which you can use for the copy you can always use <a href="http://webandmobile.mfabrik.com/docs/web-and-mobile/user-manual/installation#modifying-your-local-hosts-file">/etc/hosts file trick </a>to spoof domain names. This way you can make Apache to serve the forum from the server even if the forum is not connected to any real domain name yet.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/03/30/copymove-phpbb3-forum-from-a-server-to-another-computer-ubuntulinux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable PHP log output (error_log) on XAMPP on OSX</title>
		<link>http://blog.mfabrik.com/2011/03/16/enable-php-log-output-error_log-on-xampp-on-osx/</link>
		<comments>http://blog.mfabrik.com/2011/03/16/enable-php-log-output-error_log-on-xampp-on-osx/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 21:29:18 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[error_log]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[tail]]></category>
		<category><![CDATA[xampp]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=1124</guid>
		<description><![CDATA[If you are using XAMPP to develop PHP software (WordPress, Joomla!) on OSX you might want to get some advanced logging output from your code. PHP provides nice error_log() function, but it is silent by default. Here are short instructions how to enable it and follow the log. Use your favorite editor to edit php.ini [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using <a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a> to develop PHP software (WordPress, Joomla!) on OSX you might want to get some advanced logging output from your code. PHP provides nice <a href="http://php.net/manual/en/function.error-log.php">error_log</a>() function, but it is silent by default. Here are short instructions how to enable it and follow the log.</p>
<p>Use your favorite editor to edit php.ini file in <em>/Applications/XAMPP/etc/php.ini</em> &#8211; sudo priviledges needed, <a href="http://www.peterborgapps.com/smultron/">Smultron</a> does it out of the box.</p>
<p>Change lines:</p>
<pre>log_errors = Off</pre>
<pre>;error_log = filename</pre>
<p>To:</p>
<pre>log_errors = on</pre>
<pre>error_log = /tmp/php.log</pre>
<p>Restart Apache using <em>XAMPP controller</em> in <em>Finder -&gt; Applications</em>.</p>
<p>Now use the following UNIX command to see continuous log flow in your terminal:</p>
<pre>tail -f /tmp/php.log
</pre>
<p>See also the earlier article about <a href="http://blog.mfabrik.com/2010/12/22/local-xampp-development-and-unix-file-permissions/">XAMPP and file permissions</a>.
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/03/16/enable-php-log-output-error_log-on-xampp-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Apache virtual hosts behind Varnish</title>
		<link>http://blog.mfabrik.com/2011/03/04/setting-up-apache-virtual-hosts-behind-varnish/</link>
		<comments>http://blog.mfabrik.com/2011/03/04/setting-up-apache-virtual-hosts-behind-varnish/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 10:44:28 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[plone]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[listen]]></category>
		<category><![CDATA[namevirtualhost]]></category>
		<category><![CDATA[ports]]></category>
		<category><![CDATA[static media]]></category>
		<category><![CDATA[varnish]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=1058</guid>
		<description><![CDATA[Varnish is a very fast front end cache server. You might want to use it at the front of Apache to speed up loading of your static pages and static media, for example for your WordPress blog. You can also use Varnish backends to multiplex the requests between Plone and Apache based PHP software running [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.varnish-cache.org/">Varnish</a> is a very fast front end cache server. You might want to use it at the front of Apache to speed up loading of your static pages and static media, for example for your WordPress blog. You can also use Varnish backends to multiplex the requests between Plone and Apache based PHP software running on the same server using different <em>backend</em> directives.</p>
<p>However if you wish to use Apache virtual hosts with Varnish there is a trick in it.</p>
<p>We use the following setup</p>
<ul>
<li>Varnish listens to port 80, HTTP</li>
<li>Apache listens to port 81</li>
<li>Varnish uses Apache as a backend</li>
</ul>
<p>The related <em>varnish.vcl</em> is</p>
<pre>backend backend_apache {
.host = "127.0.0.1";
.port = "81";
}

sub vcl_recv {
 ...
 elsif (req.http.host ~ "^blog.mfabrik.com(:[0-9]+)?$") {
    set req.backend = backend_apache;
 }
 ...
}</pre>
<p>Note that the backend IP is 127.0.0.1 (localhost). By default, with Debian or Ubuntu Linux, Apache configuration does not do virtual hosting for this.</p>
<p>So if <em>/etc/apache2/sites-enabled/blog.mfabrik.com </em>looks like:</p>
<pre>&lt;VirtualHost *:81&gt;

 ServerName blog.mfabrik.com
 ...
 LogFormat       combined
 TransferLog     /var/log/apache2/blog.mfabrik.com.log

 ...

 ExpiresActive On
 ExpiresByType image/gif A3600
 ExpiresByType image/png A3600
 ExpiresByType image/image/vnd.microsoft.icon A3600
 ExpiresByType image/jpeg A3600
 ExpiresByType text/css A3600
 ExpiresByType text/javascript A3600
 ExpiresByType application/x-javascript A3600
&lt;/VirtualHost&gt;</pre>
<p>And now the trick &#8211; you need to add the following to <em>/etc/apache2/httpd.conf</em></p>
<pre>NameVirtualHost *:81</pre>
<p>Unless you do all this, Apache will just pick the first virtualhost file in <em>/etc/apache2/sites-enabled</em> and use it for all requests.</p>
<p>Also you need to edit ports.conf and change Apache to listen to port 81:</p>
<pre>Listen 81</pre>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/03/04/setting-up-apache-virtual-hosts-behind-varnish/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Importing Apache log file with performance information into OpenOffice / Excel using Python script</title>
		<link>http://blog.mfabrik.com/2011/01/24/importing-apache-log-file-with-performance-information-into-openoffice-excel-using-python-script/</link>
		<comments>http://blog.mfabrik.com/2011/01/24/importing-apache-log-file-with-performance-information-into-openoffice-excel-using-python-script/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 16:47:42 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[plone]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[analyse]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[microsoft excel]]></category>
		<category><![CDATA[openoffice.org calc]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[pyexcelerator]]></category>
		<category><![CDATA[shlex]]></category>
		<category><![CDATA[zodb]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=907</guid>
		<description><![CDATA[You can enhance Apache log files to include performance information, like read/sent bytes and HTTP request processing time. Compared to load tool (JMeter) generated data this information is usually easier to acquire and reflects the actual production server usage patterns. I think there even exist tools to replay the log data to rerun the load [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.mfabrik.com/2010/12/21/enhanced-apache-logging-request-duration-balancer-member-transferred-bytes/">You can enhance Apache log files to include performance information, like read/sent bytes and HTTP request processing time</a>. Compared to load tool (JMeter) generated data this information is usually easier to acquire and reflects the actual production server usage patterns. I think there even exist tools to replay the log data to rerun the load in simulation mode. This, however, works only on systems whose state can be reseted to the original situation (<a href="http://www.zodb.org/">like with ZODB transactional database</a>).</p>
<p>Below is an example Python script snippet which reads this custom Apache log file and creates Excel export out of it. After this, you can easily open this file in OpenOffice Calc or Microsoft Excel and draw nice diagrames out of it to see where the performance bottlenecks are.</p>
<p>The script splits duration column for the output file. You can easily add your own splits or use Calc&#8217;s Text to Columns editor.</p>
<p>The script:</p>
<pre>#!/bin/python

import shlex
from pyExcelerator.Workbook import Workbook

FILE = "/var/log/apache2/yourlogfile.log"

def get_parts(line):
	""" Extract the parts of a line"""

	parts = shlex.split(line) # Split reserving parts inside quotation marks
	# 'duration:0/42327', 'io:643/4507', 'balancer:http://127.0.0.1:13003/']

	return parts

def get_duration(duration):
	""" Extract duration in ms from log line """

	keyword, args = duration.split(":")
	seconds, microseconds = args.split("/")

	mseconds = int(microseconds) 

	return mseconds

wb = Workbook()
sheet = wb.add_sheet('0')

print "Reading log"
i = 0

for line in open(FILE, "rt"):
	parts = get_parts(line)
	j = 0

	for part in parts:
		sheet.write(i,j,part)
		j += 1
         	sheet.write(i,len(parts)+1,get_duration(parts[-3]))
	i += 1

wb.save('output.xls')</pre>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2011/01/24/importing-apache-log-file-with-performance-information-into-openoffice-excel-using-python-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Local XAMPP development and UNIX file permissions</title>
		<link>http://blog.mfabrik.com/2010/12/22/local-xampp-development-and-unix-file-permissions/</link>
		<comments>http://blog.mfabrik.com/2010/12/22/local-xampp-development-and-unix-file-permissions/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 17:13:30 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[chgrp]]></category>
		<category><![CDATA[chown]]></category>
		<category><![CDATA[documentroot]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[unix file permissions]]></category>
		<category><![CDATA[xampp]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=888</guid>
		<description><![CDATA[If you are using XAMPP Apache+MySQL+PHP stack to develop web applications on your OSX or Linux computer you might want to fiddle with Apache settings to make your life easier. By default XAMPP users nobody user for running Apache. If you try to load any file created by your normal system user Apache will give [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using <a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a> Apache+MySQL+PHP stack to develop web applications on your OSX or Linux computer you might want to fiddle with Apache settings to make your life easier.</p>
<p>By default XAMPP users nobody user for running Apache. If you try to load any file created by your normal system user Apache will give access denied error. This means that either you must make all PHP files readable for everyone, or change the file owner. This is painful if you need to repeat the process for every file.</p>
<p>Instead, it is easier to make XAMPP run under the permissions of your local user.</p>
<p>Edit<em> /Applications/XAMPP/etc/httpd.conf</em>:</p>
<pre>
<div id="_mcePaste">&lt;IfModule !mpm_winnt_module&gt;</div>
<div id="_mcePaste">&lt;IfModule !mpm_netware_module&gt;</div>
<div id="_mcePaste">User yourusername</div>
<div id="_mcePaste">Group staff</div>
<div id="_mcePaste">&lt;/IfModule&gt;</div>
<div id="_mcePaste">&lt;/IfModule&gt;</div>

&lt;IfModule !mpm_winnt_module&gt;&lt;IfModule !mpm_netware_module&gt;</pre>
<pre>DocumentRoot "/Users/yourusername/yoursiteroot"</pre>
<p>You also need to change the location of setting default folder execution rights htdocs location to your development location</p>
<pre>#
# This has been changed from /Applications/XAMPP/htdocs
#
&lt;Directory "/Users/moo/code/joomla/mobilejoomla_dev"&gt;
    Options Indexes FollowSymLinks ExecCGI Includes
   AllowOverride All</pre>
<pre>&lt;/Directory&gt;</pre>
<p>And now Apache will happily eat all files you create or edit.
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2010/12/22/local-xampp-development-and-unix-file-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enhanced Apache logging: request duration, balancer member, transferred bytes</title>
		<link>http://blog.mfabrik.com/2010/12/21/enhanced-apache-logging-request-duration-balancer-member-transferred-bytes/</link>
		<comments>http://blog.mfabrik.com/2010/12/21/enhanced-apache-logging-request-duration-balancer-member-transferred-bytes/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 18:24:02 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[technology]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[balancer]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=886</guid>
		<description><![CDATA[This helps you to diagnose problems on the production environment if you are running Apache or Apache mod_balancer. Put to your &#60;virtualhost&#62; # timestamp referer useragent, server time seconds/microseconds, transfered bytes input/output, which balancer was used LogFormat "%h %l %u %t \"%r\" %&#62;s %b \"%{Referer}i\" \"%{User-Agent}i\" duration:%T/%D io:%I/%O balancer:%{BALANCER_WORKER_NAME}e" TransferLog     /var/log/apache2/yoursite.log More info [...]]]></description>
			<content:encoded><![CDATA[<p>This helps you to diagnose problems on the production environment if you are running Apache or Apache mod_balancer. Put to your &lt;virtualhost&gt;</p>
<pre>
<div id="_mcePaste"># timestamp referer useragent, server time seconds/microseconds, transfered bytes input/output, which balancer was used</div>
<div id="_mcePaste">LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\" duration:%T/%D io:%I/%O balancer:%{BALANCER_WORKER_NAME}e"</div>
<div id="_mcePaste">TransferLog     /var/log/apache2/yoursite.log</div>

<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">More info</span></pre>
<ul>
<li><a href="http://www.ducea.com/2008/02/06/apache-logs-how-long-does-it-take-to-serve-a-request/">http://www.ducea.com/2008/02/06/apache-logs-how-long-does-it-take-to-serve-a-request/</a></li>
</ul>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2010/12/21/enhanced-apache-logging-request-duration-balancer-member-transferred-bytes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install Joomla! on your Ubuntu/Linux server with basic security</title>
		<link>http://blog.mfabrik.com/2010/05/31/how-to-install-joomla-on-your-ubuntulinux-server-with-basic-security/</link>
		<comments>http://blog.mfabrik.com/2010/05/31/how-to-install-joomla-on-your-ubuntulinux-server-with-basic-security/#comments</comments>
		<pubDate>Mon, 31 May 2010 09:13:36 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[email. chmod]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[virtualhost]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=540</guid>
		<description><![CDATA[This how to shorty explains how to set-up a Joomla! hosting on a shared hosting server you own to have basic security. This instructions apply for Debian/Ubuntu based systems, but can be generalized to any Linux based system like Fedora. In this how to we use the following software versions Joomla 1.5 Apache 2.2 MySQL [...]]]></description>
			<content:encoded><![CDATA[<div>This how to shorty explains how to set-up a Joomla! hosting on a shared hosting server you own to have basic security. This instructions apply for Debian/Ubuntu based systems, but can be generalized to any Linux based system like Fedora.</div>
<div>In this how to we use the following software versions</div>
<div>
<ul>
<li>Joomla 1.5</li>
<li>Apache 2.2</li>
<li>MySQL 5.1</li>
<li>Ubuntu 8.04 Hardy Heron server edition</li>
</ul>
</div>
<p>The instructions may apply for other versions too.</p>
<h2>Prerequisitements</h2>
<p>What you need to have in order to use this how to</p>
<ul>
<li>Basic UNIX file permissions knowledge</li>
<li>Basic UNIX shell knowledge</li>
<li>You have a Linux server (Ubuntu / Debian) for which you have root user access and you plan to use this server to host one or several Joomla! sites</li>
<li>Apache and MySQL instaleld on your server</li>
</ul>
<h2>User setup<br />
<span style="font-weight: normal; font-size: 13px;"> </span></h2>
<h2><span style="font-weight: normal; font-size: 13px;">Set-up an UNIX user on a dedicated server for Joomla! hosting. The user can SSH in the box and write to his home folder, /tmp and /var/www site folder.</span></h2>
<p><span style="font-weight: normal; font-size: 13px;">We create a user called &#8220;user&#8221; in this instructions. Replace it with the username you desire. We also use the example site name (www).yoursite.com.</span></p>
<div>Create new UNIX user and /home/user folder.</div>
<pre>sudo adduser user # Asks for the password and created /home/user</pre>
<div>Create corresponding /var/www/user folder.</div>
<pre>sudo mkdir /var/www/user
sudo chmod -R user:user /var/www/user # Only user has writing access to this folder</pre>
<h2>Setup MySQL user account</h2>
<p>Install MySQL as per Debian/Ubuntu instructions.</p>
<p>Login as MySQL admin user (may vary depending how your MySQL is configured). Note that first you will be asked for <em>sudo</em> password, then for MySQL administrative user password.</p>
<pre>sudo mysql -u admin -p</pre>
<div>Then create a new database with the same name as new as the UNIX user. Make sure that we use UTF-8 character encoding so we avoid irritating encoding problems in the future.</div>
<pre>CREATE DATABASE user DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;</pre>
<div>Create a MySQL user with the same name as the UNIX user. Use  a random password and give it all rights for the database. Note that this password should differ from the UNIX username password as this must be stored as plain-text in Joomla PHP files. Also MySQL differs users whether they came from localhost or other IP address. Here we use localhost so that the database is connectable only from the same server as  Apache is running.</div>
<pre>GRANT ALL ON user.* TO 'user'@'localhost' identified by 'zxc123zxc';<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;"> </span></pre>
<h2>Extract Joomla! installation files</h2>
<p><span style="font-size: x-small;"><span style="font-size: small;"><span>Enter the folder which will contain web site PHP files.</span></span></span></p>
<pre>sudo -i -u user # pose yourself as UNIX user who runs the site</pre>
<pre>cd /var/www/user</pre>
<div>Load the latest Joomla! source code to the server using wget command. Check <a href="http://www.joomla.org/download.html">the download URL from joomla.org web site</a>.</div>
<pre>wget http://joomlacode.org/gf/download/frsrelease/12350/51111/Joomla_1.5.18-Stable-Full_Package.zip</pre>
<div>Unzip it.</div>
<div>
<pre>unzip Joomla_1.5.18-Stable-Full_Package.zip</pre>
<p>Exit posing yourself as user UNIX user.</p>
<pre>exit</pre>
</div>
<h2>Set file permission</h2>
<div>In order to secure your server</div>
<div>
<ul>
<li>Configuration files and upload directory must be writable by Apache user (www-data for Ubuntu/Debian, httpd for Fedora/Red Hat)</li>
<li>Other .php files should be read-only</li>
</ul>
</div>
<p>Note that during Joomla&#8217;s browser based installation Apache&#8217;s <em>www-data</em> must have write access to folder in order to create configuration.php file. We will later remove this access right.</p>
<p>We will set Joomla! files under UNIX group group www-data so that Apache can read them. Certain files are set to be writable. This must be done as root user.</p>
<pre>sudo chown -R user:www-data /var/www/user # Make user group to www-data</pre>
<pre>sudo chmod g+wrx /var/www/user # Read only access to www-data user. Write access for installation, will be later removed.</pre>
<p>Now <em>ls -l</em> command in /var/www/user should give you something like this for fil masks:</p>
<pre>drwxr-xr-x 11 user www-data    4096 2010-05-28 10:22 plugins
-rwxr--r--  1 user www-data     304 2010-05-28 10:21 robots.txt
drwxr-xr-x  6 user www-data    4096 2010-05-28 10:22 templates</pre>
<h2>Creating Apache configuration</h2>
<div>This allows serving Joomla! by Apache and starting the browser based configuration.</div>
<div>First create Apache configuration file under <em>/etc/apache2/sites-enabled</em> as root user. We assume <em>nano</em> terminal base text editor is installed on the server.</div>
<pre>sudo nano /etc/apache2/sites-enabled/yoursite.conf</pre>
<div>Below is a sample configuration file. You may need to match your server public IP in &lt;virtualhost, so that Apache knows for which IP address sites are served. We use virtual hosting: every site on the server is identified by incoming HTTP request.</div>
<div><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">&lt;VirtualHost *&gt;</span></div>
<pre>   ServerName yoursite.com
   ServerAlias www.yoursite.com
   ServerAdmin info@yourcompany.com

   LogFormat       combined
   TransferLog     /var/log/apache2/yoursite.log

   # Make sure this virtual host if capable of executing PHP5
   Options +ExecCGI
   AddType application/x-httpd-php .php .php5

   # Point to www folder where Joomla! is extracted
   DocumentRoot /var/www/yoursite

   # Do not give illusion of safety
   # as PHP safe_mode really is a crap
   # and only causes problems
   php_admin_flag safe_mode off

   #
   # This entry will redirect traffic www.yoursite.com -&gt; yoursite.com
   # Assume mod_rewrite is installed and enabled on Apache
   # 301 is HTTP Permanent Redirect code
   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC]
   RewriteRule (.*) http://yoursite.com$1 [L,R=301]

&lt;/VirtualHost&gt;</pre>
<h2><span style="font-weight: normal;">Faking the DNS entry</span></h2>
<div>If you have not yet reserved a domain name for your site, but still want to get the virtual host working, you can add a DNS name entry into a <a href="http://en.wikipedia.org/wiki/Hosts_file">hosts</a> file on your local computer. The following assumes you are using Ubuntu desktop, but <em>hosts </em>file is available on Windows and OSX too.</div>
<pre>sudo gedit /etc/hosts</pre>
<div>Then add the lines like the example below. Do not forget to remove this from <em>hosts</em> file when the actual DNS has been set up.</div>
<pre># Force this hostname to go to your server public IP address from your local computer</pre>
<pre>123.123.123 yoursite.com www.yoursite.com</pre>
<h2>Start Joomla! browser based installation</h2>
<div>Then enter the URL of your site to the browser:</div>
<pre>http://yoursite.com</pre>
<div>Joomla! installation page should appear.</div>
<div>
<ul>
<li>Fill in MySQL database values as created before.</li>
<li>If you plan to use SSH for file transfer do not enable FTP layer (unsecure).</li>
<li>Use a random password as Joomla! administrator user and store it somewhere in safe.</li>
<li>When Joomla! browser based installation goes to the point it asks you to remove the installation directory follow the instructions below.</li>
</ul>
</div>
<h2 style="font-size: 1.5em;">Secure the configuration</h2>
<div>Now remove extra permissions from Apache&#8217;s www-data user so that in the case there is a PHP / Joomla security hole, your site files cannot get compromised.</div>
<div>Some folders must remain writable as Joomla! will upload or write files in them.</div>
<pre>sudo chmod -R g-w /var/www/user # Remote write permission
sudo rm -rf /var/www/user/installation # Remove installation directory
# Add write permission to folders which contain writable files
sudo chmod -R g+x /var/www/user/logs
sudo chmod -R g+x /var/www/user/images
sudo chmod -R g+x /var/www/user/tmp
sudo chmod -R g+x /var/www/user/images</pre>
<h2>Setting up htaccess files</h2>
<p>Joomla! comes with a sample htaccess file which has some security measurements by having RewriteRules to prevent malformed URL access.</p>
<p>To install this file do the following</p>
<pre>sudo -i
cd /var/www/user
cp htaccess.txt .htaccess
chmod user:www-data .htaccess # Set file permission to be readable by Apache and writable by the UNIX user</pre>
<p>Then we create a .htaccess file which we will place in all folders with Joomla! write access to prevent execution of PHP files in these folders. First we create htaccess.limited file which we use as a template.</p>
<pre>sudo -i
cd /var/www/user
nano htaccess.limited # Open text editor</pre>
<p>Use the following htaccess.limited content</p>
<pre># secure directory by disabling script execution
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI -Indexes</pre>
<p>And put the master template htaccess.limited  to proper places</p>
<pre>cp htaccess.limited media/.htaccess
chown -R user:www-data media/.htaccess 

cp htaccess.limited tmp/.htaccess
chown -R user:www-data tmp/.htaccess 

cp htaccess.limited logs/.htaccess
chown -R user:www-data logs/.htaccess

cp htaccess.limited images/.htaccess
chown -R user:www-data images/.htaccess</pre>
<h2>Start using the site</h2>
<div>Now go to your site with the browser again and Joomla! start page should come up.</div>
<div>Login as administration account you gave in Joomla! browser based installation.</div>
<div>Type URL <em>http://yoursite.com</em> in your browser.</div>
<h2>Setting outgoing email</h2>
<div>This is probably first thing you want to do as Joomla! administrator. You configure the SMTP server which will be used for outgoing email. The server  is usually provided by network operator who provides the internet connection for your server.</div>
<div>Login as Joomla! administrator user.</div>
<div>Go to Site  -&gt; Global Configuration -&gt; Server.</div>
<div>Choose SMTP mail mode.</div>
<div>Enter SMTP details.</div>
<h3>Test outgoing email</h3>
<div>Create a new user with an email address you control The user should receive <em>New User Details</em> email message from the site on the moment the user is created.</div>
<h2>Maintaining file permission</h2>
<div>If you modify or create any files (e.g. upload a new theme) to your server you need to set file permissions for it.</div>
<div>
<ul>
<li>UNIX  user: <em>user (</em>your site username)</li>
<li>UNIX group: <em>www-data</em></li>
</ul>
</div>
<div>To make it possible to set the group ownership with user user you first need to add it to www-data group.</div>
<div>
<pre>sudo usermod -a -G www-data user # Add user to www-data group so that it can set group permissions</pre>
</div>
<div>Then you can fix the permissions for uploaded files (templates and libraries folders assumed)</div>
<pre>sudo -i -u user # Login as your UNIX user
chgrp -R www-data templates libraries # Fix group ownership
chmod -R g+rx libraries templates # Set read access for the group</pre>
<div>This way secure file permissions are fixed after files have been changed. Alternatively, if your secure SFTP program supports setting permissions during the file upload, you can use that option</div>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2010/05/31/how-to-install-joomla-on-your-ubuntulinux-server-with-basic-security/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Integrating and theming WordPress with your CMS site using XDV</title>
		<link>http://blog.mfabrik.com/2010/03/28/integrating-and-theming-wordpress-with-your-cms-site-using-xdv/</link>
		<comments>http://blog.mfabrik.com/2010/03/28/integrating-and-theming-wordpress-with-your-cms-site-using-xdv/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 12:48:17 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[plone]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[xdv]]></category>
		<category><![CDATA[zope]]></category>
		<category><![CDATA[deliverance]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[locationmatch]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[theming]]></category>
		<category><![CDATA[virtualhost]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xsl]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=421</guid>
		<description><![CDATA[Introduction XDV is an external HTML theming engine, a.k.a. theming proxy, which allows you to mix and match HTML and CSS from internal and external sites by using simple XML rules. It separates the theme development from the site development, so that people with little HTML and CSS knowledge can create themes without need to [...]]]></description>
			<content:encoded><![CDATA[<div id="xdv-theming">
<div>
<h1><a id="introduction" name="introduction" href="http://www.tele3.cz/jbar/rest/render.py#id1">Introduction</a></h1>
<p>XDV is an external HTML theming engine, a.k.a. theming proxy, which allows you to mix and match HTML and CSS from internal and external sites by using simple XML rules. It separates the theme development from the site development, so that people with little HTML and CSS knowledge can create themes without need to know underlying Python, PHP or whatever. It also enables integration of different services and sites to one, unified, user experience. For example, XDV is used by <cite>plone.org &lt;http://plone.org&gt;</cite> to integrate Plone CMS and Trac issue tracker.  XDV compiles theming rules to XSL templates, which has been a standard XML based templates language since 1999. XSL has good support in every programming language and web server out there. Example backends to perform XSL transformation include</p>
<ul>
<li>Python and lxml library</li>
<li>Apache&#8217;s mod_transform</li>
<li>nginx web server</li>
<li>All XSL capable Java and .NET software out there</li>
</ul>
<p>XDV theming can be used together with Plone where enhanced support is provided by <a href="http://pypi.python.org/pypi/collective.xdv">collective.xdv package</a> package. Technically, collective.xdv adds Plone settings panel and does XSL transformation in Zope&#8217;s post-publication hook using lxml library.  XDV can be used standalone with <a href="http://pypi.python.org/pypi/xdv/0.3a2">XDV package</a> to theme any web site, let it be WordPress, Joomla, Drupal or custom in-house PHP solution from year 2000.  XDV is based on <a href="http://deliverance.openplans.org/">Deliverance specification</a> The difference between XDV and Deliverance reference implementation is that XDV internally compiles themes to XSL templates, when Deliverance relies on processing HTML in Python. Currently XDV approach seems to be working better, as we had many problems trying to apply Deliverance for WordPress site (redirects didn&#8217;t work, HTTP posts didn&#8217;t work, etc.).</p>
</div>
<div>
<h1><a id="tutorials" name="tutorials" href="http://www.tele3.cz/jbar/rest/render.py#id3">Tutorials</a></h1>
<ul>
<li><a href="http://plone.org/products/collective.xdv/documentation/reference-manual/theming">http://plone.org/products/collective.xdv/documentation/reference-manual/theming</a></li>
<li><a href="http://pypi.python.org/pypi/collective.xdv">http://pypi.python.org/pypi/collective.xdv</a></li>
<li><a href="http://pypi.python.org/pypi/xdv">http://pypi.python.org/pypi/xdv</a></li>
<li><a href="http://pypi.python.org/pypi/dv.xdvserver">http://pypi.python.org/pypi/dv.xdvserver</a> (with WSGI)</li>
</ul>
</div>
<div>
<h1><a id="setting-up-xdv-development-tools" name="setting-up-xdv-development-tools" href="http://www.tele3.cz/jbar/rest/render.py#id4">Setting up XDV development tools</a></h1>
<p>XDV tools are deployed as Python eggs. You can use tools like <cite>buildout &lt;http://www.buildout.org/&gt;</cite> configuration and assembly tool or easy_install to get XDV on your development computer and the server.  If you are working with Plone you can integrate XDV to your site existing buildout. If you are not working with Plone, <a href="http://pypi.python.org/pypi/xdv#installation">XDV home page</a> has instructions how to deploy XDV command standalone.</p>
</div>
<div>
<h1><a id="xdv-rules" name="xdv-rules" href="http://www.tele3.cz/jbar/rest/render.py#id5">XDV Rules</a></h1>
<p>Rules (rules.xml) will tell how to fit content from external source to your theme HTML.  It provides straightforward XML based syntax to manipulate HTML easily</p>
<ul>
<li>Append, replace and drop HTML pieces</li>
<li>Insert HTML snippets</li>
<li>CSS or XPath selectors can be used to identify HTML parts</li>
<li>It is possible to mix and match content from more than two sites</li>
<li>etc.</li>
</ul>
<p>Rules XML syntax is documented at <a href="http://pypi.python.org/pypi/xdv">XDV homepage</a>.  Rules will be compiled to XSL template (theme.xsl) by <em>xdvcompiler</em> command. The actual theming is done by one of the XSL backends listed above, by taking HTML as input and applying XSL transformations on it.  Note that currently rules without matching selectors are silently ignored and there is no bullet-proof way to debug what happens inside XSL transformation, except by looking into compiled theme.xsl.</p>
</div>
<div>
<h1><a id="using-xdv-to-theme-and-integrate-a-wordpress-site" name="using-xdv-to-theme-and-integrate-a-wordpress-site" href="http://www.tele3.cz/jbar/rest/render.py#id6">Using XDV to theme and integrate a WordPress site</a></h1>
<p>Below are instructions how to integrate a WordPress site to your CMS. In this example CMS is Plone, but it could be any other system.  We will create XDV theme which will theme WordPress site to match our CMS site in the fly.</p>
<p style="text-align: center;"><a href="http://blog.mfabrik.com/wp-content/uploads/2010/03/xdv_wordpress.png"><img class="size-full wp-image-424 aligncenter" title="xdv_wordpress" src="http://blog.mfabrik.com/wp-content/uploads/2010/03/xdv_wordpress.png" alt="" width="658" height="720" /></a></p>
<p>WordPress theme using built with XDV and using a live Plone web page as a theme template.  This way WordPress theme inherits &#8220;live data&#8221; from Plone site, like top tabs (portal sections), footer, CSS and other stuff which can be changed in-the-fly and reflecting changes to two separaet theming products would be cumbersome.  Benefits using WordPress for blogging instead of main CMS</p>
<ul>
<li>WordPress post and comment management is easy</li>
<li>WordPress does not need to be touched: the old public WordPress instance can keep happily running wherever it is during the whole process</li>
<li>You do not need to migrate legacy WordPress installations to your CMS&#8217;s internal blogging tool</li>
<li>WordPress comes with extensive blog spam filtering tools. We get 11000 spam comments a month.</li>
<li>WordPress is designed for blogging and the user interface is good for that</li>
<li>WordPress integrates well with blog pingback support services</li>
<li>WordPress supports Gravatars and other blogging plug-ins</li>
<li>..and so on&#8230;</li>
</ul>
<p>Benefits of using XDV theming instead of creating native WordPress theme are</p>
<ul>
<li>You need to maintain only one theming add-on product e.g. one for your main CMS and WordPress receives updates to this site and theme automatically</li>
<li>WordPress does not need to be touched</li>
<li>You can host your WordPress on a different server, even wordpress.com, and still integrate it to your main CMS</li>
<li>The theme can be recycled not only for WordPress, but also other external services: Bugzilla, Trac, Webmail, phpBB, you-name-it</li>
<li>Even though WordPress has slick UI, it is a well known fact that it is a can of worms internally. My developers do not like the idea of PHP development and would spit on my face if I ask them to go a develop a WordPress theme for us</li>
</ul>
<div>
<h2><a id="theme-elements" name="theme-elements" href="http://www.tele3.cz/jbar/rest/render.py#id7">Theme elements</a></h2>
<p>The theme will consist of following pieces</p>
<ul>
<li>Deliverance rules XML file which defines how to combine Plone and WordPress HTML (rules.xml)</li>
<li>Additional CSS definitions active only for WordPress (wordpress.css). Dependency to this CSS in injected to the &lt;head&gt; by rules XML</li>
<li>Special Plone page template which will provide slots where WordPress can drop in the content (wordpress_listing.pt)</li>
<li>A helper script which makes it easy for repeatable perform theming actions, like recompiling the theme (xdv.py)</li>
</ul>
<div>
<h3><a id="cms-page-template" name="cms-page-template" href="http://www.tele3.cz/jbar/rest/render.py#id8">CMS page template</a></h3>
<p>This explains how to create a Plone page template where WordPress content will be dropped in. This step is not necessary, as we could do this without touching the Plone. However, it makes things more straightforward and explicit when we known that WordPress theme uses a certain template and we explicitly define slots for WordPress content there.  Example:</p>
<pre>&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="here/main_template/macros/master"
      i18n:domain="plone"&gt;

&lt;body&gt;

    &lt;div metal:fill-slot="content"&gt;

        &lt;div id="wordpress-content"&gt;
                &lt;!-- Your WordPress "left column" will go there --&gt;
        &lt;/div&gt;

    &lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
</div>
<div>
<h3><a id="theming-rules" name="theming-rules" href="http://www.tele3.cz/jbar/rest/render.py#id9">Theming rules</a></h3>
<p>Following are XDV rules (rules.xml) how we will fit WordPress site to Plone frame.  It will integrate</p>
<ul>
<li>Content from WordPress</li>
<li>Metadata from WordPress</li>
<li>CSS from Plone</li>
<li>Page basic structrure from Plone</li>
</ul>
<p>rules.xml:</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;rules xmlns="http://namespaces.plone.org/xdv"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:css="http://namespaces.plone.org/xdv+css"&gt;

    &lt;!-- Remove WordPress CSS by filtering out &lt;style&gt; tags--&gt;
    &lt;drop css:content="style" /&gt;

    &lt;!-- Make sure that WordPress metadata is present in &lt;head&gt; section --&gt;
    &lt;append css:content="head link" css:theme="head" /&gt;

    &lt;!-- note: replace does not seem to handle multiple meta tags very well --&gt;
    &lt;drop css:theme="meta" /&gt;
    &lt;append css:content="head meta" css:theme="head" /&gt;

    &lt;!-- Use blog title instead of Plone page title --&gt;
    &lt;replace css:content="title" css:theme="title" /&gt;

    &lt;!-- Put WordPress sidebar to Plone's portlets section --&gt;
    &lt;append css:content="#r_sidebar" css:theme="#portal-column-one .visualPadding" /&gt;

    &lt;!-- Place wordpress content into our theme content area --&gt;
    &lt;copy css:content="#contentleft" css:theme="#wordpress-content" /&gt;

    &lt;!-- This mixes in WordPress specific CSS sheet which is applied for pages
         served from WordPress only and does not concern Plone CMS.
         This stylesheet will theme WordPress specific tags,
         like blog posts and comment fields.
         We keep this file in Plone, but this could be served from elsewhere. --&gt;
    &lt;append css:theme="head"&gt;
        &lt;style type="text/css"&gt;
           @import url(http://mfabrik.com/++resource++plonetheme.mfabrik/wordpress.css);
        &lt;/style&gt;
    &lt;/append&gt;

    &lt;!-- This stylesheet is used by special spam protection plug-in NoSpamNX --&gt;
    &lt;append css:theme="head"&gt;
        &lt;link rel="stylesheet" href="http://blog.mfabrik.com/wp-content/plugins/nospamnx/nospamnx.css" type="text/css" /&gt;
    &lt;/append&gt;

    &lt;!-- Remove Google Analytics script used for CMS site --&gt;
    &lt;drop css:theme="#page-bottom script" /&gt;

    &lt;!-- Rebuild our Google Analytics code, using a different tracker id this time
         which is a specific to our blog.
      --&gt;
    &lt;append css:theme="#page-bottom"&gt;

        &lt;script type="text/javascript"&gt;
                var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
                document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
        &lt;/script&gt;

        &lt;script type="text/javascript"&gt;
                try {
                       var pageTracker = _gat._getTracker("UA-8819100-2");
                       pageTracker._trackPageview();
                } catch(err) {
                }
        &lt;/script&gt;
    &lt;/append&gt;

&lt;/rules&gt;
</pre>
</div>
<div>
<h3><a id="wordpress-specific-css" name="wordpress-specific-css" href="http://www.tele3.cz/jbar/rest/render.py#id10">WordPress specific CSS</a></h3>
<p>This CSS has styles which are applied only to WordPress pages. They are mainly corner case fixes where WordPress and CMS styles must match.  The CSS file is loaded when rules.xml injects it to &lt;head&gt; section.  wordpress.css:</p>
<pre>/* Font and block style fixes */

#wordpress-content h1 {
        border: 0;
}

#wordpress-content .post-end {
        margin-bottom: 60px;
}

#wordpress-content pre {
        width: 600px;
        overflow: auto;
        background: white;
        border: 1px solid #888;
}

#wordpress-content ul {
        margin-left: 20px;
}

#wordpress-content .post-info-date,
#wordpress-content .post-info-categories,
#wordpress-content .post-info-tags {
        font-size: 80%;
        color: #888;
}

/* Make sure that posts and comments look sane in our theme */

#wordpress-content .post {
        margin-top: 15px;
}

#wordpress-content .commentlist li {
        margin: 20px;
        background: white;
        padding: 10px;
}

#wordpress-content .commentlist li img {
        float: left;
        margin-right: 20px;
        margin-bottom: 20px;
}

#wordpress-content #commentform {
        margin: 20px;
}

#wordpress-content {
        margin-left: 20px;
        margin-right: 20px;
}

/* Make WordPress "sidebaar" look like Plone "portlets */

.template-wordpress_listing #portal-column-one ul {
        list-style: none;
        margin-bottom: 40px;
}

.template-wordpress_listing #portal-column-one ul#Recent li {
        margin-bottom: 8px;
}

.template-wordpress_listing #portal-column-one ul#Categories a {
        line-height: 120%;
}

.template-wordpress_listing #portal-column-one h2 {
        background: transparent;
        border: 0;
        font-weight:normal;
        line-height:1.6em;
        padding:0;
        text-transform:none;
        font-size: 16px;
        color: #9b9b9b;
        border-bottom:4px solid #CDCDCD;
}
</pre>
</div>
<div>
<h3><a id="helper-script" name="helper-script" href="http://www.tele3.cz/jbar/rest/render.py#id11">Helper script</a></h3>
<p>The following Python script (xdv.py) makes it easy for us</p>
<ul>
<li>Recompile the theme</li>
<li>Test the theme applied on the site</li>
<li>Preview the theme in our browser</li>
</ul>
<dl>
<dt>It is basically wrapped with default file locations around</dt>
<dd><em>bin/xdvcompiler</em> and <em>bin/xdvrun</em> commands with some webbrowser opening magic.</dd>
</dl>
<p>xdv.py:</p>
<pre>"""

 This command line Python script compiles your rules.xml to XDV XSL

 Modify it for your own needs.

 It assumes your buildout.cfg has xdv section and generated XDV
 commands under bin/

 To compile, execute in the buildout folder::

     python src/plonetheme.mfabrik/xdv.py

 To build test HTML::

     python src/plonetheme.mfabrik/xdv.py --test

 To build test HTML and preview it in browser, execute in buildout folder::

     python src/plonetheme.mfabrik/xdv.py --preview

"""

import getopt, sys
import os
import webbrowser

# rules XML for theming
RULES_XML = "src/plonetheme.mfabrik/deliverance/etc/rules.xml"

# Which XSL file to generate for compiled XDV
OUTPUT_FILE = "theme.xsl"

# Which file to generate applied theme test runs
TEST_HTML_FILE = "test.html"

# Our "theme.html" is a remote template served for each request.
# Because we are doing live integrattion, this is a HTTP resource,
# not a local file.
THEME="http://mfabrik.com/news/wordpress_listing/"

#
# External site you are theming.
# Note: must have ending slash (lxm cannot handle redirects)
#
SITE="http://blog.twinapex.fi/"

try:
    opts, args = getopt.getopt(sys.argv[1:], "pt", ["preview", "test"])
except getopt.GetoptError, err:
    # print help information and exit:
    print str(err) # will print something like "option -a not recognized"

# Convert options to simple list
opts = [ opt for opt, value in opts ]

print "Compiling transformation"
value = os.system("bin/xdvcompiler -o " + OUTPUT_FILE + " " + RULES_XML +" " + THEME)
if value != 0:
    print "Compilation failed"
    sys.exit(1)

if "-p" in opts or "--preview" in opts or "-t" in opts or "--test" in opts:
      print "Generating test HTML page"
      value = os.system("bin/xdvrun -o " + TEST_HTML_FILE + " " + OUTPUT_FILE + " " + SITE)
      if value != 0:
          print "Page transformation failed"
          sys.exit(1)

if "-p" in opts or "--preview" in opts:
    # Preview the result in a browser
    # NOTE: OSX needs Python &gt;= 2.5 to make this work

    # Make sure test run succeeded
    url = "file://" + os.path.abspath(TEST_HTML_FILE)
    print "Opening:" + url

    # We prefer Firefox for preview for its superious
    # Firebug HTML debugger and XPath rule generator
    try:
        browser = webbrowser.get("firefox")
    except webbrowser.Error:
        # No FF on the system, or OSX which can't find its browsers
        browser = webbrowser.get()

    browser.open_new_tab(url)
</pre>
</div>
</div>
<div>
<h2><a id="compiling-the-theme" name="compiling-the-theme" href="http://www.tele3.cz/jbar/rest/render.py#id12">Compiling the theme</a></h2>
<p>This will generate XSL templates to do theming transform. It will compile rules XML with some boilerplate XSL.  Running our compile script:</p>
<pre>python src/plonetheme.mfabrik/xdv.py
</pre>
<p>Since Plone usually does not use any relative paths or relative resources in HTML, we do not give the parameter &#8220;Absolute prefix&#8221; to the compilation stage. In Plone, everything is mapped through a virtual hosting aware resource locator: portal_url and VirtualHostMonster.  For more information see</p>
<ul>
<li><a href="http://pypi.python.org/pypi/xdv/0.3a2#compilation">http://pypi.python.org/pypi/xdv/0.3a2#compilation</a></li>
</ul>
</div>
<div>
<h2><a id="testing-the-theme" name="testing-the-theme" href="http://www.tele3.cz/jbar/rest/render.py#id13">Testing the theme</a></h2>
<p>The following command will apply theme for an example external page:</p>
<pre>bin/xdvrun -o theme.html theme.xsl http://blog.twinapex.fi
firefox theme.xhtml
</pre>
<p>&#8230; or we can use shortcut provided by our script &#8230;</p>
<pre>python src/plonetheme.mfabrik/xdv.py --preview
</pre>
</div>
<div>
<h2><a id="applying-the-theme-in-apache-production-environment" name="applying-the-theme-in-apache-production-environment" href="http://www.tele3.cz/jbar/rest/render.py#id14">Applying the theme in Apache production environment</a></h2>
<p>These steps tell how to apply the integration theme for WordPress when WordPress is running under Apache virtualhost.</p>
<div>
<h3><a id="installing-dependencies" name="installing-dependencies" href="http://www.tele3.cz/jbar/rest/render.py#id15">Installing dependencies</a></h3>
<p>We use Apache and mod_transform. <a href="http://pypi.python.org/pypi/xdv#apache">Instructions how to set up modules for Apache</a> are available on XDV homepage. Some hand-build modules must be used, but instructions to set them up for Ubuntu / Debian are available.  Apache 2 supports <a href="http://httpd.apache.org/docs/2.2/mod/mod_filter.html">filter chains</a> which allow you to perform magic on HTTP response before sending it out. This corresponds Python&#8217;s WSGI middleware.  We&#8217;ll use special built of mod_transform and mod_depends which are known to working. These modules were forked from their orignal creations to make them XDV compatible, as the orignal has not been updated since 2004 (here you can nicely see how open source guarantees &#8220;won&#8217;t run out of support&#8221; freedom).</p>
<ul>
<li><a href="http://code.google.com/p/html-xslt/">XDV mod_transform and mod_depends homepage</a></li>
<li><a href="http://www.outoforder.cc/projects/apache/mod_transform/">Orignal mod_transform and mod_depends homepage</a></li>
</ul>
<p>Example:</p>
<pre>sudo -i
apt-get install libxslt1-dev libapache2-mod-apreq2 libapreq2-dev apache2-threaded-dev
wget http://html-xslt.googlecode.com/files/mod-transform-html-xslt.tgz
wget http://html-xslt.googlecode.com/files/mod-depends-html-xslt.tgz
tar -xzf mod-transform-html-xslt.tgz
tar -xzf mod-depends-html-xslt.tgz
cd mod-depends-html-xslt ; ./configure ; make ; make install ; cd ..
cd mod-transform-html-xslt ; ./configure ; make ; make install ; cd ..
</pre>
<p>Enable built-in Apache modules:</p>
<pre>a2enmod filter
a2enmod ext_filter
</pre>
<p>For modules <em>depends</em> and <em>transform</em> you need to manually add them to the end of Apache configuration, as they do not provide a2enmod stubs for Debian. Edit /etc/apache2/apache.conf:</p>
<pre>LoadModule depends_module /usr/lib/apache2/modules/mod_depends.so
LoadModule transform_module /usr/lib/apache2/modules/mod_transform.so
</pre>
<p>You need to hard reset Apache to make the new modules effective:</p>
<pre>/etc/init.d/apache2 force-reload
</pre>
</div>
<div>
<h3><a id="virtual-host-configuration" name="virtual-host-configuration" href="http://www.tele3.cz/jbar/rest/render.py#id16">Virtual host configuration</a></h3>
<p>Below is our virtualhost configuration which runs WordPress and PHP. Transformation filter chain has been added in.  /etc/apache/sites-enabled/blog.mfabrik.com:</p>
<pre>&lt;VirtualHost *&gt;

    ServerName blog.mfabrik.com
    ServerAdmin info@mfabrik.com

    LogFormat       combined
    TransferLog     /var/log/apache2/blog.mfabrik.com.log

    # Basic WordPress setup

    Options +Indexes FollowSymLinks +ExecCGI

    DocumentRoot /srv/www/wordpress

    &lt;Directory /srv/www/wordpress&gt;
        Options FollowSymlinks
        AllowOverride All
    &lt;/Directory&gt;

    AddType application/x-httpd-php .php .php3 .php4 .php5
    AddType application/x-httpd-php-source .phps

    # Theming set-up

    # This chain is used for public web pages
    FilterDeclare THEME
    FilterProvider THEME XSLT resp=Content-Type $text/html

    TransformOptions +ApacheFS +HTML
    # This is the location of compiled XSL theme transform
    TransformSet /theme.xsl

    # This will make Apache not to reload transformation every time
    # it is performed. Instead, a compiled version is hold in the
    # virtual URL declared above.
    TransformCache /theme.xsl /srv/plone/twinapex.fi/theme.xsl

    # We want to apply theme only for
    # 1. public pages (otherwise WordPress administrative interface stops working)
    &lt;Location "/"&gt;
        FilterChain THEME
    &lt;/Location&gt;

    # 2. Admin interface and feeds should not receive any kind of theming
    &lt;LocationMatch "(wp-login|wp-admin|wp-includes)"&gt;
        # The following resets the filter chain
        # http://httpd.apache.org/docs/2.2/mod/mod_filter.html#filterchain
        FilterChain !
    &lt;/LocationMatch&gt;

&lt;/VirtualHost&gt;
</pre>
</div>
<div>
<h3><a id="running-it" name="running-it" href="http://www.tele3.cz/jbar/rest/render.py#id17">Running it</a></h3>
<p>After Apache has all modules enabled and your virtualhost configuration is ok, you should see WordPress through your new theme by visiting at the site served through Apache:</p>
<ul>
<li><a href="../">http://blog.mfabrik.com</a></li>
</ul>
</div>
<div>
<h3><a id="automatically-reflecting-cms-changes-back-to-xdv-theme" name="automatically-reflecting-cms-changes-back-to-xdv-theme" href="http://www.tele3.cz/jbar/rest/render.py#id18">Automatically reflecting CMS changes back to XDV theme</a></h3>
<p>The theme should be recompiled every time</p>
<ul>
<li>Plone is restarted: CSS references change in &lt;head&gt; as CSS cache is rebuilt</li>
<li>CSS is modified: CSS references change in &lt;head&gt; as CSS cache is rebuilt</li>
<li>Plone content is changed and changes reflect back to WordPress theme (e.g. a new top level site section is being added)</li>
</ul>
<p>This is because the compilation will hard-link resources and template snippets to resulting the theme.xsl file. If hard-linked resources change on the Plone site, the transformation XSL file does not automatically reflect back the changes.  It could be possible to use Plone events automatically to rerun theme compilation when concerned resources change. However, the would be quite complex.  For now, we are satisfied with a scheduled task which will recompile the theme now and then.  Alternatively, mod_transforms could be run in non-cached mode with some performance implications.  Here is a shell script, update-wordpress-theme.sh, which will perform the recompilation and make Apache&#8217;s transformation cache aware of changes:</p>
<pre>#!/bin/sh
#
# Periodically update WordPress theme to reflect changes on CMS site
#

# Recompile theme
sudo -H -u twinapex /bin/sh -c cd /srv/plone/twinapex.fi ; python src/plonetheme.mfabrik/xdv.py

# Make Apache aware of theme changes
sudo apache2ctl graceful
</pre>
<p>Then we call it periodically in cron job, every 15 minutes in /etc/cron.d/update-wordpress:</p>
<pre># Make WordPress XDV theme to reflect changes on CMS
0,15,30,45 * * * * /srv/plone/twinapex.fi/update-wordpress-theme.sh
</pre>
</div>
</div>
<div>
<h2><a id="updating-wordpress-settings" name="updating-wordpress-settings" href="http://www.tele3.cz/jbar/rest/render.py#id19">Updating WordPress settings</a></h2>
<p>No changes on WordPress needed if the domain name is not changed in the theme transformation process.</p>
<div>
<h3><a id="site-url" name="site-url" href="http://www.tele3.cz/jbar/rest/render.py#id20">Site URL</a></h3>
<p>Unlike Plone, WordPress does not have decent virtual hosting machinery. It knowns only one URL which is uses to refer to the site in the external context (e.g. RSS feeds).  This setting can be overridden in</p>
<ul>
<li>WordPress administrative interface</li>
<li>wp-config.php</li>
</ul>
<p>Here is an example how we override this in our wp-config.php:</p>
<pre>// http://codex.wordpress.org/Editing_wp-config.php#WordPress_address_.28URL.29
define('WP_HOME','http://blog.mfabrik.com');
define('WP_SITEURL','http://blog.mfabrik.com');
</pre>
</div>
</div>
<div>
<h2><a href="http://www.tele3.cz/jbar/rest/render.py#id21">HTTP 404 Not Found special case</a></h2>
<p>Http 404 Not Found responses are not themed by Apache filter chain. This is not possible due to order of pipeline in Apache.  As a workaround you can set up a custom HTTP 404 page in WordPress which does not expose the old theme.</p>
<ul>
<li>Go to WordPress admin interface, Theme editor</li>
<li>Edit 404.php and modify it so that it does not pull in the WordPress theme:
<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Not found&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

        &lt;h1&gt;Not Found, Error 404&lt;/h1&gt;
        &lt;p&gt;Aaaaw, snap! The page you are looking for no longer exists. It must be our hamster who ate it.&lt;/p&gt;

        &lt;a href="&lt;?php bloginfo('url'); ?&gt;"&gt;Go to blog homepage&lt;/a&gt;

        &lt;a href="http://mfabrik.com"&gt;mFabrik business site&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
</li>
</ul>
<p>For more information see</p>
<ul>
<li><a href="http://codex.wordpress.org/Creating_an_Error_404_Page">http://codex.wordpress.org/Creating_an_Error_404_Page</a></li>
</ul>
</div>
<div>
<h2><a id="roll-out-checklist" name="roll-out-checklist" href="http://www.tele3.cz/jbar/rest/render.py#id22">Roll-out checklist</a></h2>
<p>Below is a checklist you need to go to through to confirm that the theme integration works on your production site</p>
<ul>
<li>WordPress public pages are loaded with the new theme</li>
<li>WordPress login works</li>
<li>WordPress administrative interface works</li>
<li>RSS feed from WordPress works and contain correct URLs</li>
<li>HTTP 404 not found is handled correctly</li>
<li>HTTP 302 redirect is handled correctly (i.e. missing / at the end of blog post URL)</li>
<li>Changes on CMS site are reflected to WordPress theme within the update delay</li>
<li>Old blog site is redirected to new site using HTTP 301 (if applies)</li>
</ul>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2010/03/28/integrating-and-theming-wordpress-with-your-cms-site-using-xdv/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Building a mobile site and applications with Django and Python</title>
		<link>http://blog.mfabrik.com/2009/09/30/building-a-mobile-site-and-applications-with-django-and-python/</link>
		<comments>http://blog.mfabrik.com/2009/09/30/building-a-mobile-site-and-applications-with-django-and-python/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 08:46:52 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[pys60]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apex vertex]]></category>
		<category><![CDATA[augmented reality]]></category>
		<category><![CDATA[bicycling]]></category>
		<category><![CDATA[bilingual]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[browsercontrol]]></category>
		<category><![CDATA[capabilities]]></category>
		<category><![CDATA[darwin]]></category>
		<category><![CDATA[django-cms]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[handset]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[lbs]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[location based]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[mobile profile]]></category>
		<category><![CDATA[mod_python]]></category>
		<category><![CDATA[multichannel]]></category>
		<category><![CDATA[multilingual]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[oulu]]></category>
		<category><![CDATA[phonegap]]></category>
		<category><![CDATA[premium]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[publishing]]></category>
		<category><![CDATA[rtsp]]></category>
		<category><![CDATA[series 40]]></category>
		<category><![CDATA[series 60]]></category>
		<category><![CDATA[sniffing]]></category>
		<category><![CDATA[streaming]]></category>
		<category><![CDATA[symbiansigned]]></category>
		<category><![CDATA[tourism]]></category>
		<category><![CDATA[traffic statistics]]></category>
		<category><![CDATA[twinapex]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[upnorth]]></category>
		<category><![CDATA[user agent]]></category>
		<category><![CDATA[webkit]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://blog.twinapex.fi/?p=248</guid>
		<description><![CDATA[Recently we created a mobile site for an interactive bicycle tour. oulugo.mobi (you need to use mobile browser to access the site or you&#8217;ll get a redirect) is a multimedia enriched bicycle tour through the historic parts of the city of Oulu. All content is provided by OnGo. The route, which you can bicycle through is [...]]]></description>
			<content:encoded><![CDATA[<p>Recently <a href="http://www.twinapex.com">we</a> created a mobile site for an interactive bicycle tour. <a href="http://oulugo.mobi">oulugo.mobi</a> (you need to use mobile browser to access the site or you&#8217;ll get a redirect) is a multimedia enriched bicycle tour through the historic parts of <a href="http://ouka.fi/english/index.asp">the city of Oulu</a>. All content is provided by <a href="http://www.ongo.fi/en/index.htm">OnGo</a>.</p>
<p>The route, which you can bicycle through is drawn on Google Maps. There are nine  action points where the user can listen to streaming audio clips, with still images, in his/her mobile phone. This is sort of  augmented reality experience: The user sees the real world (where he/she is now bicycling) combined with the historic events (audio playback narrative). For example, at Linnansaari (a location on the route) you&#8217;ll see the actual 17th century castle ruins and the narrator tells how the castle exploded when fire, caused by a lighting, reached gunpowder warehouse&#8230; boom. The explosion caused stones fly over 400 meters.</p>
<p>Alternatively, the clips are available as podcasts from <a href="http://www.oulutourism.fi/oulugo/en_default.aspx">Oulu Tourism pages</a>. You can download them into your iPod for offline listening and use in conjuction with a paper map. This demostrates interesting mix of multichannel publishing: paper, web, mobile and podcasts.</p>
<p>The tour is bilingual in Finnish and English.</p>
<p>There exists unreleased iPhone application, based on <a href="http://phonegap.com">PhoneGap</a>, which allows the user to track his/her location real-time on the web page. We didn&#8217;t see it worth of trouble to go through Apple iPhone application review process. When location based service support comes for the browser this feature is indended to be included as the standard HTML5 feature of the service.</p>
<p>There also exists Nokia Series 60 mobile application, based on<a href="http://wiki.opensource.nokia.com/projects/PyS60"> PyS60</a> and Series 60<a href="http://www.forum.nokia.com/info/sw.nokia.com/id/47d8a7fe-768c-44e5-bc26-fcba0a05e35e/S60_Platform_Browser_Control_API_Guide_v2_0_en.pdf.html"> BrowserControl API</a>, which allows the user to track his/her location in real-time. The application provides wrapper around Series 60 WebKit control and allows Javascript to access phone native functions (GPS) over localhost socket communication. Like with Apple, we didn&#8217;t see real-time tracking feature interesting enough to go through Symbian Signed process to get our application released. Also, BrowserControl had seriousquality problems and we didn&#8217;t consider it stable enough for the end users. <a href="https://code.launchpad.net/~august-joki/pys60community/browsercontrol">Some work is available in PyS60 Community Edition repository</a>.</p>
<p>The service is hosted <a href="http://www.twinapex.com/solutions/outsourcing-hosting-and-maintenance-of-internet-and-mobile-systems">on Python specific virtual server on Twinapex services server farm</a>.</p>
<h2>Features</h2>
<ul>
<li>Premium content tailored for audio listening</li>
<li>Dubbed in English and Finnish by a professional voice actor</li>
<li>Bilingual: English/Finnish</li>
<li>Adapts for smartphones (WebKit based browsers) and low end phones (XHTML mobile profile browsers)</li>
<li>Streaming video and audio (RTSP / progressive HTTP download forv iPhone). Different audio quality is provided on depending on the handset features.</li>
<li>Screen resolution detection based on <a href="http://en.wikipedia.org/wiki/User_Agent">user agent sniffing</a>. Three different version of images are used.</li>
<li>Custom Google Maps component for mobile is used. The component adapts for different mobile phones based on sniffing. Features include zoom, show action point, show the current location, search street address name. This component can be published on a request.</li>
<li>Management interface features include video upload, video transcoding different mobile versions and editing bilingual content</li>
<li><a href="http://www.twinapex.com/products/mobile-publishing/apex-vertex/handset-database">Apex Vertex handset database is used to detect the user&#8217;s mobile phone capabilities</a></li>
<li><a href="http://www.twinapex.com/products/mobile-publishing/apex-vertex/reporting">Apex Vertex logging and traffic analytics capabilities are used for the site statistics</a></li>
</ul>
<h2>Software stack</h2>
<ul>
<li><a href="http://www.ubuntu.com">Ubuntu 8.04 Hardy Heron virtual server</a></li>
<li><a href="http://www.apache.org">Apache 2.2 / mod_python</a></li>
<li><a href="http://python.org">Python 2.5</a></li>
<li><a href="http://djangoproject.com">Django 1.0</a></li>
<li><a href="http://django-cms.org/">Django-CMS 1.0</a></li>
<li><a href="http://code.google.com/p/mobilesniffer/">mobile.sniffer Python package to provide abstraction over different handset databases</a></li>
<li><a href="http://www.twinapex.com/products/mobile-publishing/apex-vertex">Apex Vertex streaming</a> solution (RTSP based on Darwin streaming server by Apple)</li>
<li><a href="http://tinymce.moxiecode.com/">TinyMCE WYSIWYG editor</a></li>
<li><a href="http://developer.apple.com/opensource/server/streaming/index.html">Darwin streaming server</a></li>
<li><a href="http://extjs.com/">ExtJS</a> is extensively used in Apex Vertext management interface</li>
</ul>
<h2>Development effort</h2>
<p>Development time: Around 100 hours. Three different developers where involved. Used development tools: <a href="http://www.eclipse.org">Eclipse</a>, <a href="http://pydev.sourceforge.net/">PyDev</a>, <a href="http://subclipse.tigris.org/">Subclipse</a>, <a href="http://subversion.tigris.org/">Subversion</a>. There were around five meetings between the content provider and the technology provider. Few beta testing rounds using iPhone application were performed by bicycling in -10 celcius degrees weather (north and so on&#8230;). No polar bears were harmed during the creation of this mobile service.</p>
<p>The service is linked in from Oulu Tourism pages and thousands of paper brochures printed for Oulu summer season 2009.</p>
<p><strong style="font-weight: bold;">About the author Mikko Ohtamaa</strong></p>
<ul>
<li><a href="http://www.linkedin.com/in/ohtis  ">LinkedIn</a></li>
<li><a href="http://twitter.com/moo9000">Twitter</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2009/09/30/building-a-mobile-site-and-applications-with-django-and-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

