PHP Extensions on Linux

Hi All,

For the past few years, I’ve always ran Apache, PHP and MySQL under Windows, only ever using Linux for my production environment (which I rarely had to touch). I’m not making the jump to a Ubuntu virtual machine to host my LAMP development environment. The biggest difference I’ve noticed between PHP on Windows and PHP on Linux is how they handle extensions. On Windows, when you install PHP, you get a whole load of extensions under the “ext” directory which you can enable or disable at leisure. With PHP on Linux though, you don’t get this, instead you need to compile PHP with all the extensions you wish to use, or think you may use in the future. If you ever change you’re mind you have to re-configure, re-make and re-install PHP.

I was wondering if there was a more Windows approach to extensions on Linux, or if I’m start with re-building PHP every time I want to add or remove an extension. I guess the same question is, is there anywhere on the internetz that offers a repository of pre-compiled “.so” php modules which would be compatible with Ubuntu 9.10?

Note, this isn’t even mentioning the hassle of finding all the dependencies required to build extensions with PHP. It took me almost an hour just to add a couple of common extensions to my PHP build.


Dynamic libraries work the same in Linux as they do for you in Windows. The only difference is the file extension – .so vs .dll. You don’t have to recompile PHP to enable or disable them, you just add them to your php.ini, the same as you did in Windows.

I’m sure most non-standard extensions you would want to add are available through apt-get or whatever Ubuntu’s package manager is. I run RedHat/CentOS on all my servers, and installing a PHP extension is just one command, which doesn’t involve compiling PHP.

All the standard ones are already be installed, and you’ll find their configurations in the php.d directory. I’m not sure where Ubuntu puts the extensions themselves… probably /usr/lib/php/modules?

Thanks for the reply Dan. Just to clarifying, I’m building PHP from source, and so need to explicitly tell the configure script which PHP options and extensions I’d like. This does not generate “.so” php extensions, but instead seems to compile these extensions into PHP. There is a “ext” folder in the PHP source directory which has all the extensions you’d expect, but in there uncompiled form. I guess I could always compile the individual extensions as php modules, but is there not a pre-compiled php extension repository out there somewhere?

You don’t need to compile your own PHP. And even if you did, you can still use dynamically loaded extensions, like you did in Windows.

For example, type:

sudo apt-get install php5-gd

and the gd module is installed.

To install PHP in Ubuntu, without compiling from source:

sudo apt-get install php5

I’ve ended up compiling all the required extensions myself using these simple steps…

A few of the extensions relied on 3rd party libraries, plus there were a few other little hiccups, but nothing Google couldn’t solve. For anyone else planning on doing this, one thing I can tell you is that you need to install “autoconf” before you’ll be able to compile php extensions using the steps in the above link.

If you have PHP setup properly, you can just do:

pecl install ext_name

And the official reference for installing extensions can be found at:

I don’t believe the common extensions (ie. those bundled with PHP) are available on PECL, hence this won’t work for those extensions. Either way though, it’s a good tip.

Yeah, those you won’t find in PECL.

Considering this is a development environment, I would go with the package manager route Dan outlined.

I just don’t want to be dependant on the package manager, plus it seems only a sub-set of extensions is available via the package manager. Compiling extensions myself takes a little longer, and you do get problems with some of the extensions (missing dependencies) but otherwise, it seems like the most flexible and modular solution, which is what attracts me to it. Thanks for all your input though.

I might be wrong, but as far as i know package manager installation have many advantages over compiled from source one. Like i will mention these:
[B]- Security updates

  • Normal Patches[/B]

And its not that difficult to enable and use extensions in Linux, personally i use package manager way, easy to use and update plus get working system in minutes.

I compiled my own php from source on my server. The trick is, you have to use the ./configure option to specify the path to the php.ini file, or no php.ini file will be read in.

On mine, I used:

Then you can configure extensions exactly the same way as windows, using /etc/php.ini

Stormrider, I’m not quite sure what you’re talking about. What does “–with-config-file-path” achieve exactly? I compiled PHP with the intention of adding/creating a php.ini file afterwards. What’s the disadvantage of this compared to what you’re referring to?

Using that switch tells php to look in the path you specify for a php.ini file, simple as that