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,如下



参考资料:

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/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值