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 php

錯誤log:html

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

按照提示安裝perllinux

# 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就沒法運行。
補救辦法:
查看文件apache

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

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

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

成功!ui

與apache整合

1.httpd.conf修改

若是php安裝正確,apache的配置文件會自動被備份(httpd.conf.bak)和修改,修改以下
打開以下注釋,加載php模塊。
LoadModule php5_module modules/libphp5.sothis

若是想讓apache解析php文件,還須要在httpd.conf中加入(#AddOutputFilter INCLUDES .shtml下面):code

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 看是否被解析

相關文章
相關標籤/搜索