操作系统:CentOS 5.8 x86 64bit
PHP版本:php 5.2.1
一、获取php版本并解压
PHP各版本下载地址 http://www.php.net/releases/
一般下载 tar.gz 的包。
- tar -xzvf php-5.2.1.tar.gz
- cd php-5.2.1
二、安装PHP编译安装需要的组件的开发包 及编译工具等
- yum -y install gcc gcc-c++ perl
- yum -y install flex autoconf zlib libtiff-devel pam-devel
- yum -y install libtool libtool-ltdl libtool-ltdl-devel
- yum -y install bison bison-devel
- yum -y libxslt libxslt libxslt-devel
- yum -y install ncurses ncurses-devel
- yum -y install zlib zlib-devel
- yum -y install openssl openssl-devel
- yum -y install gnutls-devel
- yum -y install libmcrypt libmcrypt-devel
- yum -y install libxml2 libxml2-devel
- yum -y install openssl openssl-devel
- yum -y install bzip2 bzip2-devel
- yum -y install curl curl-devel
- yum -y install libjpeg libjpeg-devel
- yum -y install libpng libpng-devel
- yum -y install freetype-devel
- yum -y install gmp-devel
- yum -y install mysql-devel
- yum -y install ncurses ncurses-devel
- yum -y install unixODBC-devel
- yum -y install pspell-devel
- yum -y install net-snmp net-snmp-devel
- yum -y install openldap-devel openldap-servers openldap-clients
有些包可能是你不需要的,你可以按具体需求增减,另外mcrypt,Libmcrypt,mhash这三个包如果yum安装无法获得,采取文章后面的解决方法。
三、编译三步骤 configure ,make , make install
1、configure
- ./configure --prefix=/usr/local/php --with-apxs2=/usr/sbin/apxs --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/etc/php.d --without-sqlite --enable-mbstring --with-curl --with-gettext --with-bz2 --with-mysql=/usr/lib64/mysql -enable-shmop --enable-calendar --with-openssl --with-pspell --enable-ftp --with-openssl --with-zlib --enable-exif --with-gmp --enable-sysvmsg --enable-sockets --enable-wddx --with-xsl --with-mcrypt --with-mysqli --with-mime_magic --with-pdo-mysql --libdir=/usr/lib64 --with-libdir=lib64 --with-gd --with-jpeg-dir=/usr/lib64 --with-png-dir=/usr/lib64 --with-freetype-dir=/usr/lib64
这里有几个注意点:
a、指定安装路径,方便换版本及删除,也方便自己查找文件。
b、指定apache的相关文件apxs2的路径,这个文件安装了httpd-devel才有
c、指定配置文件路径,方便配置
d、指定相关lib文件的路径,本文是在64位系统下的lib64
2、make
make的时候可能会提示什么xxx没找到,解决方法一般是安装xxx-devel的包就可以了。
3、make install
只要configure和make过了后,make install一般没问题,该命令执行后会出现一些安装信息的提示,务必得一个单词一个单词的看懂看明白,譬如这句:
libtool: install: warning: remember to run `libtool --finish /software/php-5.2.1/libs'
- [root@localhost php-5.2.1]# make install
- Installing PHP SAPI module: apache2handler
- /usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp5.la /usr/lib64/httpd/modules
- /usr/lib64/apr-1/build/libtool --mode=install cp libphp5.la /usr/lib64/httpd/modules/
- cp .libs/libphp5.so /usr/lib64/httpd/modules/libphp5.so
- cp .libs/libphp5.lai /usr/lib64/httpd/modules/libphp5.la
- libtool: install: warning: remember to run `libtool --finish /software/php-5.2.1/libs'
- chmod 755 /usr/lib64/httpd/modules/libphp5.so
- [activating module `php5' in /etc/httpd/conf/httpd.conf]
- Installing PHP CLI binary: /usr/local/php/bin/
- Installing PHP CLI man page: /usr/local/php/man/man1/
- Installing build environment: /usr/lib64/build/
- Installing header files: /usr/local/php/include/php/
- Installing helper programs: /usr/local/php/bin/
- program: phpize
- program: php-config
- Installing man pages: /usr/local/php/man/man1/
- page: phpize.1
- page: php-config.1
- Installing PEAR environment: /usr/lib64/php/
- [PEAR] Console_Getopt - installed: 1.2
- [PEAR] Archive_Tar - installed: 1.3.2
- pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
- [PEAR] PEAR - installed: 1.4.11
- Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
- You may want to add: /usr/lib64/php to your php.ini include_path
- Installing PDO headers: /usr/local/php/include/php/ext/pdo/
- [root@localhost php-5.2.1]#
四、复制php配置文件
- cp php.ini-dict /usr/local/etc/php.ini
五、让apache调用这个php版本
1、查看httpd.conf,检查php模块有没有被调用
- #LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so
- #检查上面的#号去掉没,php安装的时候一般会自动加上这行,但是还是确认一下。
- LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so
2、查看httpd.conf,添加对PHP的解析
- AddType application/x-httpd-php .php .phtml
- AddType application/x-httpd-php-source .phps set-variable = max_connections=100
七、测试
1、在apache中配置个站点,在http.conf后增加如下内容
- listen 60080
- <VirtualHost *:60080>
- ServerAdmin root@test_web_site
- DocumentRoot /var/www/html/test_web_site
- DirectoryIndex index.php
- ServerName www.test.com
- ServerAlias test.com
- ErrorLog logs/www.test.com-error_log
- TransferLog logs/www.test.com-access_log
- </VirtualHost>
- <Directory /var/www/html/test_web_site>
- Options FollowSymLinks
- AllowOverride All
- Order deny,allow
- Allow from all
- </Directory>
2、在路径/var/www/html/test_web_site 中把php探针文件上传进去,探针文件文章后有附件下载。
注:感谢探针 程序设计: 田慧民 Shvip
3、访问 http://xx.xx.xx.xx:60080 ,看是否有PHP网页可以访问
六、一些问题
1、关于mcrypt,Libmcrypt,mhash的安装
下载地址
http://sourceforge.net/projects/mcrypt/files/Libmcrypt/
http://sourceforge.net/projects/mcrypt/files/MCrypt/
http://sourceforge.net/projects/mhash/files/mhash/
先安装Libmcrypt,再安装mhash,再安装mcrypt
命令都是
./configure
make
make install
如果configure mcrypt时提示找不到libmcrypt的库,给个参考的解决方法
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
然后再配置。