CentOS - PHP - Yum Install with Custom ./configure params

I have successfully configured and compiled php on my dev server, and works great, but after talking to a sysadmin buddy, he informed that custom compiles of the latest builds are not recommended for production (or even development) systems. He noted a situation where they custom configured and compiled PHP 5.3.6, only to find that there was some issue with a low-level Postgres driver, so they had to revert back to 5.3.3.

So I am considering going back to yum to install PHP, however I have several custom configuration settings and was wondering if it's possible to pass or configure how PHP will be compiled through YUM?

My current configure line:

Configure Command =>  './configure'  '--with-libdir=lib64' '--prefix=/usr/local/_custom/app/php' '--with-config-file-path=/usr/local/_custom/app/php/etc' '--with-config-file-scan-dir=/usr/local/_custom/app/php/etc/modules' '--disable-all' '--with-apxs2=/usr/sbin/apxs' '--with-curl=/usr/sbin/curl' '--with-gd' '--with-iconv' '--with-jpeg-dir=/usr/lib' '--with-mcrypt=/usr/bin' '--with-pcre-regex' '--with-pdo-mysql=mysqlnd' '--with-png-dir=/usr/lib' '--with-zlib' '--enable-ctype' '--enable-dom' '--enable-hash' '--enable-json' '--enable-libxml' '--enable-mbstring' '--enable-mbregex' '--enable-pdo' '--enable-session' '--enable-simplexml' '--enable-xml' '--enable-xmlreader' '--enable-xmlwriter'

Download src.rpm for the package, it contains ORIGINAL source code and all the files required for compiling custom rpm's:

  • php.spec - spec file needed for rpmbuild
  • php-xxx.tar.gz - original source code
  • various patches (.diff, .patch)
  • documentation files to be added (if exist)

To build rpm - you will need rpm-build package which contains rpmbuild program.

It also can be done with yumdownloader (from yum-utils package):

yum install yum-utils rpm-build

yumdownloader --source php

Install src.rpm:

rpm -Uvh *.src.rpm

cd to rpmbuild SPEC dir;

RHEL5, old Fedora

cd /usr/src/redhat/SPEC/

Suse:

cd /usr/src/packages/SPEC/

RHEL6, newer Fedora:

cd ~/rpmbuild/SPEC/

php.spec file contains details about how package is built and which components will be included. It also contains data regarding dependencies and required packages to have in order to build new packages correctly. So, rpmbuild will remind you about any missing packages.

You will need to:

  1. Download updated php source code from php.net and put it into SOURCES dir
  2. Specify new version in "Version:" string in the php.spec file, also use lower value in "Release:" string and add your custom name in it, like "Release: 0.mike"
  3. Check .spec file for possible additional changes (maybe there are some security patches not needed in current version, rpmbuild will tell you about that if file is already patched). Maybe you will need to comment some "Patch xx:" string and some "%patch xx" if you will have any problems.
  4. run rpmbuild:

    rpmbuild --target x86_64 -ba php.spec

--target x86_64 - specifies platform (can be i386, x86_64, amd64, etc)

-ba - "build all", will build both final .rpm and new src.rpm packages

You can find built packages in ../RPM/ and ../SRPM/ directories.

This method ensures, that vendor patches are included, directory. file structure hierarchy is the same, component is compatible, dependencies are met and old version will be safely replaced. Also, you guarantee your future updates.

p.s. I disagree with "new version in production is bad" string. I am providing support services to dozen of companies, also have shared hosting and I always prefer to have fresh version. Only problem with php is moving from one subversion to another (like 5.1.x to 5.2.x, 5.2.x to 5.3.x) - there are some general changes and deprecated/removed functions. But newer is faster, secure and better maintained, followed.

p.s.s. I'll never compile anything manually and put files in /usr/local/ in my life, I've learned rpm as I needed it in few days, now everything is running smooth.


No, unfortunately you can't specify custom configure commands with yum. The software provided by yum and other similar package installers is pre-built per vendor specs.

I'd also recommend not going with the latest build of something just because its available, especially on production systems. I've encountered similar issues as your buddy where some strange bug reared its ugly head and I spent hours, days, weeks tracking it down...or just ended up reverting to the old build.

I would do a custom php build as you have done, which is what we do at my company. When a new stable version of php is out, we build it in /usr/local/php-x.x.x, test it, then update binary symlinks and shared libs in /etc/ld.so.conf.d and we're good. Developers always have requests for specific features, so its necessary for us to have the freedom and flexibility of a custom build. You could keep an eye on what version of php CentOS is recommending/distributing, and update at that time.