Thursday, October 30, 2008

Apache2 PHP config

I am installing a couple of shopping cart online stores AKA commerce packages in order to evaluate them for use in an online store I'm setting up. I did a little research and decided based on features and the one deal breaker required feature, Google Checkout, on two commerce packages. The first is Zen Cart and the second is Magenta.

One of the commerce packages noted that one of the extension modules required enabling PHP short_tags. I had previously disabled php short_tags because it was preventing the use of the xml declaration tag at the top of my html files.

I use XHTML 1.1 for all my HTML work. Converting every document I do significant work on to XHTML 1.1. So turning back on PHP short_tags in my HTML files was not an option.

Luckily that was not necessary. I have enabled the PHP handler for .html and .xhtml files in my php5.conf located in /etc/apache2/conf.d/. I have a few other PHP related configuration statements that are wrapped by an if module mod_php statement.

I created a Files section within that if module mod_php that disables short tags only within .html and .xhtml files. Like so:

<IfModule mod_php5.c>
AddHandler application/x-httpd-php .html .xhtml
<Files ~ "\.x?html$">
php_flag short_open_tag off
Alias /phpinfo /var/www/phpinfo.php
Alias /apcinfo /usr/share/php/apc.php

I also have a couple of aliases in there that make useful system info URLs available automatically on all web hostnames. The PHP Alternative Cache, APC, has builtin PHP login security. I'm going to add PHP authentication to the phpinfo and post the code.

Yikes backslash zero on

I started a new blog at, One Liner Code. I was reviewing my posts when I realized that my sed example didn't make sense to me. I didn't understand how I could have messed up such a simple example in the language that most easily lends itself to one liners. I thought I had double checked all of my examples and made sure they were running right. Turns out the html code looked fine. There was a preprocessor stepping in between me and my sed Hello World post. It was turning my backslash zero into a null.

I whipped out my handy dandy php evaluator and encountered failure using the htmlentities() string function. php wouldn't give me the htmlentity code for characters that didn't need them. I decided to switch it up and get the charactor code using a ruby one liner:

ruby -e '"0".each_byte {|i| p i}'

I could have also used a php one liner like this:

php -r 'echo ord("0")."\n";'

The quick fix \&#48; allowed the post preprocessor to accept the backslash zero and turn it into the correct character representation.