Home Articles HowTo Guides HowTo: Install PHP Subversion Extension In Ubuntu

HowTo: Install PHP Subversion Extension In Ubuntu

E-mail Print PDF

There's a nice little PHP extension providing native support for Subversion (i.e. you don't need the subversion binaries installed to use it). The installation instructions on php.net advise that this extension is part of the PHP core and that no installation is necessary. Whilst that is true - the extension is bundled with the php core, it is seemingly not built by default, and at least on Debian-based distributions, there does not appear to be any binary package for this extension. If you want to use this extension on Ubuntu (as I did) you will need to build and install it manually.

Probably, more experienced PHP developers would not be confused about any of this, but I have to admit that it took me some time to figure out why these functions were "part of the PHP core" yet not available in my PHP environment, and seemingly not available anywhere in the Debian package repositories either. I guess I've just been spoilt by the excellent Debian packaging for too long :D

Anyway, the main reason I'm writing this HowTo is that my googling failed to turn up any results about installing this extension other than the manual page on php.net. Basically, you need to build it manually from the community extensions directory PECL. This was another small point of confusion for me at first - "apt-cache search pecl" will turn up the package php-pear, but you have to know that PEAR and PECL share the same packaging and distribution mechanism. I'm not sure why this isn't a mandatory dependency, but you will need also the phpize tool from the appropriate PHP development package (e.g. php5-dev). The only other dependency, is the Subversion headers (libsvn-dev) which are needed to compile the extension even though the Subversion binaries are not required for use.

sudo apt-get install php-pear php5-dev libsvn-dev

Then you can do:

sudo pecl install svn

...which should download the extension source code, build the svn.so file and install it somewhere that php will find it.

Running this on Hardy, pecl complained that it didn't know where to find php.ini which needs to be told to load the extension (configuration option "php_ini" is not set to php.ini location). I didn't bother trying to fix that, mostly because there are usually two separate php configs - a default one for the CLI interpreter and another used by apache. I only use php with apache, so I added the line:

extension=svn.so

...in the dynamic extensions section of /etc/php5/apache2/php.ini. If all went well, just restart apache, and job done! Checking phpinfo() should show the extension installed under the heading "svn".

Update:

I had to do this again recently and pecl didn't want to install svn because there is no release marked as stable yet. All you need to do to tell it to install the beta release is use:

sudo pecl install svn-0.3

Last Updated on Monday, 07 September 2009 09:10