歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> Unix 系統下的安裝--php

Unix 系統下的安裝--php

日期:2017/2/28 11:16:13   编辑:關於Unix


本節將指導如何在 Unix 系統下安裝和配置 PHP。在開始安裝之前,請務必研究自己使用的系統和 web 服務器的相關章節。
在安裝前需要考慮的事項一節提到,在本節主要以 web 為中心介紹 PHP 的設置。不過本節也會覆蓋一些 PHP 命令行用法的設置方法。
在 Unix 平台下安裝 PHP 有幾種方法:使用配置和編譯過程,或是使用各種預編譯的包。本文主要針對配置和編譯 PHP 的過程。很多 Unix 類系統都有包安裝系統,可以用它來設置一個有著標准配置的 PHP。但是若需要與標准配置不同的功能(例如一個安全服務器,或者不同的數據庫驅動擴展模塊),可能需要編譯 PHP 和/或 web 服務器。如果不熟悉編譯軟件,可以考慮搜索一下是否有人已經編譯了包含所需要功能的預編譯包。
編譯所需的知識和軟件:
基礎的 Unix 技能(有能力操作“make”和一種 C 語言編譯器)
一個 ANSI C 語言編譯器
flex:版本 2.5.4
bison:版本 1.28(推薦)、1.35 或 1.75
一個 web 服務器
模塊特別需要的組件(例如 gd、pdf 庫等)
PHP 初始的配置和安裝過程被 configure 腳本中一系列命令行選項控制。可以通過 ./configure --help 命令了解 PHP 所有可用的編譯選項及簡短解釋。本手冊是分開對這些選項編寫文檔的。可在附錄中找到核心配置選項,而擴展模塊特定的配置選項分別在其函數參考頁面中描述。
配置好 PHP 後,便可以開始編譯模塊和/或可執行文件。make 命令用來做這一工作。如果該命令執行失敗而找不到原因,請參考安裝問題一節。
Unix 系統下的 Apache 1.3.x
本節包括在 Unix 平台的 Apache 下安裝 PHP 的說明和提示。我們在另外的頁面也有 Apache 2 的安裝和說明。
可以從核心配置選項列表以及位於手冊對應部分的特定擴展配置選項中選擇參數並在安裝步驟第 10 步將它們添加到 configure 命令中。版本號在這裡被省略了以保證此說明的正確性。需要將這裡的“xxx”替換為自己使用的文件的正確值。
例 4.1. PHP 的 Apache 共享模塊版本安裝說明
1. gunzip apache_xxx.tar.gz
2. tar -xvf apache_xxx.tar
3. gunzip php-xxx.tar.gz
4. tar -xvf php-xxx.tar
5. cd apache_xxx
6. ./configure --prefix=/www --enable-module=so
7. make
8. make install
9. cd ../php-xxx
10. 現在,配置 PHP。這是定制 PHP 的不同選項的時候,例如要加載哪些擴展庫。使用
./configure --help
來列出可用的選項。在下面的示例中只是簡單地配置 Apache 1 和 MySQL 支持。
用戶的 apxs 的路徑可能和此示例中的不同。
./configure --with-mysql --with-apxs=/www/bin/apxs
11. make
12. make install
如果在安裝之後決定修改配置選項,那麼只需重復以上最後三步。只須重新啟動
Apache 就可以使新模塊生效。不需要重新編譯 Apache。注意除非特別指出,
“make install”總是會安裝 PEAR,各種 PHP 工具例如 phpize,PHP CLI 以及其它。
13. 建立 php.ini 文件。
cp php.ini-dist /usr/local/lib/php.ini
可以編輯 php.ini 來設置 PHP 選項。如果想把 php.ini 放在其它目錄,在第
10 步加上以下選項:
--with-config-file-path=/path
如果選擇了 php.ini-recommended,確保閱讀一下其中的變更說明,因為這些會
影響到 PHP 的行為。
PHP 模塊所在的路徑。上面的 make install 步驟可能已經添加了,但還是檢查確認一下。
對 PHP 4:
對 PHP 5:
對 PHP 4:
AddModule mod_php4.c
對 PHP 5:
AddModule mod_php5.c
16. 告訴 Apache 將哪些後綴作為 PHP 解析。例如,讓 Apache 把 .php 後綴的文件解析為
PHP。可以將任何後綴的文件解析為 PHP,只要在以下語句中加入並用空格分開。這裡以
添加一個 .phtml 來示例。
AddType application/x-httpd-php .php .phtml
為了將 .phps 作為 PHP 的源文件進行語法高亮顯示,還可以加上:
AddType application/x-httpd-php-source .phps
17. 用通常的過程啟動 Apache(必須完全停止 Apache 再重新啟動,而不是用 HUP 或者
USR1 信號使 Apache 重新加載)。

