PHP的安裝以及與apache整合的介紹

來源:互聯網
上載者:User
這篇文章主要介紹了關於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 installed2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs3. 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 directoryconfigure: error: Aborting

按照提示安裝perl

# perl -v  //先查看果然沒安裝# yum install -y perl# perl -v  //安裝成功This is perl, v5.10.1 (*) built for x86_64-linux-thread-multiCopyright 1987-2009, Larry WallPerl may be copied only under the terms of either the Artistic License or theGNU General Public License, which may be found in the Perl 5 source kit.Complete documentation for Perl, including FAQ lists, should be found onthis system using "man perl" or "perldoc perl".  If you have access to theInternet, 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 .htmlAddHandler 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

<?phpphpinfo();?>

3.重啟apache

4.訪問 http:ip/info.php 看是否被解析

以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.