PHP安装及与apache整合

软件版本

  • apache 2.4.29
  • php 5.4.45

php安装

# tar -zxvf php-5.4.45.tar.gz
# cd php-5.4.45
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml2=/usr/include/libxml2    
# make 
# make install

安装中的错误及解决

如下步骤出现错误

/configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml2=/usr/include/libxml2

错误log:

Sorry, I cannot run apxs.  Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/local/apache2/bin/apxs follows:
./configure: /usr/local/apache2/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory
configure: error: Aborting

按照提示安装perl

# perl -v  //先查看果然没安装
# yum install -y perl
# perl -v  //安装成功
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

再次./configure仍然提示这个错误。于是百度。。。。
才知道需要先按照perl再按照apache才行,不安装perl的情况下安装apache,apxs就无法运行。
补救办法:
查看文件

# cat /usr/local/apache2/bin/apxs

第一行是 #!/replace/with/path/to/perl/interpreter -w
改为:#!/usr/bin/perl -w
再次:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml2=/usr/include/libxml2

成功!

与apache整合

1.httpd.conf修改

如果php安装正确,apache的配置文件会自动被备份(httpd.conf.bak)和修改,修改如下
打开如下注释,加载php模块。
LoadModule php5_module modules/libphp5.so

如果想让apache解析php文件,还需要在httpd.conf中加入(#AddOutputFilter INCLUDES .shtml下面):

AddType application/x-httpd-php .html
AddHandler php5-script .php
  1. 让apache解析PHP代码
    AddHandler php5-script .php
  2. 让apache解析html里的PHP代码
    AddType application/x-httpd-php .html
2.apache/htdos/中加入php文件如:info.php
<?php
phpinfo();
?>
3.重启apache
4.访问 http:ip/info.php 看是否被解析
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值