操作系统:CentOS 5.8 x86 64bit
PHP版本:php 5.2.1
一、获取php版本并解压
PHP各版本下载地址
一般下载 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版本