2007/02/02

转载:Upgrading to PHP 5.2.0 on RHEL and CentOS 4

这是个老外博客上转载的。这老外Fedora Core 7的源代码包编译php5.2.0的RPM,还不错,我测试了,能够成功,继续研究直接将Suhosin Patch 0.9.6.2集成到SRPM中。呵呵 。


With the release of an src.rpm for PHP 5.2.0 in the Fedora Core 7 development branch, I’ve decided to roll out PHP 5.2.0 as a test on a couple of our smaller forums that are running vBulletin 3.6.4. According to the changelog, PHP 5.2.0 has an improved memory-management system. With any luck it’ll be faster than 5.1.6 and won’t break anything in the process.

The procedure to build the PHP 5.2.0 RPMs for RHEL and CentOS 4 is almost identical to the one I used to install PHP 5.1.6 on RHEL and CentOS 4 so this is going to read very similarly to the original how-to. In fact, I recommend reading that post as well before you begin.

One quick warning though, PHP 5.2.0 is currently the bleeding-edge release. I do not recommend that you install it on your production servers without first testing on a development box to make sure that your applications still work as expected. I would also recommend that you build the PHP 5.1.6 RPMs as well, that way you can easily roll back if needed.

To start, you’ll need three things. First, you’re going to need ‘root’ access to your server. If you don’t have it, even if you can build the RPMs, you won’t be able to install them. Second, on most machines, you’ll need to install a huge list of dependencies. Finally, you’ll need the PHP src.rpm from FC7’s development tree.

To start out, if you’ve never built a src.rpm file before, log in to your server as ‘root’ and run the following commands:

  • mkdir /usr/src/redhat
  • chmod 777 -R /usr/src/redhat

After that, you can fill the dependencies using one of the commands below. If you installed a “minimal” system then there may be about 100 packages that get pulled in (if you have the ‘yum’ command, use that, if not, use ‘up2date’). Please note that this list of packages is slightly different than the one for PHP 5.1.6. Make sure that you run one of these commands, even if you’ve already followed my PHP 5.1.6 how-to.

  • yum install wget nano make autoconf automake rpm-build postfix fileutils file libtool gcc cpp gcc-c++ perl-DBI readline-devel libc-client-devel libstdc++-devel 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 krb5-devel cyrus-sasl-devel openldap-devel postgresql-devel unixODBC-devel libxml2-devel net-snmp-devel libxslt-devel libxml2-devel expat-devel ncurses-devel gd-devel freetype-devel
  • up2date -u wget nano make autoconf automake rpm-build postfix fileutils file libtool gcc cpp gcc-c++ perl-DBI readline-devel libc-client-devel libstdc++-devel 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 krb5-devel cyrus-sasl-devel openldap-devel postgresql-devel unixODBC-devel libxml2-devel net-snmp-devel libxslt-devel libxml2-devel expat-devel ncurses-devel gd-devel freetype-devel

There is one more package that you’ll need but where you get it depends on what version of MySQL you use. If you use the default version of MySQL (4.1.20), type one of the following:

  • yum install mysql-devel
  • up2date -u mysql-devel

If you use MySQL 5.0.22 from the CentOS “Plus” repo then download mysql and mysql-devel to your server and then run the following:

  • rpm -Uvh mysql*.rpm

Next, switch to a non-root user, download the PHP 5.2.0 src.rpm and the php-pear 1.4.9 src.rpm to your server, and run the commands:

  • rpm -ivh php-5.2.0-8.src.rpm
  • rpm -ivh php-pear-1.4.9-4.src.rpm
  • cd /usr/src/redhat/SPECS/

All that’s left is to make one small change to the php.spec file (this controls how the src.rpm is compiled and then packaged into rpm files) and then run rpmbuild. Follow the steps below to edit the spec file.

  • nano -w php.spec
  • Press [Ctrl]+[W], type “CFLAGS” (without the double-quotes), and then press [Enter].
  • In the line that is found, remove the text “-Wno-pointer-sign” and the trailing space that is left behind.
  • Press [Ctrl]+[O], [Enter], and then [Ctrl]+[X] to save and then return to the shell.

At this point, all we need to do is build the RPMs. To do that, run the command below.

  • rpmbuild -bb php.spec

Once that finishes (and depending on the system, it may take an hour or more) you’ll have a ton of RPMs in the “/usr/src/redhat/RPMS/i386″ folder. At this point, you can switch back to being ‘root’ and then use “rpm -Uvh filename” to install what you need. You will definitely need the following packages:

  • php
  • php-cli
  • php-common

In all likelihood, you’ll also want:

  • php-mysql
  • php-gd

Once that’s done you’ll want to build and install ‘php-pear’. You can do so by running the commands below.

  • rpmbuild -bb php-pear.spec
  • rpm -ivh ../RPMS/noarch/php-pear-1.4.9-4.noarch.rpm

At this point you should have a fully-functional system running PHP 5.2.0. If you run and Ioncube- or Zend-encoded scripts then make sure you update your loaders. Likewise, if you use a PHP cache like APC or eAccelerator then make sure you rebuild for your new version of PHP otherwise it won’t work. Any questions or comments, let me know.

没有评论: