php

Essential Tools for a PHP Developer

Tobias Schlitt has just posted some slides from his talk entitled "6 essential PHP development tools in 60 minutes". I flicked the 90 or so slides in PDF format, they pretty much mirror my development environment.

Tobias left out 2 must haves from my personal list. Vim, the only editor I can use for any prolonged period of hacking (go easy emacs fanbois). Although not really a PHP tool, Firebug, is an essential tool for any serious modern web application developer,

With this environment hacking on PHP based web apps should be a breeze.

As a side note I am starting to play with git after watching Linus' Google Tech Talk on it, and I am starting to like a it, so maybe soon it will be s/svn/git for me.

A Virtual Host per Project

Not long before my old laptop got to the end of it usable lifespan I started playing with the Zend Framework in my spare time. One of the cool things about ZF is that it wants to use friendly URLs, and a dispatcher to handle all the requests. The downside of this approach, and how ZF is organised, it works best if you use a Virtual Host per project. At first this seemed like a real pain to have to create a virtual host per project. One Saturday afternoon I worked through the apache docs and found a solution - then I found it fantastic. Rather than bore you with more of my views on Zend Framework, I will explain how to have a virtual host model that requires a little work up front and is very low maintenance.

It gets tedious copying and pasting virtual host config files each time you want to start a new project, so instead I let Apache do the work for me.

I added a new virtual host config file called projects to /etc/apache2/sites-available. The file contains

UseCanonicalName Off

LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon

<Directory /home/dave/Projects>
Options FollowSymLinks
AllowOverride All
</Directory>

NameVirtualHost 127.0.0.2
<VirtualHost 127.0.0.2>
	ServerName projects

	CustomLog /var/log/apache2/access_log.projects vcommon

	VirtualDocumentRoot /home/[username]/Projects/%1/application/www
	AccessFileName     .htaccess
</VirtualHost>

The important bit is the VirtualDocumentRoot directive which tells Apache to map a hostname to a path. I use an IP address from the 127.0.0.0/8 range for the virtual host, so they aren't accessible to the outside world and I don't have to worry about it changing every time I check locations.

All of my projects live under ~/Projects and each one gets a directory structure that looks something like this.

[projectname]
  |
  +- notes - coding notes, like grep output when refactoring etc
  |
  +- resources - any reference material or code snippets
  |
  +- application - the code for the project
     |
     +- www - document root for vhost

There are usually other paths here too, but they vary from project to project.

To make this work there are few more steps. First enable the new virtual host

$ sudo a2ensite projects

Don't reload apache yet.

Next you need to add the apache module

$ sudo a2enmod vhost_alias

Time to edit your /etc/hosts file so you can find the virtual hosts. Add a line similar to this

127.0.0.2 projects phpgw-trunk.project [...] phpgw-stable.project

Now you can restart apache

$ sudo /etc/init.d/apache2 reload

This is handy for developing client sites - especially using drupal.

Now my /var/www/index.html is just an empty file.

I am getting a bit bored with adding entries to /etc/hosts all the time. If I get around to adding dnsmasq with wildcard hosts to the mix, I will post a follow up.

This setup is based on my current dev environment (Ubuntu Hardy), but it also works on older versions of Ubuntu. The steps should be similar for Debian and derivatives. For other distros, it should work, just how to make it work may be a little different. Feel free to post tips for others in the comments.

Day 2 at PHP Unconference Hamburg

I arrived back in Bergen late last night after spending another day the PHP Unconference in Hamburg. I even managed to get one speaker to do his talk in English, which made things a lot easier for me.

My brain started to adjust to German a bit more, which made things easier than on day 1. Overall I think I understood about 25% of what was being discussed, which sound like a waste of time, but that 25% was pretty good quality. Also the discussions in the corridors was great too. At the end of the day the language spoken isn't very important when compared to the ideas shared.

For me, the only attraction of web based social networks, is to provide a backup of my addressbook online. FOSS on the other hand is a global "social network" that is real. Events like linux.conf.au, the PHP Unconference in Hamburg, Bar Camp Melbourne and other similar events are a vital part of the networks - they provide the space for us to meet and discuss ideas.

I also used the trip as an opportunity to catch up with Christian Böttger, Release Coordinator for phpGroupWare. Not only did we discuss the project, but we caught up on how business and life in general was going. It is always good to catch up with Christian, I just wish I had more than a couple of hours to spare.

My next couple of events are locked in. Wednesday night is drinks with Johan Gunnarsson from phpGroupWare, at the airport in Copenhagen. Overnight Google emailed me a confirmation for the Google Developer Day 2008 in Sydney on June 18, there is some interesting stuff on there too - less FOSS centric but still seems pretty cool.

PHP Unconference Hamburg Day 1

I spent yesterday at the PHP Unconference in Hamburg. None of the sessions were in English, so that meant I really struggled with some of the sessions, while some of the others I could pick up some of it.

Between sessions I meant to meet a few people I had chatted with in IRC, but never met in meatspace. I always like to be able to put a face to a nick or blog, then have a beer or 2. This is exactly what happened last night.

I managed to land a big thick Ajax book (in English), which was pretty cool - something to read on the plane back to Australia

It is sad that phpGroupWare doesn't have the "brand recognition" it once had. Hopefully we can turn that around later this year if we get a release out.

I am skipping the morning session, and hope to catch some good sessions this afternoon.

For the record, the Norwegian company I work for isn't eZ.

PHP on crack

I had a chuckle while reading Ed Finkler's PHP6 wish list. After reading the comment by Damien Seguy I almost fell off my chair.

Try running the following code under PHP

<?php
${'!@#$%^&*()[]:;"<>,./?'} = "i bet this won't work!<br>\n";
${"omg???!!! wtf???!!! :D"} = "omg it does<br>\n";
echo ${'!@#$%^&*()[]:;"<>,./?'} . ${"omg???!!! wtf???!!! :D"};

It worked here on PHP 5.2.3 with ubuntu security fixes. I got

i bet this won't work!<br>
omg it does<br>

This contradicts the PHP manual, but hey it works.

hello_world.c

$ cat hello_world.c
#include <stdio.h>

main()
{
    printf ("Hello World!\n");
}

$ gcc hello_world.c -o hello_world
$ chmod +x hello_world
$ ./ hello_world
Hello World!
$

I have started playing with C recently. I am still finding it annoying, yet enjoyable at the same time. The PHP developers have spoilt me (and other PHP coders). PHP gives you most of the power of C, without having to deal with annoying string handling, easy arrays, memory management and having to build to test. I am sure there is more.

Unlike OS X, I think I will persist with C.

Other than reminding myself of how to do hello world in C, why did I post this? I thought you would never ask, it is because my blog is now syndicated on Planet Linux Australia. I am pretty honoured by being added. Hopefully there are others who appreciate my rants :)

bye bye PHP 4

I have several servers running PHP 5 already, but as my laptop is my primary phpGroupWare development and test environment, it was running PHP 4.

I knew this day would come, I just didn't think it would be so soon. PHP4 has been dropped from ubuntu. Ubuntu has never shipped php4 in main, but until feisty it has been in available in the universe.This is no more.

The advantage of using PHP 5 on ubuntu is that it is in main, so has full security support.

I started using PHP 3 and I was pretty enthusiastic about making the jump to PHP4, but have held back on PHP 5 due to the problems with running phpGroupWare (and other scripts) under it. It looks like I no longer have any excuses,

Now that all the major distros ship PHP 5 and PHP 6 is around the corner, it is time to bury PHP 4. The world didn't end when register globals was turned off by default. Switching to PHP 5 won't kill us either, but holding back may.

Really Simple CalDAV Store

Interesting PHP CalDAV implementation. Could be useful for phpGroupWare

http://rscds.sourceforge.net/