Linux 安裝 PHP

來源:互聯網
上載者:User

安裝PHP 

兩種方法
 1.下載安裝包安裝
 2.使用yum線上安裝
一 下載安裝包安裝

1、 下載
    http://www.php.net/downloads.php
2、解壓
    tar -zxvf php-5.3.16.tar.gz
3、建立目標檔案夾
    mkdir /usr/local/php
    也就是說等下安裝的php要安裝到這個檔案夾裡面
4、配置
    回到原來解壓後的檔案夾
    ./configure --prefix=/usr/local/php  --with-apxs2=/usr/local/apache/bin/apxs

--prefix=   確定程式的安裝路徑

--with-apxs2=/usr/local/apache/bin/apxs   其中apxs是在安裝Apache時產生的,到自己的apache尋找此檔案
         apxs:是一個為Apache HTTP伺服器編譯和安裝擴充模組的工具,使之可以用由mod_so提供的LoadModule
        指令在運行時載入到Apache伺服器中。我的理解是通過這個工具把PHP模組動態載入到Apache中

這個apxs很重要,是apache 增加擴充模組 需要的。。。


出現錯誤:configure: error: xml2-config not found. Please check your libxml2 installation.

運行yum install libxml2,然後再運行yum install libxml2-devel安裝完畢後,重新運行上面的./configure命令。、


編譯完成時會列出一些設定檔資訊,需要注意

Generating files

configure: creating ./config.status

creating main/internal_functions.c

creating main/internal_functions_cli.c

+--------------------------------------------------------------------+

| 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 sapi/cgi/php-cgi.1

config.status: creating ext/phar/phar.1

config.status: creating ext/phar/phar.phar.1

config.status: creating main/php_config.h

config.status: executing default commands

5、編譯
                 make   
       6、測試編譯
                 make test   
      7、安裝
            make install
      注意以下資訊


Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20121212/

Installing PHP CLI binary:        /usr/local/bin/

Installing PHP CLI man page:      /usr/local/php/man/man1/

Installing PHP CGI binary:        /usr/local/bin/

Installing PHP CGI man page:      /usr/local/php/man/man1/

Installing build environment:     /usr/local/lib/php/build/

Installing header files:          /usr/local/include/php/

Installing helper programs:       /usr/local/bin/

  program: phpize

  program: php-config

Installing man pages:             /usr/local/php/man/man1/

  page: phpize.1

  page: php-config.1

Installing PEAR environment:      /usr/local/lib/php/

[PEAR] Archive_Tar    - installed: 1.3.12

[PEAR] Console_Getopt - installed: 1.3.1

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util       - installed: 1.2.3

[PEAR] PEAR           - installed: 1.9.5

Wrote PEAR system config file at: /usr/local/etc/pear.conf

You may want to add: /usr/local/lib/php to your php.ini include_path

/usr/local/php-5.5.30/build/shtool install -c ext/phar/phar.phar /usr/local/bin

ln -s -f phar.phar /usr/local/bin/phar

Installing PDO headers:          /usr/local/include/php/ext/pdo/



 

8、設定檔

    cp /usr/local/src/php-5.3.16/php.ini-development  /usr/local/php/lib/php.ini
           把原來位於原始碼裡面的php.ini-development拷貝到/usr/local/php/lib/php.ini下,並且重新命名為php.ini
           這裡一定要注意,每個系統php安裝的位置不同,一定先找到自己解壓後的php-5.3.16檔案夾中的php.ini-development   然後選擇好自己php安裝資料夾的路徑

 

9.重啟apache

10、測試
    在apache的htdocs下建立一個php檔案test.php,裡面的內容如下:
    <?php
    phpinfo();
    ?>
    然後在瀏覽器裡輸入http://127.0.0.1/test.php
    如果出現php的相關配置,成功,如果什麼都沒有輸入,說明失敗,重新以上步驟或者尋找原因

如果決定在安裝後改變更配置置選項,只需重複最後的三步configure, make, 以及 make install,然後需要重新啟動 Apache 使新模組生效。Apache不需要重新編譯。

 

如果安裝訪問失敗,比如直接顯示php源碼,或者提示下載php檔案

一些解決辦法:

1.apache沒有添加對應的php類型,所以不支援php的指令碼解析

解決辦法:在設定檔中添加對應類型

找到apache設定檔:知道位置的自己去找,不知道位置的試試使用find命令

在根目錄下執行:#find / -name "httpd.conf"

修改httpd.conf在檔案中添加一行內容:AddType application/x-httpd-php .php

2.沒有加上針對php的索引,如果沒有該索引的支援,則無法解析用php編寫的網頁

解決辦法:在設定檔中添加對應索引

找到設定檔方法同上,找到DirectoryIndex index.html

改為DirectoryIndex index.html index.htm index.php 即可

3.開啟了防火牆

用命令:#getenforce

來查看防火牆的狀態,若是Enforcing,說明是開啟的,請在設定檔中關閉

在/etc/selinu目錄下,修改config中的enforcing為disabled

4.未載入php5_module模組 

解決辦法:添加模組

在設定檔中添加:LoadModule php5_module modules/libphp5.so
       (這個需要在編譯時間 添加 --with-apxs2=/usr/local/apache/bin/apxs






二 使用yum線上安裝
yum install php
yum install php-devel





三  測試 安裝完成後
可以在目錄下建立一個PHP檔案  例如1.php
寫入代碼:
<?php phpinfo(); ?>
然後訪問這個檔案,就能看到PHP的一些資訊,
php.ini設定檔的路徑可以在這個頁面上看到

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.