Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to install PHP from source code on my Ubuntu 12.04 VPS.

I'm installing PHP like this:

  1. Download the latest version from the php.net website.
  2. Configure it using the parameters below.
  3. Install any dependencies when necessary. (libxxxxx-dev)
  4. Then do a make
  5. Then a make install
  6. Move the php.ini file and the fpm configuration files in the right place

I'm using these parameters in the configure command:


Now, this goes all well and good. The version works as expected and during the installation I had no trouble. Now the fun stuff comes. Whenever I want to install something like mcrypt (for example) I would normally type apt-get install php5-mcrypt but when I do, and take a look at the dependencies I see that PHP5 is still listed as one and will be installed once I hit y (overwriting my own version).

Now the real core of my question is, how do I let Ubuntu know that I already have PHP5 installed so that it does not attempt to install PHP5 as a dependency anymore. Do I have to change something in the configure process? Do I have to install PHP5 using the apt-get manner first, remove it manually, and install my own version of PHP after.

It is worth mentioning that I need this custom PHP build to make Pthreads work since there isn't a repo that offers a ZTS version of PHP (yet, please make one, somebody?).

share|improve this question
How exactly you compile your own version of PHP? –  Braiam Apr 7 at 19:57
Ok, first, I'm reluctant to help anyone in the misguided endeavor of installing PHP, custom or otherwise. You really, really don't want to do that. Rethink it, please. You still want to? Are you sure? Ok, then the correct thing to do it to download the Ubuntu PHP package sources, configure those and then rebuild them. That way you will have an Ubuntu package you can then install, which your system will know about. You probably need more details. Feel free to ask. See also unix.stackexchange.com/q/112157. This is about backporting, but it covers the basics of customizing packages. –  Faheem Mitha Apr 7 at 19:58
I'm really unfamiliar with back porting. Tbh this is the first time I hear about it. I'll read some posts about it and when I have questions, I'll respond on this question. Thanks for the effort anyway. –  Martijn Riemers Apr 7 at 20:05
@MartijnRiemers This isn't backporting, it is customization. Not really the same thing, but the basic machinery is similar. BTW, if you want someone to be notified of your comment, you need to prefix your comment with the username with an @ in front. –  Faheem Mitha Apr 7 at 20:08

2 Answers 2

up vote 1 down vote accepted

There are several alternatives here:

  1. Add the --prefix=/usr/local to the configure script (assuming this is what PHP uses) or otherwise ensure that your PHP is installed to /usr/local. This would mean that you would have your own build of PHP installed alongside the system one. Since, for example, /usr/local/bin takes precedence over /usr/bin in PATH, your own build will be used in many of the cases (particularly when starting from the command line). By default this shouldn't interfere with the system packages which may have been built against a particular version of PHP and be broken if they try to use libraries provided by your own build. With this approach though you do need to pay some attention to which programs are using which libraries, however it should be possible to do this without problems.

  2. Find a packaged version of PHP that is closer to your needs. If it is a newer version, there are plenty of Ubuntu ppas that offer this (preferably look in official 'backport' repositories first since anyone can create a possibly broken ppa). Note that this may also cause conflicts which force you to install other packages from the ppa (or leave you screwed if they are unavailable).

  3. Download the source package and recompile it. This might be what you need to do if you want custom build options. There are many tutorials throughout the internet for this, but basically you would add the necessary deb-src lines to your sources.list file (or sources.list.d) and download with apt-get source (or just download the necessary files directly from packages.ubuntu.com). Extract with archives dpkg-source Then you would tweak the build options within the package debian directory, build with debuild or dpkg-buildpackage and install with dpkg -i. You can even do this with a package from a ppa if you also need a newer version (although same caveats apply).

  4. Finally the most difficult option is to create your own package. Starting with one of the above source packages and using different version of the upstream source than is otherwise available is a good place to start. However, here is completely up to you to ensure that the package plays nicely with the rest of your system.

share|improve this answer
@Martijn Riemers Yes, no 3 is what I had in mind. I would not recommend 1. Having two versions of a package installed is always a recipe for trouble. –  Faheem Mitha Apr 7 at 20:26
@Faheem Mitha, 3 seems the best option to me. I'll see what I can do. –  Martijn Riemers Apr 7 at 20:28
@Graeme If I do it like way 3, will Ubuntu know I installed PHP5 then? –  Martijn Riemers Apr 8 at 13:46
@MartijnRiemers, of course, yes. What you create is a package, much the same as the one you usually install with apt. –  Graeme Apr 8 at 14:31
@Graeme I finally managed to pull it off. Thanks so much! I owe you one haha –  Martijn Riemers Apr 8 at 15:09

Ok, instead of the method you mentioned at first try this:

First, make sure you have deb-src entries in your sources.list file and you have run apt-get update. It will make the steps below easier. Now install building tools:

sudo apt-get install devscripts

install your build dependencies:

sudo apt-get build-dep php5

Get the sources of php5:

apt-get source php5
cd php5*

You will notice that apart of downloading the sources, it also applied patches. Now look for the configuration script, which is in debian/rules. There's an entry called COMMON_CONFIG, edit it as you like:

editor debian/rules
## add, remove, change the configuration and save the file.
## You will find that most of them are enabled by default,
## or already included.

I would recommend to bump the version of PHP using dch -i. Now you are ready to build your stuff:

debuild -us

This will create the files ready to install in the parent directory. Now, you really should reconsider why you need to build stuff from source. Most of the security issues are fixed immediately there's a fix available, and due the nature of PHP (being something used in production), it's recommendable to use the official packages instead.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.