没有特殊需求的情况下尽量使用yum安装php。centos6下php5.2参考文档

和编译5.2类似,需要首先安装编译环境和依赖:

yum groupinstall 'Development Tools'
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd ./libiconv-1.14
./configure –prefix=/usr/local/libiconv
make && make install

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
如果提示错误信息:make: *** [sapi/cli/php] Error 1
尝试:make ZEND_EXTRA_LIBS='-liconv' 然后make install

yum install libicu-devel

yum install -y gcc gcc-c++ make gmp-devel libc-client-devel zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

ln -s /usr/lib64/libc-client.so  /usr/lib/libc-client.so

cp -frp /usr/lib64/libldap* /usr/lib/

相关依赖处理完毕,开始下载php5.4并解压编译安装:

wget http://cn2.php.net/distributions/php-5.4.45.tar.gz
tar zxvf php-5.4.45.tar.gz
cd  php-5.4.45
./configure \
–prefix=/usr/local/php5.4 \
–with-apxs2=/usr/sbin/apxs \
–with-config-file-path=/usr/local/php5.4/etc \
–with-mysql \
–with-mysqli \
–with-iconv-dir=/usr/local/libiconv \
–with-config-file-scan-dir=/usr/local/php5.4/php.d \
–with-mhash=/usr \
–with-icu-dir=/usr \
–with-bz2 \
–with-curl \
–with-freetype-dir \
–with-gd \
–with-gettext \
–with-gmp \
–with-imap \
–with-imap-ssl \
–with-jpeg-dir \
–with-kerberos \
–with-ldap \
–with-mcrypt \
–with-openssl \
–without-pear \
–with-pdo-mysql \
–with-png-dir \
–with-xmlrpc \
–with-zlib \
–enable-bcmath \
–enable-calendar \
–enable-ctype \
–enable-dom \
–enable-exif \
–enable-ftp \
–enable-gd-native-ttf \
–enable-intl \
–enable-json \
–enable-mbstring \
–enable-pcntl \
–enable-session \
–enable-shmop \
–enable-simplexml \
–enable-soap \
–enable-sockets \
–enable-tokenizer \
–enable-wddx \
–enable-xml \
–enable-zip \
–disable-fileinfo

预编译通过后进行make

make -j $Cpunum && make install

1.png

2.png

安装完成拷贝php配置文件。

mkdir /usr/local/php5.4/etc

cp php.ini-production /usr/local/php5.4/etc/php.ini

3.png

安装完成后修改apache配置文件以便能处理php文件。

/etc/httpd/conf.d 目录下建立一个php.conf

内容为 AddType application/x-httpd-php .php

4.png

保存后重启apache服务。

phpinfo测试页面:

5.png