帮助中心 >
编译安装php

[root@ebadu tmp]# wget http://museum.php.net/php5/php-5.2.6.tar.gz
[root@ebadu tmp]# tar -zxvf php-5.2.6.tar.gz
[root@ebadu tmp]# cd php-5.2.6

##先下载所需组件

 

  • cd /tmp
  • wget http://superb-dca2.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
  • wget http://superb-dca2.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
  • wget http://superb-sea2.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
  • tar xzf libmcrypt-2.5.8.tar.gz
  • tar xzf mhash-0.9.9.9.tar.gz
  • tar xzf mcrypt-2.6.8.tar.gz
  • //安装libmcrypt
  • cd /tmp/libmcrypt-2.5.8
  • ./configure --prefix=/usr
  • make && make install
  • //安装libmcrypt
  • cd /tmp/mhash-0.9.9.9
  • ./configure --prefix=/usr
  • make && make install
  • //安装mcrypt
  • /sbin/ldconfig //搜索出可共享的动态链接库
  • cd /tmp/mcrypt-2.6.8
  • ./configure
  • make && make install


##解决可能出现的libiconv错误。
 

  • cd /tmp
  • wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
  • tar xzf libiconv-1.14.tar.gz
  • cd libiconv-1.14
  • ./configure --prefix=/usr/local/libiconv
  • make && make install

##开始安装php


 

开始安装php-5.2.17:
 

  • cd /tmp/php-5.2.17
  • ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --enable-bcmath --with-bz2 --with-curl --enable-ftp --with-gd --enable-gd-native-ttf --with-gettext --with-mhash --enable-mbstring --with-mcrypt --enable-soap --enable-zip --with-iconv=/usr/local/libiconv --with-mysql=/usr/local/mysql --without-pear
  • make
  • make install

 

编译参数解释:
–prefix=/usr/local/php:设置安装路径
–with-apxs2=/usr/local/apache/bin/apxs:编译共享的 Apache 2.0 模块
–with-config-file-path=/etc:指定配置文件php.ini地址
–with-config-file-scan-dir=/etc/php.d:指定额外的ini文件目录
–with-openssl:编译OpenSSL支持
–with-zlib:编译zlib支持
–enable-bcmath:启用BC风格精度数学函数
–with-bz2:BZip2支持
–with-curl:CRUL支持
–enable-ftp:FTP支持
–with-gd:GD支持
–enable-gd-native-ttf:启用TrueType字符串函数
–with-gettext:启用GNU gettext支持
–with-mhash:mhash支持
–enable-mbstring:启用支持多字节字符串
–with-mcrypt:编译mcrypt加密支持
–enable-soap:SOAP支持
–enable-zip:启用zip 读/写支持
–with-iconv=/usr/local/libiconv:iconv支持
–with-mysql=/usr/local/mysql:启用mysql支持
–without-pear:不安装PEAR
更多编译参数解释参考http://www.php.net/manual/zh/configure.about.php或者./configure –help查看。

cp php.ini-dist /usr/local/php/etc/php.ini   //复制配置文件php.ini

在/etc/httpd/conf/httpd.conf文件中加入php文件类型解析:
Addtype application/x-httpd-php .php

重启httpd:
 

  • service httpd restart

添加测试页面:
[root@localhost /]# vi /usr/local/apache/htdocs/index.php

[root@localhost /]# vi /usr/local/apache/htdocs/index.php
<?php
phpinfo();
?>
~