Redhat Server 5.7 安裝配置PHP


PHP的簡介

       PHP於1994年由Rasmus Lerdorf創建,剛剛開始是Rasmus Lerdorf 為了要維護個人網頁而制作的一個簡單的用Perl語言編寫的程序。這些工具程序用來顯示 Rasmus Lerdorf 的個人履歷,以及統計網頁流量。后來又用C語言重新編寫,包括可以訪問數據庫。他將這些程序和一些表單直譯器整合起來,稱為 PHP/FI。PHP/FI 可以和數據庫連接,產生簡單的動態網頁程序.......[參考百科]

       PHP的官方網址:http://www.php.net/

PHP安裝配置

     首先去官網http://cn2.php.net/downloads.php下載最新版的安裝包或你需要的版本,本次實驗的系統環境為Red Hat Enterprise Linux Server release 5.7 64bit。這篇文章是安裝配置nagios的過程

Code Snippet
  1. [root@getlnx05 kerry]# tar zxvf php-5.4.10.tar.gz
  2.  
  3. [root@getlnx05 kerry]# cdphp-5.4.10
  4.  
  5. [root@getlnx05 php-5.4.10]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs

 

 clip_image002

報錯詳細信息:

General settings

checking whether to include gcov symbols... no

checking whether to include debugging symbols... no

checking layout of installed files... PHP

checking path to configuration file... DEFAULT

checking where to scan for configuration files...

checking whether to enable PHP's own SIGCHLD handler... no

checking whether to explicitly link against libgcc... no

checking whether to enable short tags by default... yes

checking whether to enable dmalloc... no

checking whether to enable IPv6 support... yes

checking whether to enable DTrace support... no

checking how big to make fd sets... using system default

Configuring extensions

checking size of long... (cached) 8

checking size of int... (cached) 4

checking for int32_t... yes

checking for uint32_t... yes

checking for sys/types.h... (cached) yes

checking for inttypes.h... (cached) yes

checking for stdint.h... (cached) yes

checking for string.h... (cached) yes

checking for stdlib.h... (cached) yes

checking for strtoll... yes

checking for atoll... yes

checking for strftime... (cached) yes

checking which regex library to use... php

checking whether to enable LIBXML support... yes

checking libxml2 install dir... no

checking for xml2-config path...

configure: error: xml2-config not found. Please check your libxml2 installation.
View Code

 

報錯“configure: error: xml2-config not found. Please check your libxml2 installation.”是因為缺少libxml2相關的包libxml2-devel, 如下所示,先檢查已經安裝了那些libxml2相關的包

 

 

Code Snippet
  1. [root@getlnx05 php-5.4.10]#  rpm -qa |greplibxml2
  2.  
  3. libxml2-python-2.6.26-2.1.12
  4.  
  5. libxml2-2.6.26-2.1.12
  6.  
  7. libxml2-2.6.26-2.1.12

clip_image004

[root@getlnx05 php-5.4.10]# rpm -qa libxml2-devel

[root@getlnx05 php-5.4.10]# yum install libxml2-devel

clip_image006

[root@getlnx05 php-5.4.10]#  ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs

clip_image008

[root@getlnx05 php-5.4.10]#make

clip_image010

[root@getlnx05 php-5.4.10]#make install

clip_image012

接下來配置Apache服務,關於Apache的安裝,可以參考我的博客Linux系統安裝Appach 2.4.6

PHP環境配置

Step 1: Apache環境配置

首先找到Apache的配置文件配置文件/usr/local/apache/conf/httpd.conf (我Apache服務安裝目錄為/usr/local/apache)

找到

#User daemon

#Group daemon

修改為

User nagios

Group nagios

另外找到ServerName www.example.com:80 ,在下面增加ServerName添加服務器的IP地址

clip_image014

另外找到下面配置,增加index.php

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

clip_image016

接下來找到<IfModule mime_module>,在后面增加配置信息AddType application/x-httpd-php .php,如下所示

clip_image018

出於安全考慮,一般訪問nagios的安全監控界面必須經過授權才能訪問(不要那么,安裝配置PHP是安裝配置nagios的過程,如果大家只是為了安裝配置PHP環境,完全可以跳過下面),這需要增加驗證配置,即在httpd.conf 文件最后添加如下信息:

clip_image020

Step 2:創建apache目錄驗證文件

[root@getlnx05 conf]#  /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd kerry

clip_image022

這樣就在/usr/local/nagios/etc 目錄下創建了一個htpasswd 驗證文件,當通過http://192.168.xx.xxx/nagios/ 訪問時就需要輸入用戶名和密碼了。當然驗證文件的密碼是加密過的,如下所示:

[root@getlnx05 conf]# cat /usr/local/nagios/etc/htpasswd

kerry:$apr1$H1bHFvhH$q.bsSARuh4Ns2Z5G9hmQN.

[root@getlnx05 conf]#

 

image

Step 3:重啟Apache服務

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl restart

AH00526: Syntax error on line 515 of /usr/local/apache/conf/httpd.conf:

AuthUserFile takes one argument, text file containing user IDs and passwords

[root@getlnx05 conf]#

用vi打開/usr/local/apache/conf/httpd.conf文件,定位到515行(下面紅色的哪一行),后面的哪一行漢字注釋變成導致,如下圖所示:

Code Snippet
  1. #setting for nagios
  2.  
  3. ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
  4.  
  5. <Directory "/usr/local/nagios/sbin">
  6.  
  7. AuthType Basic
  8.  
  9. Options ExecCGI
  10.  
  11. AllowOverride None
  12.  
  13. Order allow,deny
  14.  
  15. Allow from all
  16.  
  17. AuthName "Nagios Access"
  18.  
  19. AuthUserFile /usr/local/nagios/etc/htpasswd //用於此目錄訪問身份驗證的文件
  20.  
  21. Require valid-user
  22.  
  23. </Directory>
  24.  
  25. Alias /nagios "/usr/local/nagios/share"
  26.  
  27. <Directory "/usr/local/nagios/share">
  28.  
  29. AuthType Basic
  30.  
  31. Options None
  32.  
  33. AllowOverride None
  34.  
  35. Order allow,deny
  36.  
  37. Allow from all
  38.  
  39. AuthName "nagios Access"
  40.  
  41. AuthUserFile /usr/local/nagios/etc/htpasswd
  42.  
  43. Require valid-user
  44.  
  45. </Directory>

clip_image024

將這一行注釋清除后,重啟Apache服務,OK,問題解決,打開http://192.168.7.223/nagios/進入網站,點擊其它頁面發現亂碼,這是因為Apache沒有開啟cgi腳本的緣故。進入apache的主配置文件httpd.conf將#LoadModule cgid_module modules/mod_cgid.so前的注釋符號去掉,重啟Apache服務即可解決問題

clip_image026

 

 

 

參考資料:

http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM