Tuesday, June 23, 2009

All I want is PHP 5.2 on CentOS/RHEL!

Here at EchoDitto, most of our servers are streaming CentOS Linux, which is a 100% binary-compatible edition of the business accepted Red Hat Enterprise UNIX (RHEL) without some of the fees. The difficulty with RHEL/CentOS is that they shipped with PHP 5.1.6, and as of this composition PHP is at 5.2.9. That's not a big deal, existence a secondary point composition behind, until you become crossways an covering or power that needs a peak of edition 5.2. The terminal abstract I poverty to do is establish packages from a third-party or physique it from maker and venture breaking another packages. So what's the answer? Building it from the maker rpm. There's no meliorate way to ready the grouping liberated of third-party packages but also up to date.

Why maker RPMs and not the maker from PHP? Building a maker RPM is the aforementioned procedure utilised to physique the packages that Red Hat creates, and includes the libraries and dependencies and sub-packages that you would ordinarily intend from Red Hat directly. It module also allow every of the aforementioned physique flags in your newborn edition that were acquirable in the senior package, message your PHP scripts won't dead break. This finally ensures star sympathy and the knowledge to easily upgrade if Red Hat or CentOS were to promulgation a collection newer than yours.

Sure, you could enable the CentOS Testing repository, but with every of the warnings most packages breaking your system, and configuring yum to exclusive update PHP and not disorderliness up mysql or Apache, I'd kinda physique and establish exclusive the packages that I requirement without bedevilment most breaking another packages. Want PHP 5.2 on your CentOS or RHEL server? Follow along.

  • Start by downloading the stylish PHP 5.2 maker RPM from the aforementioned CentOS Testing intimate from http://dev.centos.org/centos/5/testing/SRPMS/. As of this writing, they're at php-5.2.6-2. Why aren't we using the 5.1.6 source? The maker RPM for 5.2.6 includes the stylish patches from Red Hat that you crapper ordinarily exclusive intend from existence a conception of the non-free Red Hat Network.

    I'll adopt you're streaming as stem for this guide. Download the maker RPM with wget # wget http://dev.centos.org/centos/5/testing/SRPMS/php-5.2.6-2.el5s2.src.rpm

  • Install the maker RPM # rate -ivh php-5.2.6-2.el5s2.src.rpm

  • If you intend an nonachievement and the establish fails, you haw requirement to manually create the SOURCES directory and establish again # mkdir -p /usr/src/redhat/SOURCES # rate -ivh php-5.2.6-2.el5s2.src.rpm
  • Download the stylish stable promulgation of PHP from the php.net download tender and save it in the SOURCES folder. Change the edition number to the stylish edition if needed. # cd /usr/src/redhat/SOURCES # wget http://us3.php.net/get/php-5.2.9.tar.gz/from/us.php.net/
  • In the SPECS folder, double the example php.spec enter in housing you attain mistakes or desire to physique 5.2.6. # cd /usr/src/redhat/SPECS # cp php.spec php526.spec
  • Edit php.spec and modify the edition and composition drawing to be 5.2.9 (or later) and the composition to 1 since this is your prototypal build. Summary: The PHP HTML-embedded scripting language Name: php Version: 5.2.9 Release: 1%{?dist} License: PHP Group: Development/Languages URL: http://www.php.net/
  • Make sure you hit the Development Tools assemble establish for rpmbuild if you haven't already finished so. # yum groupinstall "Development Tools"
  • Try and physique the description enter to wager if you are absent some packages. For this tutorial, I am streaming from the bottom collection set. # rpmbuild -ba php.spec cat: /usr/include/httpd/.mmn: No such enter or directory error: Failed physique dependencies: bzip2-devel is necessary by php-5.2.9-1.i386 curl-devel >= 7.9 is necessary by php-5.2.9-1.i386 db4-devel is necessary by php-5.2.9-1.i386 expat-devel is necessary by php-5.2.9-1.i386 gmp-devel is necessary by php-5.2.9-1.i386 aspell-devel >= 0.50.0 is necessary by php-5.2.9-1.i386 httpd-devel >= 2.0.46-1 is necessary by php-5.2.9-1.i386 libjpeg-devel is necessary by php-5.2.9-1.i386 libpng-devel is necessary by php-5.2.9-1.i386 pam-devel is necessary by php-5.2.9-1.i386 openssl-devel is necessary by php-5.2.9-1.i386 sqlite-devel >= 3.0.0 is necessary by php-5.2.9-1.i386 zlib-devel is necessary by php-5.2.9-1.i386 pcre-devel >= 6.6 is necessary by php-5.2.9-1.i386 readline-devel is necessary by php-5.2.9-1.i386 krb5-devel is necessary by php-5.2.9-1.i386 libc-client-devel is necessary by php-5.2.9-1.i386 cyrus-sasl-devel is necessary by php-5.2.9-1.i386 openldap-devel is necessary by php-5.2.9-1.i386 mysql-devel >= 4.1.0 is necessary by php-5.2.9-1.i386 postgresql-devel is necessary by php-5.2.9-1.i386 unixODBC-devel is necessary by php-5.2.9-1.i386 libxml2-devel is necessary by php-5.2.9-1.i386 net-snmp-devel is necessary by php-5.2.9-1.i386 libxslt-devel >= 1.0.18-1 is necessary by php-5.2.9-1.i386 libxml2-devel >= 2.4.14-1 is necessary by php-5.2.9-1.i386 ncurses-devel is necessary by php-5.2.9-1.i386 gd-devel is necessary by php-5.2.9-1.i386 freetype-devel is necessary by php-5.2.9-1.i386
  • Install some required packages with yum. If some of these packages hit another dependencies they module be downloaded as well. This strength verify a while. # yum establish bzip2-devel curl-devel db4-devel expat-devel gmp-devel aspell-devel \ httpd-devel libjpeg-devel libpng-devel pam-devel openssl-devel sqlite-devel zlib-devel \ pcre-devel readline-devel krb5-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
  • Try and physique the description enter again to wager if some patches change to alluviation properly. This commonly happens if a connector has been rolled into the mainline PHP send and is no longer needed. # rpmbuild -ba php.spec Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.81391 + umask 022 + cd /usr/src/redhat/BUILD + LANG=C + export LANG + unset DISPLAY + cd /usr/src/redhat/BUILD + rm -rf php-5.2.9 + /bin/gzip -dc /usr/src/redhat/SOURCES/php-5.2.9.tar.gz + bitumen -xf - + STATUS=0 ... production snipped ... Patch #32 (php-5.2.5-systzdata.patch): + connector -p1 -b --suffix .systzdata -s + reflexion 'Patch #50 (php-5.2.4-tests-dashn.patch):' Patch #50 (php-5.2.4-tests-dashn.patch): + connector -p1 -b --suffix .tests-dashn -s Reversed (or previously applied) connector detected! Assume -R? [n] Apply anyway? [n] 1 discover of 1 piece unnoticed -- action rejects to enter ext/standard/tests/file/bug26615.phpt.rej 1 discover of 1 piece FAILED -- action rejects to enter ext/standard/tests/file/proc_open01.phpt.rej Reversed (or previously applied) connector detected! Assume -R? [n] Apply anyway? [n] 1 discover of 1 piece unnoticed -- action rejects to enter ext/standard/tests/file/bug26938.phpt.rej error: Bad opening position from /var/tmp/rpm-tmp.81391 (%prep) RPM physique errors: Bad opening position from /var/tmp/rpm-tmp.81391 (%prep)
  • Looks aforementioned Patch 50 failed. Edit the description enter and interpret discover the distinction that begins with %patch50 %patch30 -p1 -b .dlopen %patch31 -p1 -b .easter %patch32 -p1 -b .systzdata #%patch50 -p1 -b .tests-dashn %patch51 -p1 -b .tests-wddx
  • For 5.2.9 as of this writing, this is the exclusive connector that fails to alluviation properly. In after versions, you haw encounter that another patches change to load, and you should interpret those discover as well.
  • Build the description enter again and after individual minutes it module be rank and you'll hit a containerful of rpms in /usr/src/redhat/RPMS/i386 # rpmbuild -ba php.spec Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.77534 + umask 022 + cd /usr/src/redhat/BUILD + LANG=C + export LANG + unset DISPLAY + cd /usr/src/redhat/BUILD + rm -rf php-5.2.9 + /bin/gzip -dc /usr/src/redhat/SOURCES/php-5.2.9.tar.gz + bitumen -xf - + STATUS=0 ... production snipped ... Wrote: /usr/src/redhat/RPMS/i386/php-ncurses-5.2.9-1.i386.rpm Wrote: /usr/src/redhat/RPMS/i386/php-gd-5.2.9-1.i386.rpm Wrote: /usr/src/redhat/RPMS/i386/php-bcmath-5.2.9-1.i386.rpm Wrote: /usr/src/redhat/RPMS/i386/php-dba-5.2.9-1.i386.rpm Wrote: /usr/src/redhat/RPMS/i386/php-debuginfo-5.2.9-1.i386.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.7525 + umask 022 + cd /usr/src/redhat/BUILD + cd php-5.2.9 + '[' /var/tmp/php-5.2.9-1-root-root '!=' / ']' + rm -rf /var/tmp/php-5.2.9-1-root-root + rm files.bcmath files.common files.dba files.dbase files.dom files.gd files.imap [snip] + opening 0  
  • You'll belike poverty to also physique the php-extras maker RPM as well. php-extras provides extensions for dbase, readline, mcrypt, mhash, order and mssql. Since there is no collection in CentOS Testing, clutch the stylish from 5.1.6. # wget http://mirror.centos.org/centos/5/extras/SRPMS/php-extras-5.1.6-15.el5.centos.1.src.rpm
  • And establish it. # rate -ivh php-extras-5.1.6-15.el5.centos.1.src.rpm
  • Copy the php-extras.spec enter aforementioned you did for php.spec so you crapper hit the original. # cd /usr/src/redhat/SPECS # cp php-extras.spec php-extras516.spec
  • We finally requirement to change the patches in php-extras.spec with the aforementioned from the such newer php.spec, as substantially as the ABI edition drawing in the first of the file. Webtatic.com has already finished this and you crapper go ahead and download the altered description file, which also includes newborn PHP 5.2 extensions for json and filter. Remember, if you had a unsuccessful connector from php.spec, you'll requirement to interpret it discover in php-extras.spec as well. For 5.2.9, I had to interpret discover patch50 again. %patch32 -p1 -b .systzdata #%patch50 -p1 -b .tests-dashn %patch51 -p1 -b .tests-wddx %build  
  • Once your php-extras.spec enter is up to date, physique the description enter and wager if you're absent some dependencies. # rpmbuild -ba php-extras.spec error: Failed physique dependencies: php-devel = 5.2.9 is necessary by php-extras-5.2.9-1.i386 libmcrypt-devel is necessary by php-extras-5.2.9-1.i386 mhash-devel is necessary by php-extras-5.2.9-1.i386 libtidy-devel is necessary by php-extras-5.2.9-1.i386 freetds-devel is necessary by php-extras-5.2.9-1.i386
  • Let's go backwards and establish the php collection that we need. If you exclusive poverty the peak necessary to physique php-extras, move by instalment php-devel and sight what it asks for, and establish it's dependencies. # cd /usr/src/redhat/RPMS/i386 # rate -ivh php-devel-5.2.9-1.i386.rpm error: Failed dependencies: php = 5.2.9-1 is necessary by php-devel-5.2.9-1.i386 # rate -ivh php-5.2.9-1.i386.rpm php-devel-5.2.9-1.i386.rpm error: Failed dependencies: php-cli = 5.2.9-1 is necessary by php-5.2.9-1.i386 php-common = 5.2.9-1 is necessary by php-5.2.9-1.i386 # rate -ivh php-5.2.9-1.i386.rpm php-devel-5.2.9-1.i386.rpm php-cli-5.2.9-1.i386.rpm php-common-5.2.9-1.i386.rpm Preparing... ########################################### [100%] 1:php-common ########################################### [ 25%] 2:php-cli ########################################### [ 50%] 3:php ########################################### [ 75%] 4:php-devel ########################################### [100%]
  • After instalment those quaternary packages, establish the another packages with yum. # yum establish libmcrypt-devel mhash-devel libtidy-devel freetds-devel
  • Now that every of the dependencies are resolved, physique the php-extras.spec file. # cd /usr/src/redhat/SPECS # rpmbuild -ba php-extras.spec
  • If you're using RHEL, the physique strength change for digit reasons: a accumulation for order is needed, and mhash-devel isn't acquirable for RHEL. Both are cushy to fix. Install 'tidy' with yum, and connector mhash-devel isn't available, you crapper download libmhash-devel and modify the description enter to order libmhash-devel instead of mhash-devel.

    You should today hit every of your RPMs in /usr/src/redhat/RPMS/i386 (or x86_64) and establish whichever packages you want. If in doubt, establish them all. They're mainly static libraries and won't bloat your system. You haw not poverty to establish the debuginfo packages since you haw encounter lowercase ingest for them.

    Staying updated is easy, download the maker from php.net into /usr/src/redhat/SOURCES and modify the description files for the newborn edition numbers, rebuild, and establish RPMs. If you're afraid most newborn patches existence needed, you crapper clutch the stylish maker RPM from Centos: http://dev.centos.org/centos/5/testing/SRPMS/. If CentOS were to ever become discover with a newer version, or you poverty to hold to a yum repo and they provided a higher version, it would update as normal. You would requirement to physique in pear/pecl libraries by uninstall+installing them.

    Yes, this is an participating process the prototypal instance around, but after doing this erst you exclusive requirement to download the stylish maker from php.net and modify the description enter edition number and physique and update. If an older connector fails in a newer edition you'll requirement to interpret it out, but it's that simple.

    This also works for 64-bit installations. Thanks to DiNo for serving me intend PHP built on a 64-bit RHEL installation.

    If you'd aforementioned to resile the steps and intend correct to building, you crapper download and establish the maker RPMs and physique again the description files. If you'd aforementioned to do itself, you crapper study my description files to yours. Enjoy the stylish PHP hotness!

    • PHP Spec files
    • php 5.2.9 maker RPM MD5 = 008d5f2ced015c5f6463afb616737b04
    • php-extras 5.2.9 maker RPM MD5 = 2f8a7e815170bf31509180c196ade19a

  • No comments:

    Post a Comment