也可以將 PHP 作為靜態對象來安裝:
例 4.2. PHP 的 Apache 靜態模塊版本安裝說明
1. gunzip -c apache_1.3.x.tar.gz | tar xf -
2. cd apache_1.3.x
3. ./configure
4. cd ..
5. gunzip -c php-5.x.y.tar.gz | tar xf -
6. cd php-5.x.y
7. ./configure --with-mysql --with-apache=../apache_1.3.x
8. make
9. make install
10. cd ../apache_1.3.x
11. ./configure --prefix=/www --activate-module=src/modules/php5/libphp5.a
(上面一行是正確的!是的,我們知道 libphp5.a 尚不存在,還不到時候,
它會在之後被創建。)
12. make
(現在應該有一個 httpd 二進制文件,可以將它復制到 Apache bin 目錄。如果這是
第一次安裝,還要“make install”。)
13. cd ../php-5.x.y
14. cp php.ini-dist /usr/local/lib/php.ini
AddType application/x-httpd-php .php

注意: 對於 PHP 4,把 php-5 換成 php-4,把 php5 換成 php4。
根據 Unix 系統和 Apache 安裝方法的不同,有很多方法停止和重啟動 Apache。以下是一些不同的 Apache/UNIX 下重啟動 Apache 的典型命令。需要把 /path/to/ 替換成自己系統上的確切路徑。
例 4.3. 重啟動 Apache 的示例命令
1. 在一些 Linux 和 SysV 的變種下:
/etc/rc.d/init.d/httpd restart
2. 使用 apachectl 腳本:
/path/to/apachectl stop
/path/to/apachectl start
3. httpdctl 和 httpsdctl(使用了 OpenSSL),類似 apachectl:
/path/to/httpsdctl stop
/path/to/httpsdctl start
4. 使用了 mod_ssl,或其他 SSL 服務器,可能需要手工重啟動:
/path/to/apachectl stop
/path/to/apachectl startssl

apachectl 和 http(s)dctl 程序所在的路徑在不同系統中通常不一樣。如果系統中有 locate 或者 whereis 或者 which 命令,那麼可以幫助找到這些控制程序。
編譯 PHP 和 Apache 的不同例子還有:
./configure --with-apxs --with-pgsql

./configure --with-apxs --with-pgsql=shared

./configure --with-apache=/path/to/apache_source --with-pgsql

此配置將生成 libmodphp5.a 庫,mod_php5.c 和一些相關的文件並且拷貝到 Apache 源程序目錄中的 src/modules/php5 目錄下。然後用 --activate-module=src/modules/php5/libphp5.a 編譯 Apache,Apache 編譯系統會生成 libphp5.a 並且將其靜態地連接到 httpd 程序中(在 PHP 4 中把 php5 替換成 php4)。PostgreSQL 支持也直接包括在這個 httpd 程序中了,因此最終結果是單一的一個包括了所有 Apache 和 PHP 支持的 httpd 可執行文件。
./configure --with-apache=/path/to/apache_source --with-pgsql=shared

