Notes for anyone trying to get PHP to work with Apache in CGI mode (rather than as a shared module):
http://www.bobulous.org.uk/coding/apache-php-cgi.html
I know that php.net recommends using the more secure shared module mode, but I wanted my development rig to match the setup of my ISP as closely as possible, and my ISP insists they know what they're doing running PHP in CGI mode. (They actually said that CGI was more secure, which I found a bit of a stretch.)
The page is mostly a big, long set of notes for me in case I need to build and configure Apache and PHP in CGI mode again in the future, but I'm hoping that the page may be of use to others too.
Unix システムへのインストール
目次
- Apache 2.0 (Unixシステム用)
- Lighttpd 1.4 (Unix システム用)
- Caudium サーバ
- fhttpd サーバ
- Sun, iPlanet, Netscape サーバ(Sun Solaris 用)
- CGI およびコマンドライン
- HP-UX へのインストール
- OpenBSD へのインストール
- Solaris へのインストール
- Debian GNU/Linux へのインストール
本章では、UNIX 系のシステムへの PHP のインストールと設定に関する 手引きを示します。使用するプラットフォームや Web サーバについての セクションを参照して、インストールを行ってください。
このマニュアルでは、 「インストールにあたっての一般的な注意事項」 の章で述べたように、Web 用のセットアップを主に扱います。加えて、 コマンドラインから PHP を使うためのセットアップについても扱います。
Unix プラットホームに PHP をインストールする方法はいくつかあり、 コンパイルして設定するやり方と(コンパイル済みの)パッケージを使う方法とに 別けられます。この手引きでは、コンパイルして設定する方法を主に取り上げます。 Unix 系システムには、パッケージを用いるインストールシステムを持つものも多く、 一般的なセットアップを行うには、パッケージが役に立つでしょう。ただし、 (セキュアサーバや様々なデータベースドライバなど)少々特殊な機能が必要な場合、 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 の configure が完了していないと、 拡張モジュールや本体の実行ファイルのビルドができません。 make コマンドの実行にあたっては、注意してください。 configure がうまく行かず原因もよくわからない場合は、 問題が起きた場合 についての章を参照してください。
Apache 1.3.x (Unix システム用)
このセクションでは、PHP を Unix プラットフォームの Apache 1.3.x にインストールする際の 手引きと注意事項について説明します。Apache 2 に関する手引きと注意 は 別のセクションにあります。
以下の説明では、バージョン番号が意図的に省略されています。 'xxx' の部分を使用するファイルに対応する番号に置き換えてください。 また、手順 10 で configure に与える引数は、 configure のすべてのオプション から選択できます。
例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 の configure を行います。ここでは、様々なオプションを指定して、 特定の拡張モジュールを有効にするといった、カスタマイズを行います。 指定可能なオプションの一覧は、./configure --help を実行すると得られ ます。以下に、簡単な設定例を示します。Apache 1 と MySQL のサポートを 有効にする例です。apxs のパスは、Apache のインストールパスによって 異なる場合があります。 ./configure --with-mysql --with-apxs=/www/bin/apxs 11. make 12. make install configure オプションを変更して再インストールする場合は、最後の 3 つ の手順を繰り返します。共有モジュールとしてコンパイルされた PHP を 有効にするには Apache を再起動するだけです。Apache の再コンパイルは 必要ありません。 特に指定がない限り、'make install' は、PEAR, phpize のような様々な 関連ツール、CLI 版 PHP などもインストールすることに注意してください。 13. php.ini ファイルをセットアップ cp php.ini-dist /usr/local/lib/php.ini PHP の実行時設定を変更するには、.ini ファイルを編集します。 このファイルを他の場所に置きたい場合は、手順 10 で、 オプション --with-config-file-path=/path を使用します。 php.ini-dist ではなく、php.ini-recommended を使用する場合は、PHP の 動作が変化しますので、ファイル中に記載されている変更点の一覧を確認する ようにしてください。 14. httpd.conf を編集し、PHP の共有モジュールをロードするよう設定します。 LoadModule 命令の右側に記述するパスは、システムの PHP 共有モジュール を指している必要があります。上記の make install により既にこの設定は 追加されている場合もありますが、確認が必要です。 PHP 4 の場合: LoadModule php4_module libexec/libphp4.so PHP 5 の場合: LoadModule php5_module libexec/libphp5.so 15. httpd.conf の AddModule セクションに以下を追加します。 ClearModuleList の下あたりに追加してください。 PHP 4 の場合: AddModule mod_php4.c PHP 5 の場合: AddModule mod_php5.c 16. Apache が特定の拡張子のファイルを PHP としてパースするよう(httpd.conf を編集して)設定します。例えば、Apache が拡張子 .php のファイルを PHP としてパースするように設定します。複数の拡張子も、空白で区切って記述する だけで PHP としてパースさせることができます。以下の例は .php と .phtml とを指定した場合です。 AddType application/x-httpd-php .php .phtml PHP のソースをハイライト表示させるために、拡張子 .phps を設定することも よく行われます。 AddType application/x-httpd-php-source .phps 17. Apache サーバを、通常の手順通り、起動させます(HUP または USR1 シグナルを 使用してリロードするのではなく、サーバを停止させてから 再起動する必要があります)。
PHP を静的オブジェクトとしてインストールすることも可能です。
例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 バイナリディレクトリにコピーすることが できます。最初のインストールの場合は、この後 "make install" を行います。) 13. cd ../php-5.x.y 14. cp php.ini-dist /usr/local/lib/php.ini 15. /usr/local/lib/php.ini を編集すると、PHP の実行時設定を変更できます。 httpd.conf もしくは srm.conf ファイルを編集し、以下を追記します。 AddType application/x-httpd-php .php
注意: PHP 4 については、php-5 を php-4 へ、 php5 を php4 へ置き換えてください。
インストールされている Apache や UNIX の種類によりますが、サーバの停止・再起動の 方法はいくつもあります。いろいろな Apache/UNIX の組合せを想定して、 サーバを再起動する典型的な方法を以下に示します。 /path/to/ を使用するシステムのアプリケーション へのパスに置き換えてください。
例3 Apache を再起動するためのコマンドの例
1. Linux および System V 系 /etc/rc.d/init.d/httpd restart 2. apachectl スクリプトを使用する方法 /path/to/apachectl stop /path/to/apachectl start 3. (OpenSSL を使用している場合) httpdctl および httpsdctl を使用する方法 /path/to/httpsdctl stop /path/to/httpsdctl start 4. mod_ssl や他の SSL サーバを使用している場合、手動で stop や start する /path/to/apachectl stop /path/to/apachectl startssl
apachectl および http(s)dctl の実行ファイルの位置は、システムにより 異なります。システムが locate もしくは whereis、which コマンドを サポートしているなら、これらサーバ制御用プログラムを見つけるために使用すると 便利でしょう。
PHP を Apache 用にコンパイルするには、いくつかの方法があります。以下に例を示します。
./configure --with-apxs --with-pgsql
この例では、Apache がロードする共有モジュールのライブラリ libphp5.so (あるいは PHP 4 では libphp4.so) が作成されます。この共有ライブラリの読み込みは、Apache の設定ファイル httpd.conf の LoadModule の行にて設定します。また、このライブラリには、 PostgreSQL サポートが埋め込まれます。
./configure --with-apxs --with-pgsql=shared
この例でも Apache 用 libphp4.so 共有ライブラリ が作成されます。加えて、(PHP 拡張モジュールの)共有ライブラリ pgsql.so も作成されます。この共有ライブラリ は、PHP 設定ファイル php.ini の extension ディレクティブにより、 もしくは PHP スクリプト内で明示的に dl() 関数により ロードされます。
./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
この例は、上と同様ですが、最終的な httpd バイナリに PostgreSQL サポートは直接埋め込まれません。共有ライブラリ pgsql.so が作成され、PHP 設定ファイル php.ini、もしくは dl() 関数により明示的に PHP にロードすることができます。
PHP のビルド方法を選択する際には、各方法の利点と欠点を考慮する必要 があります。共有モジュールのオブジェクトとしてビルドすると、Apache とは別に コンパイルすることができ、PHP を追加または変更する際に全体を 再コンパイルする必要がありません。PHP を Apache に(静的に)組み込むと、 PHP はより高速にロード・実行されます。詳細な情報については、 Apache の Web ページ 「» 動的共有オブジェクト (DSO) サポート」 を参照してください。
注意: Apache のデフォルトの httpd.conf には、次のように記述されたセクションがあります。
これを "Group nogroup" (や "Group daemon")等に変更しないと、 PHP はファイルをオープンすることができません。User nobody Group "#-1"
注意: --with-apxs=/path/to/apxs オプションを 指定する場合には実際にシステムにインストールされている apxs を指定してください。 Apache のソースディレクトリ内にある apxs を指定してはいけません。
Unix システムへのインストール
15-Oct-2008 03:53
08-Feb-2008 11:51
On Red Hat EL5.1 you need to install the libtool-ltdl-devel package (or the workaround below) to compile php.
symbolic link libltdl.so to libltdl.so.3.1.4 missing and the compile will fail.
Noting this because it wasn't necessary in Red Hat EL4.1 and caused confusion. I verified this on the box I'm migrating from. Since I built the box, and compiled php on it, I know I didn't need to do this before.
You can get around needing to install this devel.
Workaround:
# cd /usr/lib
# ln -s libltdl.so.3.1.4 libltdl.so
The devel rpm isn't necessary, just the link. I'll leave it at that. This is an rpm packaging convention change with ES5.
-Neil
27-Oct-2007 07:06
If you install PHP as an Apache module, you can consider the following. Instead of adding:
application/x-httpd-php php
application/x-httpd-php-source phps
into Apache mime.types, you can add:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
into Apache httpd.conf, OR you can add:
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
into Apache httpd.conf. The last one is the preferred way of configuration, but it does not work in previous Apache versions.
18-Oct-2007 01:19
Further down in the links it talks about using the fPIC option in the compiler to fix the SElinux error. I messed around with it and adding --with-pic to the configure will also allow the module to load. I have not done more testing with it but apache at least starts. If you have already compiled you will need to do a make clean before recompiling.
18-Oct-2007 12:16
If you get an apache failing to start message with SElinux enabled.
The error in var/log/messages is:
Oct 17 10:41:49 nwn kernel: audit(1192635709.825:37936): avc: denied { execmod } for pid=23189 comm="httpd" name="libphp5.so" dev=hda3 ino=4980740 scontext=user_u:system_r:unconfined_t:s0 tcontext=user_u:object_r:usr_t:s0 tclass=file
See the following page:
http://danwalsh.livejournal.com/6117.html?thread=23525
Basically do a chcon -t textrel_shlib_t libphp5.so
It does not sound like it is too dangerous.
13-Sep-2007 07:05
For all multi-core processors (not just Sun as noted above) you need to add --enable-shared-core to the apache config
13-Nov-2006 04: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.
01-Oct-2006 12: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
13-Jul-2006 03: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
See also http://fedora.redhat.com/docs/selinux-faq/ and http://php.net/results.php?q=selinux&p=wholesite
07-Mar-2006 10:15
Building Apache 2 and PHP 5.1.2 :
On AIX 5.2 : http://flaupretre.free.fr/redir.php?key=build_apa_aix
On HP-UX 11i (11.11) : http://flaupretre.free.fr/redir.php?key=build_apa_hpux
These documents are complete step-by-step howtos, and describe how to buid a self-sufficient package, including every software it depends on (zlib, SSL, LDAP, iconv, expat, xml, xslt, gd, png, Xpm, jpeg, freetype, bzip2, curl, MySQL, PostgreSQL, Oracle, AdoDB).
07-Nov-2005 07: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=<path to Apache 2.0/bin/apxs> --with-oci8=$ORACLE_HOME --enable-sigchild
It should now build correctly. The key with Oracle is to ensure that you pick up the libclntX.so (client librariess) where X is the Oracle version associated with the version your using for instance, in the above example, libclnt9.so
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.
23-Mar-2005 08: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..
23-Dec-2004 04: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
31-Dec-2003 12: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
at httpd.conf, to call the parser. If you use the --with-apxs2filter, the include will be:
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
</Files>
, 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).
06-Dec-2003 04:47
If you have the libphp4.a instead of libphp4.so on AIX, you can extract the .so file from the .a file by running "ar -x libphp4.a".
27-Mar-2003 04:52
http://dan.drydog.com/apache2php.html has a nice set of instructions for Apache2 + php
04-Feb-2003 09: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
10-Jun-2001 12:33
when installing with mysql support (--with-mysql=<path/to/your/mysql>) via Apache APXS you'll probably get something like 'can't load libmysqlclient.so' when you try to start up apache. There are 2 solutions to this problem. First, (as documented in INSTALL file of the php4 distribution) you can modify /etc/ld.so.conf to contain the directory name where libmysqlclient.so is (so if your mysql is installed in /usr/local, you want to add something like /usr/local/lib/mysql into /etc/ld.so.conf), else (and particularly if you haven't got the super-user on the system) you can modify (or create if it isn't defined already) LD_LIBRARY_PATH shell variable to reflect the changes you would have otherwise made to /etc/ld.so.conf (again if mysql is /usr/local LD_LIBRARY_PATH=/usr/local/lib/mysql). Either one of these methods will get the problem sorted. Just remember to run ldconfig (so that /etc/ld.so.cache is updated) if you chose to modify /etc/ld.so.conf
18-May-2001 01: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.
