Howto: build and install the intl PECL extension for PHP5 in Debian

by Sander Marechal

For the past few days I have been looking for a proper i18n (internationalisation) and l10n (localisation) method for PHP. PHP has quite a few locale aware functions such as strftime and sprintf. In combination with gettext this can work quite well. The major downside is that you need to install all the locales that you want to support on your server. Want to serve your websites in Russian? Then you need to generate a Russian locale system-wide. That won’t work when you’re on a shared hosting account somewhere.

PHP6 is promising to solve that problem with the intl functions. Even better, the intl functions are also available as a PECL extension and works on PHP 5.2.4 and newer. Debian Etch currently packages PHP 5.2.0 which is too old, but Lenny—Debian’s upcoming version—is up to PHP 5.2.6. There is no package (yet) for php5-intl in Debian Lenny but building and installing the extension yourself is really easy. Here’s a short tutorial.

First we need to install a couple of packages that allow us to build PECL extensions on Debian, and we need to install the build and runtime dependencies of the intl package (libicu38, libicu-dev and xsltproc).

  1. # apt-get install php5-dev dh-make-php fakeroot libicu38 libicu-dev xsltproc

The magic is in the dh-make-php package. It can download and configure a PECL extension for us, ready for building a Debian package. The following command tells dh-make-pecl to download and configure the intl extension.

  1. $ dh-make-pecl --depends libicu38 --build-depends libicu-dev --only 5 intl

This downloads the intl extension, configures it and adds libicu38 and libicu-dev as dependencies. The last option tells dh-make-pecl that we only want to build this extension for PHP5 and not for both PHP4 and PHP5 as is the default. Now we can build a binary Debian package.

  1. $ cd php-intl-1.0.0/
  2. $ dpkg-buildpackage -rfakeroot

Now the binary package will be built. If you have GPG configured then at the end you may get prompted (twice) for your GPG passphrase so that the files can be signed with your GPG signature. You should now have a .deb and various other files in the directory above.

  1. $ cd ..
  2. $ ls
  3. intl-1.0.0.tgz                     php-intl_1.0.0-1.dsc
  4. php5-intl_1.0.0-1_i386.deb         php-intl_1.0.0-1_i386.changes
  5. php-intl-1.0.0                     php-intl_1.0.0.orig.tar.gz
  6. php-intl_1.0.0-1.diff.gz

Now you can install the extension. If you have Apache running then you need to restart it. Note: You can't restart Apache gracefully with the apache2ctl graceful command. A graceful restart of Apache does not restart PHP so the extension will not be loaded. You need to restart Apache through the init.d script.

  1. # dpkg -i php5-intl_1.0.0-1_i386.deb
  2. Selecting previously deselected package php5-intl.
  3. (Reading database ... 177537 files and directories currently installed.)
  4. Unpacking php5-intl (from php5-intl_1.0.0-1_i386.deb) ...
  5. Setting up php5-intl (1.0.0-1) ...
  6.  
  7. # /etc/init.d/apache2 restart
  8. Restarting web server: apache2 ... waiting .

That’s all! Now you can go play with the new intl functions. Happy coding!

Creative Commons Attribution-ShareAlike

Comments

#1 Anonymous Coward

Thanks - very helpful. One minor thing, I also had to install xsltproc in order to build the package, so

# apt-get install php5-dev dh-make-php fakeroot libicu38 libicu-dev

should be changed to

# apt-get install php5-dev dh-make-php fakeroot libicu38 libicu-dev xsltproc

#2 Sander Marechal (http://www.jejik.com)

Ah, thanks for that :-) I have updated the article accordingly.

I usually have xsltproc installed on all my machines so I didn't notice that. I do quite a bit of PHP development with XML so xsltproc usually comes in handy.

#3 Anonymous Coward

Doesn't dh-make-pecl use the <dependencies> section of the package.xml distributed with the PECL extension's source to determine the --depends values?

#4 Sander Marechal (http://www.jejik.com)

If you say so. But the dependencies section of the package.xml only list php-6.0.0-dev and pearinstaller-1.4.0 as dependencies. Nothing else.

#5 Blain (http://www.zenwebware.com/)

Thank you, worked perfectly.

#6 akki (http://universe4you.com)

I am getting this error.

dpkg-buildpackage -rfakeroot
dpkg-buildpackage: warning: using a gain-root-command while being root
dpkg-buildpackage: set CFLAGS to default value: -g -O2
dpkg-buildpackage: warning: using a gain-root-command while being root
dpkg-buildpackage: set CFLAGS to default value: -g -O2
dpkg-buildpackage: set CPPFLAGS to default value:
dpkg-buildpackage: set LDFLAGS to default value:
dpkg-buildpackage: set FFLAGS to default value: -g -O2
dpkg-buildpackage: set CXXFLAGS to default value: -g -O2
tail: cannot open `debian/changelog' for reading: No such file or directory
dpkg-buildpackage: failure: tail of debian/changelog gave error exit status 1

#7 Sander Marechal (http://www.jejik.com)

Hi akki. Did you use the dh-make-pecl script to download and configure the package? That should create the debian/chaneglog package for you. You could also try creating the file manually.
Post a new comment

Registration is not required to post comments, but cookies must be enabled. One of the advantages of registration is that you can edit your comments later on (editing not yet implemented). You can register or login here.




Your e-mail address will not be published, but your website URL will. All links that you post will tagged rel="nofollow" to throw off spammers. You are allowed to use the following XHTML tags in your comment: <em> <strong> <u> <b> <i> <strike> <blockquote> <big> <small> <ul> <ol> <li> <a href=""> <pre> <code> <tt> <br>. Please allow up to 60 second processing time after you post a comment. Our spam filters may take some time.