News Archive
PhpRiot Newsletter
Your Email Address:

More information

Managing PHP 5.4 Extensions on Ubuntu

Note: This article was originally published at Planet PHP on 29 November 2012.
Planet PHP

My shiny new VPS* runs Ubuntu 12.10 (official subtitle: Quantal Queztal. Local nickname: Quirky Kestrel) and therefore has PHP 5.4 installed. It's very new so every command I type is missing, and today I realised that included a PECL module (pecl_http, of course). So I aptitude install php5-pear and then get tangled in dev packages (clue: look which libcurl you have already installed to figure out which of a long list of -dev packages to choose), managing finally to emerge with a pecl install http that completes successfully with the words:

configuration option "php_ini" is not set to php.ini location
You should add "" to php.ini

I've been using Ubuntu for some time however, and we don't put settings straight into php.ini, there's a directory called /etc/php5/conf.d/ where all the various module configurations live, or you can enable things just for when PHP is called by apache or from the CLI. However today I hopped into /etc/php5/ and saw this:

a"oa"a" apache2
a"oa"a" cli
a"oa"a" conf.d
a""a"a" mods-available

Hmmm ... mods-available ?


What's happened here is that all debian-flavoured unixes have adopted this standard for their PHP 5.4 packages, so if you're using debian, ubuntu, or any of their relatives with PHP 5.4, you'll see a directory structure like this. When you add a module to PHP, you'll add a file to the mods-available directory enabling the module and adding any config specific to it. If you want to enable the module, just do:

php5enmod http

This simply creates a symlink from the usual conf.d directory to point to where the real files are in mods-available, prefixed with a number that indicates the priority of the module. By default, the priority is 20.

Using this approach means we can toggle things on and off without commenting out big chunks of config files and leaving them lying around - if this seems familiar then that's no surprise; debian-like linuxes manage their apache configuration in just the same way. Any packages that you install using aptitude will use these exact same commands to set up the configuration and then symlink it correctly. To unlink, use the delightfully predictably-named php5dismod :)

This new structure was news to me, so I thought I'd make a note of it - lots of people are upgrading at the moment I know, so if that includes you, here's a little something to help you along the way!

* The new shiny server is a Linode. If you're signing up for a Linode and don't have any friends with referral codes, you can use mine: - this blog is hosted there and it all helps!

Lorna is an independent web development consultant, writer and trainer, open source project lead and community evangelist. This post was originally published at LornaJane