Thursday, September 23, 2010

There's more than Cpanel in this world

My brother bought simple local e-commerce application. PHP application actually. It's quite simple, the typical add to cart stuff with extra features to track affiliation. Nothing that Drupal/Ubercart can't do. But I can see a reason for people to buy that. Buying off the shelf software is cheap (provided it work out of the box) compared to developer's time to setup an open source equivalent.

I'm hosting all my brother's website so for this one I just created another user inside my Webfaction account, point the php/symlink application to the DocumentRoot inside that user's home directory, create mysql database and all set to go. But there's one problem. Clicking on certain link that supposed to open a popup just load up the main page instead of the desired page.

Since it look like a routing problem, I take look at .htaccess file. There seem to be few rules that route incoming url to the php file. Looking at source code, it turned me off a lot. IonCube encoded. Nah, I can see a reason for them to protect their hardwork. But for me to debug some 'proprietary' code ? No way. So I just asked my brother to request a support.

The first response said that the .htaccess file cannot be uploaded. I don't know how he come to the conclusion. The file is there. So I replied (to my brother) to let them know that the file is there, attached a copy of that file and asked them to verify whether the file is correct or not. I'd also mentioned that mod_rewrite is enabled, in case they're thinking of that. Some other rewrite is working so there's no reason to say mod_rewrite not working.

Another reply that really made me think enough is enough. They're complaining that they can't access something like or Wth .... so there must be a cpanel in all hosting in this world ??? The problem is simple enough to debug, writing this blog post would take much longer than that.

What I did was rename index.php to index2.php and create my own index.php. There I just print_r($_SERVER) to see all the incoming request variables. Everything look quite ordinary except for the DOCUMENT_ROOT value. My main webfaction account is at /home/myname and the DocumentRoot is located at /home/myname/webapps/thesite which is a symlink to /home/seconduser/thesite. For some reason, the DOCUMENT_ROOT value that end up in the $_SERVER variable is /home/myname/webapps/_ rather than /home/seconduser/thesite. Looked back into the .htaccess file and there's a rule that use %DOCUMENT_ROOT (RewriteCond %{DOCUMENT_ROOT}%1.php -f) which basically check if the %1.php file exists or not otherwise redirect the request to index.php. So that is it. Since DOCUMENT_ROOT value is wrong, the rule doesn't match and always redirect to index.php. My fix - hardcode the DOCUMENT_ROOT value in the rule. Done.

I'm not that annoyed if this is just some open source project. I'm more than willing to spare some of my time identifying the problem and creating patch if required. But for something that need to pay and I can't even read the code, I deserved this rant.

Saturday, September 18, 2010

Django: empty clause in for loop

One thing I like about Jinja is the else clause in the for ... in loop syntax. It handy when you want to display something like "Your cart is empty ..." when looping through a list of items, if the items is empty.

It not obvious in the documentation but after searching around, I found out that Django also had the same functionality now in changeset 9530. That's about 2 years ago, so much things I miss in Django world. Django use the keyword "empty" rather than "else" as in Jinja.

{% for item in items %}
{% empty %}
Your cart is empty
{% endfor %}

Thursday, September 16, 2010

Plesk: Overriding apache config

For PHP safe_mode you can do that through the control panel but not for open_basedir. You can create a file called vhosts.conf under conf directory in your domain root. This link explain it better.

The important thing is the command:-

/usr/local/psa/admin/sbin/websrvmng -u --vhost-name=<DOMAIN.TLD>

which would rebuild the apache config and add an Include directive to include the file we have just created. For subdomains, we need to create the vhost.conf under that subdomain conf directory and then run:-

/usr/local/psa/admin/sbin/websrvmng -a -v