本文档介绍centos6 x64版本在安装完apache和mysql后进行php5.2的编译。

#添加epel源:
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

#安装编译环境和依赖项:
yum groupinstall 'Development Tools'
yum install libmhash-devel  libmhash
yum install libicu-devel  libicu
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
1.png

#安装libiconv
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    #安装到/usr/local/libiconv目录
make && make install
2.png

3.png

#安装libmcrypt
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'

针对64位系统:

ln -s /usr/lib64/libc-client.so  /usr/lib/libc-client.so 
cp -frp /usr/lib64/libldap* /usr/lib/
ln -s /usr/lib64/libpng.so /usr/lib/libpng.so
ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so
yum -y install krb5*
ln -s /usr/lib64 /usr/kerberos/lib
cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so  或者 cp /usr/lib64/mysql/* /usr/lib/mysql/

依赖处理完毕后开始下载和编译php.

wget  http://museum.php.net/php5/php-5.2.17.tar.gz
tar zxvf ./php-5.2.17.tar.gz


./configure \
        –prefix=/usr/local/php5.2 \
        –with-apxs2=/usr/sbin/apxs \
        –with-config-file-path=/usr/local/php5.2/etc \
        –with-mysql=usr/lib64/mysql  \
        –with-mysqli \
        –with-iconv-dir=/usr/local/libiconv \
        –with-config-file-scan-dir=/usr/local/php5.2/php.d \
        –with-mhash=/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-json \
        –enable-mbstring \
        –enable-pcntl \
        –enable-session \
        –enable-shmop \
        –enable-simplexml \
        –enable-soap \
        –enable-sockets \
        –enable-tokenizer \
        –enable-wddx \
        –enable-xml \
        –enable-zip

make -j $Cpunum && make install

完成后会在apache配置文件加上对应的扩展设置。

4.png

为了能处理php文件,在apache配置文件加上 AddType application/x-httpd-php .php 设置。

这里我加到/etc/httpd/conf.d目录下(apache默认加载conf.d下的*.conf文件)

5.png

拷贝php配置文件:

mkdir /usr/local/php5.2/etc

cp php.ini-recommended /usr/local/php5.2/etc/php.ini

6.png

完成后phpinfo测试:

7.png