【求助】請教前輩在 compile PHP 時的一些觀念



贊助商連結


b90220208
2005-06-20, 09:19 PM
如題,
我簡單列出將 PHP 以 APACHE 的靜態模組來安裝的過程:
----------------------------------------------------------------------
1. cd apache_1.3.x
2. ./configure
3. cd php-4.x.y
4. ./configure --with-mysql --with-apache=../apache_1.3.x
5. make
6. make install
7. d apache_1.3.x
8. ./configure --prefix=/www --activate-module=src/modules/php4/libphp4.a
9. make
(you should now have an httpd binary which you can copy to your Apache bin
dir if it is your first install then you need to "make install" as well)
----------------------------------------------------------------------
第 9 步的描述提到 -- 將所產生的 httpd binary file 複製到 APACHE 安裝位置的
bin 目錄中.
若非首次安裝 APACHE ,可不用執行 make install 了.

:confused:Q1:
請問,為何若非首次安裝 APACHE,就無須作 make install 呢?




關於將 PHP 以 APACHE 的動態共享物件(DSO)安裝的 --with-apxs ,其提到:
----------------------------------------------------------------------
Note: Make sure you specify the installed version of apxs when
using --with-apxs=/path/to/apxs. You must NOT use the apxs version
that is in the apache sources but the one that is actually
installed on your system.
----------------------------------------------------------------------

:confused:Q2:
我不大懂其要我於安裝 PHP 時在作 --with-apxs 前須注意什麼事?




關於 httpd.conf 中的 user 及 group 設定,
PHP 的安裝文件中有一處寫到:
----------------------------------------------------------------------
Note: Apache's default httpd.conf currently ships with a section
that looks like this:

User nobody
Group "#-1"

Unless you change that to "Group nogroup" or something like that
("Group daemon" is also very common) PHP will not be able to open
files.
----------------------------------------------------------------------

:confused:Q3:
其中的 Group "#-1" 是否可換成任意一個群組呢?
這裡的使用者與群組設定為何會與 PHP 有關呢?

贊助商連結


raytracy
2005-06-21, 02:12 PM
:confused:Q1:
請問,為何若非首次安裝 APACHE,就無須作 make install 呢?
make install 時, 還會安裝一些文件(man page), conf 檔案等等, 但是您只不過重新 compile, 這些文件或設定檔並不會因為 compile 而被更動, 所以不需要每一個檔案都重新安裝 (即 make install), 只需要將新的 binary 蓋過去就好了....



----------------------------------------------------------------------
Note: Make sure you specify the installed version of apxs when
using --with-apxs=/path/to/apxs. You must NOT use the apxs version
that is in the apache sources but the one that is actually
installed on your system.
----------------------------------------------------------------------

:confused:Q2:
我不大懂其要我於安裝 PHP 時在作 --with-apxs 前須注意什麼事?
請務必使用「被 install 在您系統中的 apxs 版本」, 而不要去使用附在 apache source 裡面的版本. 這是因為: 附在 source 中的 apxs 可能只是一個範例, 或是作者用來示範的版本, 不是您目前正在使用的版本. 您必須拿系統中真正在執行的版本才行.


:confused:Q3:
其中的 Group "#-1" 是否可換成任意一個群組呢?
這裡的使用者與群組設定為何會與 PHP 有關呢?
它的意思, 只是提醒你要把 #-1 換成一個在系統中真正存在的 group 名稱. 而會使用 nobody 或是 daemon 則是因為這幾個 group 的權限通常都很低, 就算 PHP 程式出了什麼漏洞, 也不至於被入侵者取得太高的權限來破壞系統. PHP 程式執行時, 會使用您指定的 user / group 身份, 在系統裡面存取各項資源. 如果 user / group 選擇不當的話, 就有機會被駭客入侵.

b90220208
2005-06-21, 03:19 PM
Thanks a lot!! :circle:

再請教,
已知以任意身份(權限越低越安全)啟動 APACHE , MySQL 是 OK 的.
..,然 MySQL 還須對資料庫的相關檔案再作 access mode 的變更,舉例如下:

chown -R user_name /path/to/mysql/datadir
-> APACHE 有類似的要求嗎?



-------------
不一定針對 apache,當重新編譯程式時,有沒有可能遇到一種情況是:
不能用 make install 而需 user 做完 make 後,自行比對其所產生之所有files,看看同名之檔案位於 --prefix 所指定的安裝目錄中的何處,然後再依需要一一 copy 到對應之處?



------------
MYSQL 手冊文件指出:
可以藉由編輯 mysql.server 用 su 以用戶: user_name(非root)來啟動 mysqld.

請教若編輯 mysql.server 時,是否要先找出這行:
/usr/local/mysql/bin/safe_mysqld

然後在此行前先執行su root
再將此行改為: /usr/local/mysql/bin/safe_mysqld --user=新作的專用帳戶(權限極低)
然後再執行su 新作的專用帳戶

.....如此較符合安全原則?