Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Compiling PHP Extensions

DZone's Guide to

Compiling PHP Extensions

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

There are lots of reasons why you might like to compile your own PHP extensions. For me those reasons are usually:

  • The extension isn't available on pecl (e.g. uprofiler)
  • The extension is on pecl, but you need the newest version or a branch with a particular feature or fix in it, perhaps for testing
  • You are fixing an extension yourself (yay, we need more people like you!)

Related: If you followed my previous post on compiling PHP, be aware that in the php/bin/ folder there is a pecl binary that will install extensions correctly for whichever version of PHP it belongs to, so you may not need to read the rest of this post. However if you do, the paths follow on from the examples in that post.

I haven't seen a really approachable guide anywhere, we tend to speak of extensions in hushed tones, and actually it isn't particularly tricky so here is my quick how-to guide.

Start by grabbing the code you need. First we'll need to prepare it for compiling by explaining to it which version of PHP it is intended for.

For your default PHP install you can just run:

phpize
./configure

However for a version that isn't the default on your system, we can be a bit more specific with the paths to use:

phpize /path/to/toy/php/bin/phpize
./configure --with-php-config=/path/to/toy/php/bin/php-config

Either way, we're now all set to build and install our extension:

make
make install

This compiles the extension and places the binaries in the correct location (you may need to sudo make install if your user doesn't have write permission to the desired location). This process will tell you which extension file was created, such as uprofiler.so.

Check that PHP can load the extension by adding it on the command line and then viewing the modules list (beware that errors often appear at the top of this output and may scroll off screen!):

php -dextension=uprofiler.so -m

(remember to include the /path/to/toy/php for non-default installs)

You should see the extension listed in the output - you can now add it to your php.ini file or however you usually enable extensions and carry on with whatever it was you were doing!

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}