1、下载php的稳定源代码包。我这里下载的是php-5.2.3。php官网从google一搜就找到了。

2、解压
tar jxvf php-5.2.3.tar.bz2 -C /usr/src/
cd /usr/src/php-5.2.3/

3、配置程序
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2 --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib-dir --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --enable-cgi --disable-cli

4、编译,安装
make
make install

5、php与apache整合
查看<Directory />和<Directory "/usr/local/apache2/htdocs">
    Order deny,allow
    allow from all 检查这里,这里一定是要allow(允许)的,否则会提示权限不够,和不能找到网站根这两个错误。

查看以下这一条是不是已经写进httpd.conf,这是调用php功能块的语句。
LoadModule php5_module        modules/libphp5.so

查找到
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
在“DirectoryIndex index.html”一句后面添加“index.htm index.php”这两句。

查找到
<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>
在“AddType application/x-gzip .gz .tgz”下面添加
“AddType application/x-httpd-php .php”

上面这些都满足了的话,就可以再apache的网站根目录创建一个test测试页。
vim test.php
<?
  phpinfo();
?>

重启httpd服务,/usr/local/apache2/bin/apachectl restart

使用 elinks http://127.0.0.1/test.php
出现php的信息页面,表示php组件安装成功。