Building packages out of PECL modules
I’ve had a need to distribute the memcached and APC modules to various web servers in a farm. pecl/pear modules have a pretty cool interface similiar to yum, but it’s all based on source. It does, however, have facilities to help you build an RPM. Because I try to use RPM for everything I was pretty happy that this takes the work out of making the .spec file. However the generated specfile needs a lot of work.
You’ll need php-devel, httpd-devel, php-pear, rpm-build (and probably more, but it’s usually obvious)
First upgrade the package that builds the RPMs… It was changed from the version I had:
pear install channel://pear.php.net/PEAR_Command_Packaging-0.1.2
then upgrade pear otherwise you’ll end up with some really odd errors that make no sense
pear upgrade-all
Then download the module you want, ie
pecl download pecl/APC
and build a .spc file
pecl make-rpm-spec /tmp/APC-3.0.14.tgz
That will generate PECL::APC-3.0.14.spec. Move that file to /usr/src/redhat/SPECS and move the tarball to the SOURCES directory.
You’ll need to make a few changes to the .spec.
- Change the BuildRequires to require php-pear
- Change all instances of package2.xml to package.xml
- Add /usr/lib/php/modules/apc.so to the %files section
Then you should be able to build the package cleanly — rpmbuild -ba PECL\:\:APC-3.0.14.spec
That’s not all, though… You’ll want to include a config file. Make one in the SOURCES directory, ie pecl-apc.ini. It must contain the extension line, the rest are optional (I’m just getting into APC, so my values might be completely wrong)
extension=apc.so
apc.shm_size=512
apc.ttl=60
apc.write_lock=1
Add the following to the top of your .spec file, right under Source0:
Source1: pecl-apc.ini
and at the end of the %install section (right before %clean)
mkdir -p %{buildroot}/etc/php.d/
cp %{SOURCE1} %{buildroot}/etc/php.d/apc.ini
and finally, in the %files section:
%config /etc/php.d/apc.ini
This copies the config file into the php.d directory within the buildroot (where all the files go before they’re packaged up), and defines it as a config file to be included with the RPM. Thus, upgrades won’t stomp on your changes.
APC also includes a file called apc.php that can be used to check the status of the cache… Similar techniques can be used to copy it into /var/www/html, or put an Alias entry in /etc/httpd/conf.d/apc.conf
Update on Jan 8, 2010
Mike (see comments below) indicated some changes in PEAR necessitated a change in the .spec as follows:
%post
pear install --nodeps --soft --force --register-only --nobuild %{xmldir}/APC.xml

I needed to do the same thing – create an RPM for pecl/apc. I’m using APC-3.1.3p1 and Pear Command Packaging 0.2.0. The RPM builds nicely, but when I attempt to install the binary RPM on the target machine it says:
48 source files, building
running: phpize
Cannot find config.m4.
Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module
ERROR: `phpize’ failed
Not sure what to do at this point… any thoughts?
Thanks!
January 7th, 2010 at 9:55 am