PHP on Ubuntu Gutsy Gibbon with PDO and PDO_mysql

A (very) quick tutorial on setting up mysql PDO libraries for PHP on ubuntu Gutsy Gibbon.

This version of PHP is the default one that comes with this version, 5.2.3. Check you have installed the php5-common package from aptitude as this includes the pdo.so file. If you check phpinfo you should see that PDO is listed as a module although you don’t have any drivers.

Then you should do:

sudo aptitude install php5-mysql

Restart apache and check its error log in case there are any problems. Then simply refresh your phpinfo page and pdo_mysql should be listed.

For earlier versions of ubuntu/kubuntu have a look at this excellent tutorial from theatons, I followed this but its slightly out of date now which is why I’ve posted an update. Most of the rest of the tutorial is still correct though.

Ubuntu/Kubuntu and mod_rewrite

I just spent a couple of days, on and off, fiddling with my apache setup on a kubuntu box. I had a site with some very weird and scary rewrite rules which I needed to do some development work with and I just could not get the site to work!

The solution was very simple and I found the answer in this post about ubuntu and apache. Basically, AllowOverride is set to None for both / and /var/www/ by default on ubuntu, which is nice and secure but it caught me out on this occasion. Change the settings to AllowOverride All and create a symlink in mods-enabled to mods-available/rewrite.conf and restart apache – everything should then start playing nicely.

Geshi and Serendipity for Code Snippets

I write on technical subjects on this site on a fairly regular basis, and nothing annoys me more than blog software which “eats” long lines of code or renders it in a difficult-to-read way. Happily Serendipity (or s9y for short) has a plugin for geshi.

About GeSHi

I thought “geshi” was a word but I just looked it up to link to it and it turns out its actually GeSHi (Generic Syntax Hilighter) which is a very humane way of pronouncing the thing. It is a very popular way to render source code on the web and was originally intended for phpBB. Geshi is great, it has lots of pre-made syntax highlighting rules so the odds are that it can probably already render whatever language you are coding in very nicely, however if it doesn’t then that’s fine too – it is an open standard and you can jump in and write your own.

Using GeSHi

Back to this blog, I added the “Markup: Geshi” plugin from SPARTACUS (the serendipity plugin repository) and added it as an event plugin. I had a lot of problems getting it working – putting it first in the list of event plugins eventually did the trick for me. You use geshi by adding geshi tags around the code you want to show, for example:


phpinfo();
phpinfo();

Styling GeSHi

Another problem I had initially was with the default resulting fonts, however these are easy enough to change and I now have colours I chose myself (illustrated in my posts about a SOAP server and PHP compilation) which is really quite easy to do. The plugin has files with all the language highlight in them and if you scroll down and look at the “color” entries towards the end of these, it is possible to just replace the red/green/blue defaults with colours that fit in with your look and feel (pink in my case, obviously!). For me the syntax files are in serendipity/plugins/serendipity_event_geshi/geshi – this is also a good place to look to see what languages you have that are supported.

I commonly use:

  • php
  • bash
  • xml
  • sql

A useful tip for styling is that the code block is placed into a div with a class named the same as the “lang” attribute – so for example I’ve got some of them resized by adding an entry to my overall css file.

Hope this helps someone, I remember having problems finding much info about using geshi in this way when I first added the plugin. If anyone is having problems feel free to post comments, I have this working on my serendipity installation so I am happy to try to help out.

Adding Markup to Comments in Serendipity

I switched over to serendipity as my blog platform about 6 months ago and although I haven’t been blown away by it, its a better tool for this job than textpattern was. I liked textpattern a lot but serendipity is better for what I need. There were a few things that I really missed when I moved across to serendipity – and the biggest one was textile as a markup. Its available in serendipity as a plugin, and I’d recommend it to everyone, but after I had imported my existing content from textpattern to serendipity I found that turning on the markup plugin did strange things to existing content so I turned it off.

Another thing I’ve been missing is the ability to add markup in comments, such as images. Well, its back! I’ve turned on textile for comments on this site, there is a link under the comments box to a page that shows you the syntax, so feel free to add richer content to this site from now on :)

Bank Holiday Weekend To Do List

Its Easter, which means its the only time of the year we reliably get 4 days off in a row from work without taking leave. And one thing I don’t have is a lot of holiday allocation. So, we’ve got good intentions of getting as much as possible done in the house (or at least, I’ve got good intentions and will rope in anyone who crosses the threshold). Apart from a whole lot of cleaning and catch-up in the house which is normal, I’m hoping to get some or all of the following done:

  • coal hole sorted out – we have the original coal cellar in our hose which was full of DIY stuff and other junk when we bought it – not much has come out and we’ve put a lot more stuff in, to the point where you now can’t get in the door and can’t find anything!
  • workshop space sorted – this follows on from the previous point – all the tools and stuff are in B&Q bags all over the floor in the other basement room because we haven’t got any usable storage
  • garden digging – got about the last 20 ft square of digging to do in the garden before we can lay turf … weather forecast is lousy though so I doubt that will happen
  • runs to the tip – many many of these I should think, hopefully taking some of the junk out of the garage
  • living room woodwork – skirting boards and dado rails need cutting to fit, sanding, staining and actually fitting. Fireplace needs sanding and staining and reassembling. Window sill needs staining. Window frame needs repairing. Door needs a new handle. After that we might start on the shelving we’re going to build

