How to install a newer version of PHP as a package?

I have been trying to install specific/different PHP versions from source but this causes problems when other packages depend on a "php package" to be installed. Last time I tried to install PHP as a package, it was a few versions behind.

How can I install a newer/latest PHP in a way that satisfies other packages that depend on PHP?


Solution 1:

If you want the latest-greatest bleeding-edge software in Linux distro. Then you need to build the software from source (ideally creating your own package), and you must re-build any package that depend on that package.

While that is the general rule, the real situation is far more complicated.

Since you are talking about PHP, you can basically break this out into a couple different scenarios depending on exactly the package relates to PHP.

  • PHP Extensions (Any PHP modules that loaded directly into PHP to enhance its behavior). These must be rebuilt, if you rebuild PHP. A short list would include php5-dev, php5-gd, php5-mysql, php5-ldap, php5-odbc php5-pgsql, php5-sqlite, but almost every package apt-cache search 'php5-' in this list would need to be rebuild if you manually compile PHP.
  • Packages that provide software that uses. Most of these packages you wouldn't have to rebuild and you could easily trick them into working by using equivs, which is a tool that basically allows you to create a meta-package so that other packages think you have a package installed, when you installed from source. Basically this would be any PEAR package, and any web application (moodle, wordpress, drupal, cacti, etc).

If you are not sure which category a package falls under, then look at the source package details. If it depends on php5-dev, then it will have to be re-compiled.

Another somewhat imprecise way to summarize this would be like this. If the dependant application uses the Application Binary Interface, then it will need to be re-compiled when you rebuild the parent package. If a package uses an Application Programming Interface, then it might not need to be rebuilt, and you can make it work with equivs, or FPM.