Create CentOS PHP RPM

YUM Prerequisites

Before we start, we need to have all the dependencies installed:

# yum install bzip2-devel db4-devel expat-devel gmp-devel aspell-devel httpd-devel \
libjpeg-develpam-devel sqlite-devel pcre-devel readline-devel libc-client-devel \
cyrus-sasl-devel openldap-devel mysql-devel postgresql-devel unixODBC-devel \
libxml2-devel net-snmp-devel libxslt-devel libxml2-devel ncurses-devel gd-devel \
freetype-devel pam-devel

RPM Build Environment

Now setup your build environment:

1. Create a .rpmmacros in your home directory, with at least the following content:

%packager       Your Name <your.name@your-org.com>
%vendor         Your Orgnazation
%_topdir        /home/your_uid/rpm
 
%_signature     gpg
%_gpg_name      Your Packaging Dept <rpm@your-org.com>
%_gpg_path      /home/your_uid/.gnupg
 
%dist           build_id
 

2. Create the rpm directory:

% mkdir -p $HOME/rpm/{BUILD,RPMS/i386,SOURCES,SPECS,SRPMS}

Download the Source RPM

As of today, php-5.2.9-2 is the latest on http://dev.centos.org/centos/5/testing/SRPMS/. Check back often on that site for updates.

Now download the src rpm:

% wget http://dev.centos.org/centos/5/testing/SRPMS/php-5.2.9-2.el5.centos.src.rpm

Rebuild the Source RPM

If you only want to build the standard parckage without the extra, you can do:

% rpmbuild --rebuild --sign php-5.2.9-2.el5.centos.src.rpm

Customize the Source RPM

1. Install the source RPM:

% rpm -Uvh --prefix $HOME php-5.2.9-2.el5.centos.src.rpm

Now compile the package (the equivilant of doing rpmbuild --rebuild ... as above):

% cd $HOME/rpm
% rpmbuild -bb --sign SPEC/php.spec

This gives us the following packages:

php-5.2.9-2seim.i386.rpm             php-mysql-5.2.9-2seim.i386.rpm
php-bcmath-5.2.9-2seim.i386.rpm      php-ncurses-5.2.9-2seim.i386.rpm
php-cli-5.2.9-2seim.i386.rpm         php-odbc-5.2.9-2seim.i386.rpm
php-common-5.2.9-2seim.i386.rpm      php-pdo-5.2.9-2seim.i386.rpm
php-dba-5.2.9-2seim.i386.rpm         php-pgsql-5.2.9-2seim.i386.rpm
php-devel-5.2.9-2seim.i386.rpm       php-snmp-5.2.9-2seim.i386.rpm
php-gd-5.2.9-2seim.i386.rpm          php-soap-5.2.9-2seim.i386.rpm
php-imap-5.2.9-2seim.i386.rpm        php-xml-5.2.9-2seim.i386.rpm
php-ldap-5.2.9-2seim.i386.rpm        php-xmlrpc-5.2.9-2seim.i386.rpm
php-mbstring-5.2.9-2seim.i386.rpm

To add the extra packages, edit SPEC/php.spec:

mcrypt

To add mcrypt to the package, first insert the following lines into the section for "%package" in php.spec:

%package mcrypt
Summary: Standard PHP module provides mcrypt library support
Group: Development/Languages
Requires: php >= %{version}, php-api = %{apiver}
BuildRequires: libmcrypt-devel
 
%description mcrypt
Standard PHP module provides mcrypt library support

Then add --with-mcrypt to the build section:

# Build /usr/bin/php-cgi with the CGI SAPI, and all the shared extensions
pushd build-cgi
build --enable-force-cgi-redirect \
      --enable-pcntl \
      ......
      --with-mcrypt=shared \
      .......

Then add "mcrypt" to the section for stub .init:

# Generate files lists and stub .ini files for each subpackage
for mod in pgsql mysql mysqli odbc ldap snmp xmlrpc imap \
    mbstring mcrypt ncurses gd dom xsl soap bcmath dba xmlreader xmlwriter \
    pdo pdo_mysql pdo_pgsql pdo_odbc pdo_sqlite json zip \
    dbase; do
    cat > $RPM_BUILD_ROOT%{_sysconfdir}/php.d/${mod}.ini <<EOF

Then add this line to the "%file" section:

%files mcrypt -f files.mcrypt

 

mhash

To add mhash to the package, first insert the following lines into the section for "%package" in php.spec:

%package mhash
Summary: Standard PHP module provides mhash support
Group: Development/Languages
Requires: php >= %{version}, php-api = %{apiver}
BuildRequires: mhash-devel
 
%description mhash
Standard PHP module provides mhash support

Then add --with-mhash to the build section:

# Build /usr/bin/php-cgi with the CGI SAPI, and all the shared extensions
pushd build-cgi
build --enable-force-cgi-redirect \
      --enable-pcntl \
      ......
      --with-mhash=shared \
      .......

Then add "mhash" to the section for stub .init:

# Generate files lists and stub .ini files for each subpackage
for mod in pgsql mysql mysqli odbc ldap snmp xmlrpc imap \
    mbstring mcrypt mhash ncurses gd dom xsl soap bcmath dba xmlreader xmlwriter \
    pdo pdo_mysql pdo_pgsql pdo_odbc pdo_sqlite json zip \
    dbase; do
    cat > $RPM_BUILD_ROOT%{_sysconfdir}/php.d/${mod}.ini <<EOF

Then add this line to the "%file" section:

%files mhash -f files.mhash

tidy

To add tidy to the package, first insert the following lines into the section for "%package" in php.spec:

%package tidy
Summary: Standard PHP module provides tidy library support
Group: Development/Languages
Requires: php >= %{version}, php-api = %{apiver}
BuildRequires: libtidy-devel
 
%description tidy
Standard PHP module provides tidy library support

Then add --with-tidy to the build section:

# Build /usr/bin/php-cgi with the CGI SAPI, and all the shared extensions
pushd build-cgi
build --enable-force-cgi-redirect \
      --enable-pcntl \
      ......
      --with-tidy=shared \
      .......

Then add "tidy" to the section for stub .init:

# Generate files lists and stub .ini files for each subpackage
for mod in pgsql mysql mysqli odbc ldap snmp xmlrpc imap \
    mbstring mcrypt mhash tidy ncurses gd dom xsl soap bcmath dba xmlreader xmlwriter \
    pdo pdo_mysql pdo_pgsql pdo_odbc pdo_sqlite json zip \
    dbase; do
    cat > $RPM_BUILD_ROOT%{_sysconfdir}/php.d/${mod}.ini <<EOF

Then add this line to the "%file" section:

%files tidy -f files.tidy

Now compile again:

% rpmbuild -bb --sign SPEC/php.spec