1.下载PHP5.0.4最新版本
我们可以从官方网站下载最新版本,也可以从本站下载php5.0.4版本。 [root@eygle opt]# wget
http://cn2.php.net/get/php-5.0.4.tar.gz/from/cn.php.net/mirror--00:56:34--
http://cn2.php.net/get/php-5.0.4.tar.gz/from/cn.php.net/mirror => `mirror'
Resolving cn2.php.net... done.
Connecting to cn2.php.net[219.239.98.8]:80...
[root@eygle opt]# wget
http://cn.php.net/distributions/php-5.0.4.tar.gz--00:57:37--
http://cn.php.net/distributions/php-5.0.4.tar.gz => `php-5.0.4.tar.gz'
Resolving cn.php.net... done.
Connecting to cn.php.net[61.129.33.155]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5,839,214 [application/x-gzip]
100%[===============================================================>] 5,839,214 1.16M/s ETA 00:00
00:57:42 (1.16 MB/s) - `php-5.0.4.tar.gz' saved [5839214/5839214]
2.解压缩
[root@eygle opt]# gzip -d php-5.0.4.tar.gz
[root@eygle opt]# tar -xvf php-5.0.4.tar
php-5.0.4/
php-5.0.4/ext/
php-5.0.4/ext/gd/
php-5.0.4/ext/gd/gd.c
php-5.0.4/ext/gd/gd_ctx.c
php-5.0.4/ext/gd/libgd/
......
php-5.0.4/CREDITS
php-5.0.4/README.UNIX-BUILD-SYSTEM
php-5.0.4/buildconf.bat
[root@eygle opt]# cd php-5.0.4
[root@eygle php-5.0.4]# ls
acconfig.h ext missing README.QNX snapshot
acconfig.h.in EXTENSIONS mkinstalldirs README.SELF-CONTAINED-EXTENSIONS stamp-h.in
acinclude.m4 footer netware README.STREAMS stub.c
aclocal.m4 generated_lists NEWS README.SUBMITTING_PATCH tests
build genfiles pear README.TESTING TODO
buildconf header php5.spec.in README.TESTING2 TODO-5.1
buildconf.bat INSTALL php.gif README.UNIX-BUILD-SYSTEM TODO.BUILDv5
CODING_STANDARDS install-sh php.ini-dist README.WIN32-BUILD-SYSTEM TODO-PHP5
config.guess LICENSE php.ini-recommended README.Zeus TSRM
config.sub ltmain.sh README.CVS-RULES regex win32
configure main README.EXTENSIONS run-tests-config.php Zend
configure.in makedist README.EXT_SKEL run-tests.php
CREDITS Makefile.frag README.input_filter sapi
cvsclean Makefile.global README.PARAMETER_PARSING_API scripts
cvsclean.bat makerpm README.PHP4-TO-PHP5-THIN-CHANGES server-tests.php
3.配置
[root@eygle php-5.0.4]# ./configure --enable-track-vars --with-mysql --with-dom --with-zlib-dir
--with-curl --with-iconv --with-mbstring --enable-module=so --with-apxs2
creating cache ./config.cache
checking host system type... i686-pc-linux-gnu
checking for gcc... gcc
....
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... /tmp/mysql.sock
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore.
注意在这里第一个错误出现,这是由于--with-mysql没有指定配置路径导致的。
修改后再次运行configure成功。
[root@eygle php-5.0.4]# ./configure --with-apxs2=/opt/apache/bin/apxs --with-mysql=/opt/mysql
--enable-track-vars --with-dom --with-zlib-dir --with-curl --with-iconv --with-mbstring
loading cache ./config.cache
checking host system type... i686-pc-linux-gnu
checking for gcc... (cached) gcc
......
creating libtool
Generating files
updating cache ./config.cache
creating ./config.status
creating php5.spec
creating main/build-defs.h
creating scripts/phpize
creating scripts/php-config
creating sapi/cli/php.1
creating main/php_config.h
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
4.编译
[root@eygle php-5.0.4]# make
....
Build complete.
(It is safe to ignore warnings about tempnam and tmpnam).
5.安装
[root@eygle php-5.0.4]# make install
Installing PHP SAPI module: apache2handler
/opt/apache/build/instdso.sh SH_LIBTOOL='/opt/apache/build/libtool' libphp5.la /opt/apache/modules
/opt/apache/build/libtool --mode=install cp libphp5.la /opt/apache/modules/
cp .libs/libphp5.so /opt/apache/modules/libphp5.so
cp .libs/libphp5.lai /opt/apache/modules/libphp5.la
libtool: install: warning: remember to run `libtool --finish /opt/php-5.0.4/libs'
chmod 755 /opt/apache/modules/libphp5.so
[activating module `php5' in /opt/apache/conf/httpd.conf]
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/man/man1/
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Archive_Tar - already installed: 1.1
[PEAR] Console_Getopt - already installed: 1.2
[PEAR] PEAR - already installed: 1.3.5
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
[PEAR] HTML_Template_IT- already installed: 1.1
[PEAR] Net_UserAgent_Detect- already installed: 2.0.1
[PEAR] XML_RPC - already installed: 1.2.2
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
program: phpextdist
[root@eygle php-5.0.4]# libtool --finish /opt/php-5.0.4/libs
PATH="$PATH:/sbin" ldconfig -n /opt/php-5.0.4/libs
----------------------------------------------------------------------
Libraries have been installed in:
/opt/php-5.0.4/libs
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
--------------------------------------------------------------------
此时安装结束。
6.进行适当链接
你可以按照习惯对PHP进行链接
[root@eygle bin]# ln -s /opt/php/bin/php /usr/bin
[root@eygle bin]# which php
/usr/bin/php
[root@eygle bin]# php -v
PHP 5.0.4 (cli) (built: Aug 14 2005 01:11:42)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies
7.重新启动Apache
以加载新的php module [root@eygle opt]# apachectl stop
[root@eygle opt]# apachectl start
正常情况下,到这里就应该正常了,可是我却发现php不能正常使用,在error log里记录了类似如下的错误:
[root@eygle logs]# tail -f error_log
[Sun Aug 14 03:48:17 2005] [notice] child pid 27697 exit signal Segmentation fault (11)
[Sun Aug 14 03:48:17 2005] [notice] child pid 27705 exit signal Segmentation fault (11)
[Sun Aug 14 03:48:22 2005] [notice] child pid 27707 exit signal Segmentation fault (11)
[Sun Aug 14 03:48:25 2005] [notice] child pid 27683 exit signal Segmentation fault (11)
[Sun Aug 14 03:48:30 2005] [notice] child pid 27686 exit signal Segmentation fault (11)
[Sun Aug 14 03:48:36 2005] [notice] child pid 27685 exit signal Segmentation fault (11)
[Sun Aug 14 03:48:37 2005] [notice] child pid 27709 exit signal Segmentation fault (11)
[Sun Aug 14 03:48:38 2005] [notice] child pid 27711 exit signal Segmentation fault (11)
在网上搜索了一下,很多人遇到这个问题,但是就是没有解答,有人说5.0.4版本太新了,有Bug,用低版本的。
可是我不相信这个简单的解释。
分析一下,发现在Server端php能正常运行/执行,可是通过apache访问就不行了。
我还是怀疑问题不在php而是在apache。
在分析apache日志,发现重起时有如下一条记录:
[Sun Aug 14 03:47:50 2005] [notice] caught SIGTERM, shutting down
[Sun Aug 14 03:47:53 2005] [notice] Apache/2.0.49 (Unix) DAV/2 PHP/4.4.0 PHP/5.0.4 configured
-- resuming normal operations
在Apache启动时记录了两个PHP版本:PHP/4.4.0 PHP/5.0.4
我怀疑这里存在问题,打开apache的配置文件(httpd.conf)看,发现存在如下两行:
LoadModule php4_module modules/libphp4.so
LoadModule php5_module modules/libphp5.so
Apache在这里加载php的module,由于之前装过4.4.0的php,所以这里存在两条记录。
尝试注释php4_module的记录,重起apache之后,系统恢复正常。