close

 

話說昨天裝完了pear之後…接下來就是要準備使用啦

不過在這之前…先來裝裝看「pear圖形管理介面」是怎樣子好了

大爺實在不太喜歡下指令…總覺得終端機介面醜醜的…一點美感也沒有

所以還是比較偏好使用圖形介面…至少也人性化多了…

 

好啦…接下來書上的步驟1是要先安裝幾個套件:Net_userAgent_Detect、Pager、HTML_Template_IT、Pear_FrontEnd_Web,那就譹我們一個、一個來安裝唄。

# pear install Net_UserAgent_Detect
downloading Net_UserAgent_Detect-2.5.2.tgz ...
Starting to download Net_UserAgent_Detect-2.5.2.tgz (11,986 bytes)
.....done: 11,986 bytes
install ok: channel://pear.php.net/Net_UserAgent_Detect-2.5.2

 

# pear install Pager
downloading Pager-2.4.8.tgz ...
Starting to download Pager-2.4.8.tgz (36,122 bytes)
..........done: 36,122 bytes
install ok: channel://pear.php.net/Pager-2.4.8
You have new mail in /var/mail/root

#pear install HTML_Template_IT
pear/HTML_Template_IT is already installed and is the same as the released version 1.3.0
install failed


(這個大已經有裝了呀 ^^")

 

# pear install Pear_FrontEnd_Web
pear/Pear_FrontEnd_Web is already installed and is the same as the released version 0.7.4
install failed

(這個也已經有了 ^^")

 

再來步驟2書上是指要複製 WebInstaller.php 這個檔到網頁的根目錄下,不過WebInstaller.php大爺怎麼找都找不到這東東,後來才發現WebInstaller.php應該是改成pearfrontendweb.php這個檔了,那就把這個檔複製到網頁的根目錄底下試試看囉。

結果是…出錯了!!…出現了兩個錯誤

Warning: Can not find config file, please specify the $pear_user_config variable in /pearfrontendweb.php

Error: the template directory (/usr/share/php/data/PEAR_Frontend_Web/data/templates) is not a directory, or not readable. Make sure the 'data_dir' of your config file (/usr/share/php/data) points to the correct location !

 

很好,這錯誤大爺也搞不太懂是怎麼回事,應該是大爺有更改安裝的預設目錄的關係吧@@

不過大爺上網查了查,發現跟這有關的相關資料非常少,也稍微看了程式碼,看來解決這個錯誤需要要花不少的時間 @@。

 

呼…不過大爺也不是吃素的…經過大爺不死心個性的追查之下,終於找出原因了,下面是大爺使用的方式,和書上有些不同,客倌可以參考看看 ^^。

步驟1是將pear安裝路徑下的PEAR/docs/PEAR_Frontend_Web/docs/example.php複製到你的網頁根目錄下,並且改名成你喜歡的檔案名稱。

如果執行這個檔案,畫面會出現 Error: Configuration file "/var/www/bailing/lib/pear/PEAR" is empty 這個錯誤訊息。

再來我們就要修改這個檔案,請用文字編輯器,或是你喜歡的編輯器來開啟這個檔。

修改這一行,將前面的註解拿掉(//)並加上pear安裝的路徑

//$pear_user_config = '';

改成這樣->$pear_user_config = '/var/www/bailing/lib/pear/PEAR';

再重新更新畫面,會出現下面的錯誤,不過別擔心,大爺會想辨法解決這個錯誤的 ^^":

Error: the template directory (/usr/share/php/data/PEAR_Frontend_Web/data/templates) is not a directory, or not readable. Make sure the 'data_dir' of your config file (/usr/share/php/data) points to the correct location !

這個錯誤是說找不到PEAR_Frontend_Web這資料夾內的暫存檔,因為大爺是安裝時有更改過位置,所以這時就要修改 /etc/pear/pear.conf 這個檔案,一樣用文字編輯器,或是你喜歡的編輯器來開啟這個檔。

這個檔會長的像這樣:

pear.conf

找出下面這一行:

s:8:"data_dir";s:19:"/usr/share/php/data";

改成你預設安裝的pear目錄位置-> s:8:"data_dir";s:19:"/etc/pear/PEAR/data";

再執行就可以了!! ^^

下面是執行的畫面

pearWebManagement

這邊是可以更改一些pear.conf的圖形介面,跟剛才我們改pear.conf這個檔是一樣的,只是方便多了呢 ^^,在這邊可以再檢查一下,看看還有沒有那裡有設錯的,只是要記得先更改pear.conf這個檔案的權限哦,不然預設是沒辨寫入的。

 pearWebManagementConfiguration

 

順帶一題,如果你的網頁沒有設定安全機制(像是.htaccess的話,會出現警告訊息在最上方)

這邊大爺也記錄一下要怎麼設定.htaccess好了

驗證的方式像是這個樣子:

require

 

步驟1:開啟apache的htaccess設定
(以下的參考來源是:http://tern.pixnet.net/blog/post/15428569)


設定apache可以載入 .htaccess 的目錄,預設是沒有滴:
在 /etc/apache2/apache2.conf 的最後面新增以下的內容...

(這邊是適用於ubuntu哦,其它的Linux版本請上網找找)

<Directory /var/www/> ←(這裡是設定讓 .htaccess 可以載入的目錄)
AllowOverride All ←(這個是關鍵的地方...)
Order allow,deny
allow from all
</Directory>

 

步驟2:修改/etc/apache/site-available/default這個檔案

(以下是參考:http://www.wretch.cc/blog/nidgetgod/6596428)

這其實很有趣大概是安全性考量才會這樣配置吧

在 /etc/apache2/apache2.conf 裡可以看到這麼一段 AccessFileName .htaccess 可以確定它會讀 .htaccess

但是在 /etc/apache/site-available/default 裡卻將 AllowOverride 設為 None 也就是不讀入額外的配置

而要解決的問題其實也就只是將 None 改為 All 並重啟 apache 就可以了。

 

步驟3:

(以下是參考:http://turtle.ee.ncku.edu.tw/~tung/webprot/htaccess.html

  1. 首先建立一個要用密碼來保護的目錄 (如 大爺這邊的/var/www/)
  2. 在這個目錄下建立一個 .htaccess 的檔案, 內容如下

  3. AuthUserFile /var/www/  .passwd
    AuthGroupFile /dev/null
    AuthName  "access"
    AuthType Basic

    <files pearWeb.php>
    Require user yourusername
    </files>

    上面這個檔案會把整個 /var/www 目錄 (含所有子目錄), 都用紅色部份所標明的 .passwd檔案 保護起來, 任何想要瀏覽 /var/www 目錄內網頁的人, 都必須輸入正確的使用者名稱與密碼才行,大爺這邊只想要鎖單一個檔案,所以在裡面加上

    <files pearWeb.php>
    Require user yourusername
    </files>

    (加了這一段,就只有鎖住pearWeb.php這個檔,其它的不會被鎖哦 ^^。)


步驟4:建立 .passwd 這個密碼檔

這個密碼檔的名稱要和最後面那個紅色的名稱相同哦: AuthUserFile /var/www/  .passwd
然後輸入下面的指令:


# cd /var/www
# htpasswd -c .passwd  username1

輸入一組密碼,上面這個命令會建立 .passwd 這個檔, 並放入使用者 username1 與其密碼,如果你希望多放幾個使用者到密碼檔裡, 那麼可以繼續:

    htpasswd .passwd username2
    並輸入 username2 的密碼

要注意只有在第一次時才要用 -c 這個參數, 它代表重新建立一個密碼檔, 如果在密碼檔已存在的情形下使用 -c 這個參數, 密碼檔舊有記錄會被清除

    .passwd 檔案是一個普通的文字檔, 你可以用一般的文書編輯器去處理它, 刪除不要的使用者名稱與密碼

     

最後將要被保護的網頁放到 .htaccess 所在的子目錄中,然後再重新載入網頁,應該就會出現輸入帳號、密碼的對話框了 ^^

arrow
arrow
    全站熱搜

    大爺 發表在 痞客邦 留言(0) 人氣()