We do have help (anyone else at a loose end please feel free to come over as well!) but if we get half of this done it’ll be a miracle, wish us luck and have a good weekend yourself :)

Debian Change Keyboard Layout

I recently downloaded a virtual machine which had all the default factory settings in it – including an American keyboard layout. To change this on Debian Etch I simply used:

dpkg-reconfigure console-data

and then followed the online prompts. For reference (i.e. the next time I have this problem), the | (pipe) symbol on a US keyboard is mapped to the ~ (tilde) on a UK one.

Kubuntu Installation – Disk Partitioning

I’m installing Kubuntu Gutsy Gibbon onto my Dell Vostro 1500 and the first problem I hit was that the Live CD was entirely unable to repartition the disks. There are a few partitions on the disk (as you’d expect from a Dell machine running Vista, its got recovery and things) and I kept seeing the error:


An error occurred while writing the changes to the storage devices.
The resize operation is aborted

To get around this I resized the main partition in Windows and created a new partition but left it unformatted. When I went back to the Live CD install I got the option “Use largest contiguous space” and that worked fine.

Hope this helps someone!

First Manchester Girl Geek Dinner

Last night I attended the first Manchester Girl Geek Dinner. I am very excited about the Girl Geek Dinner events arriving in the north, there’s a lot of activity up here and I’m already involved in other local events such as GeekUp and BarCamp.

I’m based in Leeds, so it was about an hours drive over to Manchester. Thanks to the wonderful world of satellite navigation, I found the venue with no problems. The evening started with some mingling and drinks, and then we were all invited to take seats and help ourselves to the buffet, which was excellent. After the meal we had a variety of talks which were actually really good, I hadn’t been thinking of the talks as the highlight but they certainly were!

During the course of the drinks, the meal, and a few minutes after the talks (although it was a very late finish, 10pm or so, I didn’t leave until half past and then had to drive back to Leeds), I was able to meet and speak with an amazing selection of women of various ages, professions and backgrounds and had some interesting and valuable conversations.

Its early days for this version of this event and the plan is for it to be quarterly, I am looking forward to the next installment.

Grand Entrance Hall

When the rewiring of the house was done in November and our parquet flooring was a casualty of the process. We’ve spent the months since then with a hallway that looks like this:

Please admire the retro red and orange floorboards!!

Anyway, things are looking a lot better now – we’ve got a new floor!! I am so excited by this that I am providing a cartoon strip style display :)

I forgot to photograph the doormat we got – its in the porch, fitted rubber-backed doormat stuff that you lay like a carpet. So first impressions on entering our place are now quite different (so long as you ignore the holes in the wall)

PHP London Meet and Some Heckling

I’ve been in London on business again this week (hopefully my wild travelling will calm down a bit now) which had the nice side-effect of allowing me to get to the PHP London meetup on Thursday. It was nice to see people that I met at the conference the previous week and also to meet some people who I hadn’t managed to catch up with previously.

The talk was from William Coleman of Microsoft talking about FastCGI and using PHP on Windows. He’d have done better to not say “We’re all guys here” in his opening remarks as I found myself heckling a speaker for the first time in my life!! I counted 4 women there out of 35 or so people, so a minority but a definitely existing one. He did apologise (about 17 times and after digging a bigger hole) and I had a brief chat with him later on, and gave him my phpwomen.org business card.

The talk was good and interesting, and he brought with him a remarkable sense of humour, which he probably needed since there were lots of smart comments coming from all angles. He did however impress upon us that performance of PHP on Windows is now comparable to performance of PHP on Linux, which was actually very interesting to know. Personally I have been staying away from PHP on Windows for 5 years or so but since I now work for Ibuildings who are Zend partners, then I guess I need to have more of a clue! Other than a few confusing moments where a comparison was made between running PHP on Windows against running it on Apache (what? Is Windows a web server now?) it was a good session and its nice to hear about these developments. My feeling is that no matter how stable PHP is on Windows, its the stability of Windows itself that means I’ll be avoiding it in my production servers for some time yet.

The punchline of the evening? Apparently microsoft have invented this great thing, called a shell, where you can just type comands in to your server rather than clicking on things, so you can manage servers remotely …