CentOS 5.5下LAMP环境搭建之源码安装PHP(php-5.4.8)

CentOS 5.5下LAMP环境搭建之源码安装PHP(php-5.4.8)

 

    由于安装CentOS 5.5的设置可能不一样,所以有些软件在系统安装时就顺便安装了。下面的步骤仅供参考。

 

1、软件准备

php-5.4.8.tar.gz (http://php.net/downloads.php)

 

2、编译工具准备

    安装gccgcc-c++

[root@localhost ~]# yum install gcc gcc-c++

 

3、查询和删除系统安装的php

[root@localhost ~]# rpm -q php
package php is not installed

 

4、安装依赖的库

[root@localhost ~]# yum install libxml2-devel

 

5、编译安装PHPphp-5.4.8

(1)编译安装PHP

[root@localhost src]# tar -zxf php-5.4.8.tar.gz 
[root@localhost src]# cd php-5.4.8
[root@localhost php-5.4.8]# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
checking for grep that handles long lines and -e... /bin/grep
……
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating main/php_config.h
config.status: executing default commands
[root@localhost php-5.4.8]# make
……
[root@localhost php-5.4.8]# make install
……

 

(2)安装后的配置

[root@localhost php-5.4.8]# cp php.ini-development /usr/local/lib/php.ini
[root@localhost php-5.4.8]# cat /usr/local/apache2/conf/httpd.conf | grep php5
LoadModule php5_module        modules/libphp5.so
[root@localhost php-5.4.8]# ln -s /usr/local/apache2/bin/apachectl /etc/init.d/httpd

    在/usr/local/apache2/conf/httpd.conf的最后添加下面的内容,如下

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>

<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>

 

6、测试

    创建一个测试PHP脚本,如下

[root@localhost php-5.4.8]# cd /usr/local/apache2/htdocs/
[root@localhost htdocs]# vi index.php
[root@localhost htdocs]# ls
index.html  index.php
[root@localhost htdocs]# cat index.php 
<?php
phpinfo();
?>

 

    开启httpd服务,如下

[root@localhost htdocs]# service httpd start

 

    浏览器中打开http://localhost/index.php,如下

CentOS 5.5下LAMP环境搭建之源码安装PHP(php-5.4.8)_第1张图片

参考资料:

1http://www.php.net/manual/en/install.unix.apache2.php

2http://geek.michaelgrace.org/2011/08/configure-error-xml2-config-not-found-please-check-your-libxml2-installation/

你可能感兴趣的:(CentOS 5.5下LAMP环境搭建之源码安装PHP(php-5.4.8))