Compiling PHP 5.4 on Ubuntu 12.04

So recently I’ve been working with PHP 5.4 a LOT. Unfortunately Ubuntu (my main dev environment) is behind the times. So I’m resorting to compiling PHP manually.

Not a daunting as it may first appear. The really tricky part is working out your dependencies and configure script.

Hence the reason for this post as a reminder for myself and others that may want to do a quick compile. (I would recommend that if your compiling for a production/live environment that you make sure you understand what it is your compiling though before just using what’s here)

So where to start. Dependencies first I think

Ubuntu allows you to install dependencies for building source apt-get build-deps. We will use this and install any extras we may need.

And now the configure

Once these are done then we follow the standard make process. Notice we are also running make test… very important as it givges more data for the developers to work with.

The next thing is configuring your php.ini file as the install doesn’t have one yet so we copy either the production or development default from the source code to the new conf dir and edit to suit your needs.

Thats it. All ready to roll… almost, this installation is the one I use for use with a webserver so you will want to add the appropriate directives to apache.

Bookmark and Share

9 thoughts on “Compiling PHP 5.4 on Ubuntu 12.04

  1. carl

    I’ve got a similar setup (Ubuntu 12.04, Apache2.2, php “–with-apxs2=/path/to/apxs2″) but I’m having a tough time getting past a C compiler error, something like rodata.1.1 can't be used when compiling shared objects. Set the -fPIC flag and compile again.

    I’ve added -fPIC to gcc and g++ with environment variables with no luck. I’ve tried setting and unsetting the “–enable-shared” flag in the php configuration options, among other things that I can’t remember at the moment (somewhat frustrated :)). Do you have any recommendations for getting past this particular issue?

    Reply
    1. Matt Cockayne Post author

      Hi Carl,

      I’m afraid this ones a little beyond my own capabilities without more info. If you can provide a bit more of the output I’d be happy to have a look and see if I can spot something that might help.

      Matt

      Reply
  2. Frederick

    If you already have PHP install on the sever how to you recompile it?

    Where is the source code where you run ./configure if PHP is already installed or must I download PHP and recompile from the source?
    The last option is a little extreme and I want to avoid that.

    thx

    Reply
    1. Matt Cockayne Post author

      Hi Frederick,

      With the instructions I have given your php install will be located at /usr/local/php.

      What I normally do when I want to update is download the latest copy of php and run through the same process again using the same configure, make & make install commands (obviously making the appropriate adjustments as required) which will then overwrite the existing install.

      What you may find you will need to do is to also re-install any pecl extensions you have installed but this can vary from extension to extension.

      Matt

      Reply
  3. Nik Rolls

    If you replace ‘make install’ with ‘checkinstall’ (you will have to ‘apt-get install checkinstall’ first) then you’ll get a .deb out of it which can cleanly be uninstalled in the future. Also, you can specify the version and the system package that it replaces (in this case ‘php5′) and it will uninstall the old package for you when installing the .deb, and your build will satisfy dependencies for the package you replace. It also means that if Ubuntu ever got around to releasing a newer version of PHP than you had built, an ‘apt-get upgrade’ should theoretically handle the update for you.

    Reply
  4. Ramesh Dharan

    Note that the –enable-debug option included in the flags passed to ./configure has a non-trivial effect on performance (~2x degradation in microbenchmarks). You probably want to remove it if you’re intending to use the resulting binary in production.

    Reply
    1. Matt Cockayne Post author

      You are absolutely correct in that –enable-debug is not a trivial setting.

      However In the post I do state “that if your compiling for a production/live environment that you make sure you understand what it is your compiling though before just using what’s here”

      I would have thought that this implies that the instructions here are for a development environment. Were I compiling for Live I would be a lot more particular about my compilation so that I can get the best performance from it.

      Reply
  5. Pingback: Aufbau einer Multi-Core-fähigen PHP Version (pthreads) unter Ubuntu | Tom Thaler

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">