Installing a PHP YAML library on Ubuntu

I've just installed the PHP YAML library which is currently being developed. This will hopefully allow me to write more complex configuration documents than the tradition ini format allows.

The installation process was a bit hit and miss though, with minimal documentation, and a couple of errors on the way.

Ubuntu Packages

First off, you will need the following Ubuntu packages:

$ sudo apt-get install php5
$ sudo apt-get install php5-dev
$ sudo apt-get install php-pear
$ sudo apt-get install libyaml-dev

PECL Library
Once you get these packages installed, you can then install the PECL library:

$ sudo pecl install yaml
Failed to download pecl/yaml within preferred state "stable", latest release is version 0.6.3, stability "beta", use "channel://pecl.php.net/yaml-0.6.3" to install
install failed
$ sudo pecl install yaml-0.6.3

Currently, the library is in development, and the release version might change - requesting the stable package will get you the error message as above. Alternatively, you can check the PECL documentation for the latest version number.

Now, you might get a couple of error messages if you neglected to install one or two of the Ubuntu packages above.

ERROR: `phpize' failed

This means that php5-dev has not been installed, and so the PECL library can't be compiled into a usable module.

ERROR: `/tmp/pear/temp/yaml/configure' failed

This means that libyaml-dev was not installed - variations of this error seem to occur fairly frequently when installing PECL libraries on Ubuntu and SUSE.

PHP Configuration

Finally, once everything has been installed, you can add the extension to the PHP config. The best way to do this is to maintain the Ubuntu configuration style (meaning if your base PHP install changes, your configuration won't get wiped):

$ cd /etc/apache2/conf.d
$ sudo vi yaml.ini
extension=yaml.so
~
~
~

Save the file.

If you want to use this in a website, then you will have to restart your Apache service (as with all PHP configuration changes):

$ sudo apache2ctl restart

Job Done

You should now have access to the YAML library.

Please note - as of 0.6.3, the library is still a way from complete, with a couple of functions not currently supported (specifically, reading/writing direct to/from the YAML file). However, you can read in the file and then parse the content using a two step process - I'll be writing a short YAML parsing tutorial soon.

Comments

Lightppd

Excellent tutorial right up until the apache bit - trying to get this to work in Lightppd with little luck.

re: Lightppd

I've never used Lightppd, so I'm afraid that I can't really help out there.

One solution is to simply add the YAML extension to the php.ini file - bearing in mind that this article is for configuration on Ubuntu/Linux and not Windows (so extension configuration is a little different: http://php.net/manual/en/install.windows.extensions.php ).

Post new comment