當選擇不同的方法編譯 PHP 時,需要考慮每種方法的優勢和缺點。用共享對象方式編譯 PHP 意味著可以單獨編譯 Apache,並且不用在添加或修改了 PHP 的時候重新編譯所有程序。用內置方法編譯 PHP(靜態方式)意味著 PHP 可以加載和運行得更快。更多信息見 Apache 的 » DSO 支持頁面。
User nobody
Group "#-1"
除非把它修改成“Group nogroup”或者其它類似的(“Group daemon”也很通用),PHP 將不能打開文件。
注意: 確認在使用 --with-apxs=/path/to/apxs 時指向 Apache 安裝後的目錄中的 apxs。絕對不能用 Apache 源程序中的 apxs 而要用安裝後的 apxs。
Unix 系統下的 Apache 2.0 安裝前需要考慮的事項
--------------------------------------------------------------------------------
Last updated: Thu, 19 Apr 2007

add a note User Contributed Notes
Unix 系統下的安裝
moonlightcheese
23-Aug-2007 05:49
There is little or no documentation regarding the fact that MySQL Client Library isn't bundled with PHP anymore. The installation instructions need to be changed with, at the very least, some instructions for how to get PHP to recognize that the client library is installed. I realize that this may be a problem with licensing and as such, it's not possible to document too much regarding MySQL...
alecjw at gmail dot com
17-Aug-2007 08:09
mrstarr at nyx dot net:
This is the normal procedure, which is:
./configure
make
make install
Edit the appropriate config files.
please at nospam dot com
12-Jul-2007 01:09
I thought I should point out that when you run make it says "Build complete. Don't forget to run make test."
But the instructions on this page don't mention make test.
mrstarr at nyx dot net
10-Jun-2007 03:57
Are you serious. This install process is insane. Nobody's going to go through this complex install process just to upgrade this stuff. Its complicated enough as it is just configuring Linux to work, but having to go through this stuff over and over whenever you need to install or upgrade some dependency or component... is getting absurd.
You need a far simpler install process, preferably one that is a standard, i.e. ./configure , make, make install
davidc at php dot net
20-Mar-2007 07:35
One might want to use .phar then he'll have to compile using phar
--enable-phar --with-zlib --with-bzip2
Alex at GrimMusic dot com
13-Nov-2006 12:49
In response to the guy who posted about the SELinux:
I am new to linux/apache/php (coming from server 2003/IIS/Asp.Net), so i was stumped as to why php/apache could only use static content. Also, it couldn't access some documents that you created somewhere else, and then dragged into the HTML directory.
After some research, i found the problem was the SELinux context of the files. It took me forever to find the Proper command to use to change that, as all the examples on the net were out dated using old commands:
# chcon "user_u:object_r:httpd_sys_content_t" /var/www/html -Rc
This will change the SELinux context of all the documents under the /var/www/html directory (which is the web directory under Fedora), to allow the httpd process to access them, and the '-Rc' flag will make the changes Recursive, and will output it's progress for each file that it sucessfully changes.
squeegee
30-Sep-2006 09:24
regarding the note by phptard at gmail dot com:
This was a good starting point to get php built against the Intel-compiled mysql, but in my case, there were still errors. It wasn't until I also added LIBS="-lirc" to the beginning of the configure line that it would configure without errors. It also compiled fine after that. So the start of my configure line looked like this:
LDFLAGS="-lirc" LIBS="-lirc" EXTRA_LIBS="-lirc" ./configure
Arjan van Bentem
12-Jul-2006 12:29
When using Red Hat Fedora, beware of Security Enhanced Linux, SELinux.
Quoted from Red Hat: "The security goal is to make sure that Apache HTTP is only reading the static Web content, and not doing anything else such as writing to the content, connecting to database sockets, reading user home directories, etc."
These limitations include, among many other things, using mkdir to create directories, using fopen to access files, using fopen or get_headers to read URLs, or using exec to run external applications that happen to use sockets (or maybe access some files, but which will run fine when executed from the command line as Unix user apache or httpd -- such as HylaFAX "faxstat" as invoked from nweb2fax recvq.php and sendq.php).
See /var/log/messages for any denials due to the SELinux policy. To disable it:
- System, Administration, Security Level and Firewall
- open the SELinux tab
- click the Transition tree
- check Disable SELinux protection for Apache HTTP
- execute /etc/init.d/httpd restart
flconseil at yahoo dot fr
07-Mar-2006 06:15
Building Apache 2 and PHP 5.1.2 :
dpresley4 at yahoo dot com
06-Nov-2005 03:42
Hi,
PROBLEM: ./configure PHP --with-oci8
fails with unresolved references such as __rpc_thread_destroy@GLIBC_2_2_3_...
ONE SOLUTOIN
FOR SOLVING PHP ./configure RESULTING IN __rcp_thread_destroy@GLIBC_2_2_3_... AND
UNRESOLVED REFERENCES WITH ORACLE OCI8
KEYWORDS: PHP OCI OCI8 NET8 ./configure __rpc_thred_destroy UNRESOLVED REFERENCES
For building php-4.4.1 or later with oci8, make sure your LD_LIBARRY_PATH has at a minimum the following directories in its path for Oracle8i 8.1.5 or later, Oracle9i 9.0.2 or later, and Oracle9i Release 2: 9.2.0.4 or later, do the following:
Note: We are not using the Oracle Instant Client here. This assumes you have an actual Oracle Installation.
1. Set ORACLE_HOME
Example using Oracle 9i Relase 2 -- 9.2.0.5:
ORACLE_HOME=/opt/app/oracle/product/9iR2
2. Set LD_LIBRARY_PATH with:
LD_LIBRARY_PATH=$ORACLE_HOME/lib: \
$ORACLE_HOME/rdbms/lib:\
$LD_LIBRARY_PATH
3. On Unix / Linux, don't forget to export these environment variables:
export ORACLE_HOME LD_LIBRARY_PATH
4. Now, build PHP with the following:
./configure --with-apxs2= --with-oci8=$ORACLE_HOME --enable-sigchild
Also note that if your using Oracle 9iAS Release 2 v9.0.2, Oracle 10g iAS Release 1 v9.0.4.1, the above steps will work because ORACLE_HOME will containe all of the libraries necessary. Simply point ORACLE_HOME to the top level directory of these installations and set LD_LIBRARY_PATH as described above.
Hope this helps.
phptard at gmail dot com
23-Mar-2005 04:17
after a long night of wrestling with mysql4.0 under linux compiled with the intel compiler, i've gotten php5.0.3 to compile with mysql libraries for this flavor of mysql:
1: download the mysql for linux/intel compiler and install
2: download the rpm for the intel compiler libraries and install
3: configure php with LDFLAGS="-lirc -lgcc_s" and EXTRA_LIBS="-lirc -lgcc_s"
Example:
LDFLAGS="-lirc -lgcc_s" LD_LIBRARY_PATH="-L/usr/lib64" LD_PATH="-L/usr/lib64" LDPATH="-L/usr/lib64" EXTRA_LIBS="-lirc -lgcc_s" ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-ssl=/usr/local/ssl --without-sqlite --with-zlib-dir=/usr --with-mysql=/usr/local/mysql
of course this is on a xeon system that has half of its modules in the /usr/lib64 directory, so on a normal system, without the other kruft, it would look something more like this:
LDFLAGS="-lirc -lgcc_s" EXTRA_LIBS="-lirc -lgcc_s" ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql
Hopefully this will save someone the 6 hour headache it caused me..
diemuzi at gmail dot com
13-Jan-2005 10:11
In reference to van [at] webfreshener [dot] com to fix the krb5 problems. An easier fix is to do the following:
ln -s /usr/kerberos/include/krb5.h /usr/include/krb5.h
ln -s /usr/kerberos/include/profile.h /usr/include/profile.h
ln -s /usr/kerberos/include/com_err.h /usr/include/com_err.h
This will help solve some deps. in the future incase a situation with another compilation occurs.
alexander justadot henry at acm dot org
22-Dec-2004 12:48
The system at my workplace has a need for apache/php with all static compilation. In order to save time adminning our systems, I decided to make my own RPM of php/apache with mod_ssl support. I had always installed by hand with the instructions on this page, but when buiding the RPM way, came upon the following error when apache was compiling:
===> src/modules/php4
make[4]: *** No rule to make target `all'. Stop.
Ordinarily this is because one did not do a 'make install' in php before the second apache configure, or somehow the make install failed. But the way rpm's work, the make install must be in the %install portion of the spec file, after all makes are completed.
make install-sapi
This line will copy relevant files to the directory specified in --with-apache
samael99 at web dot de
24-Jun-2004 06:51
Quick hint for people using RH8:
if make gives you this error
FT_ENCODING_MS_SYMBOL undeclared
change on line in this file
/usr/include/freetype2/freetype/freetype.h
Search for ft_encoding_symbol - change it to
ft_encoding_ms_symbol
Now this problem is dealt with, go ahead with make.
Good Luck !
robert_sgi at yahoo dot com
08-May-2004 11:57
If you install php 4 on SGI IRIX 6.5 (in my case it was php 4.3.6 on Silicon Graphics O2 IRIX 6.5.22 machine) and you're building it with:
--with-gettext=/usr/freeware
then you need to manually edit the file named "configure" (from the php source directory) and change the line# 36739
from:
GETTEXT_LIBDIR=$GETTEXT_DIR/lib
to:
GETTEXT_LIBDIR=$GETTEXT_DIR/lib32
If you have problems in locating the line, search the text for "bindtextdomain", and look several (4) lines above.
karthik (dot) k (at) extremix (dot) net
18-Jan-2004 08:28
This is regarding the post down below about the problem with openssl on RH9. Openssl on RH9 is built with kerberos. To get PHP to build correctly you need the output of these commands when you make.
[root@graf-spee local]# pkg-config --cflags openssl
-I/usr/kerberos/include
[root@graf-spee local]# pkg-config --libs openssl
-L/usr/kerberos/lib -lssl -lcrypto -lresolv -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -ldl -lz
These could be added to your make command thus. I have not tested it out, but should work with some tweaking
make EXTRA_LDFLAGS=`pkg-config --libs openssl` EXTRA_CFLAGS=`pkg-config --cflags openssl`
thansen at terra dot com dot br
30-Dec-2003 08:36
The configure directives --with-apxs2 and --with-apxs2filter are not compatible one with other, even though the configure script will not complain about that. Each one affect the way Apache will call the php parser: If you choose the first one, you must use the traditional include:
AddType application/x-httpd-php php

SetOutputFilter PHP
SetInputFilter PHP

, and php will be called as a filter to .php files.
If you use both together, you will get compilation errors (duplicate symbols while linking libphp4).
aaronmorris at mindspring dot com
05-Dec-2003 12:47
26-Mar-2003 12:52
doug at NOSPAM dot techie dot net
04-Feb-2003 05:16
Users compiling under some versions of Solaris/SunOS may encounter the following error.
symbol ap_block_alarms: referenced symbol not found
To address this problem, add the following additional flag to the Apache build configure line:
--enable-rule=SHARED_CORE
So, adding this to the original instructions, you'd configure your Apache build like so:
./configure --prefix=/www --enable-module=so --enable-rule=SHARED_CORE
Doug
mbabcock-php at fibrespeed dot net
20-Jul-2001 09:32
The best configuration guide I've found for Apache with PHP (and PERL, mod_ssl, etc.) is Apacompile. Its home site is
dimaberastau at hotmail dot com
09-Jun-2001 09:33
marshalm at ebrd dot com
17-May-2001 10:43
HP-UX 11.X PA-RISC installation with oracle (oci8). You need to install the HP-UX patch PHSS_22514 patch (updated libdld.sl), otherwise you will get errors with dlopen() and dlclose() not found during the apache integration stage.
philip at c()rnad() dot c()m
25-Mar-2001 04:22
HOWTO: Installation on Cobalt RaQ (RaQ3 or RaQ4) :
Copyright © Linux教程網 All Rights Reserved