ページ更新: 2011-03-17 (木) (3602日前)
関連: ソフト/Script言語/PHP (2004-07-26 新規作成) CygwinのApacheで、自分でコンパイルしたPHPを使ってみた。 Cygwinじゃなくて、Windows版を使った方が簡単だと思うけど。 目次 [編集]情報源 #(My source) これらの情報を提供してくださった方に感謝します。
Apache 1.3.29-2 + PHP 4.3.8 (2004-07-26) #[編集]バージョンを調べる #(Examine the version of Cygwin packages, and record it. ) apacheに必要なパッケージとバージョンを調べる。 これから行う作業が、どのバージョンで使えたかどうか記録するため: $ grep -A20 '@ apache' /path/to/setup.ini | grep require requires: cygwin crypt libgdbm4 $ cygcheck -cd cygwin apache crypt libgdbm4 Cygwin Package Information Package Version apache 1.3.29-2 crypt 1.1-1 cygwin 1.5.10-3 libgdbm4 1.8.3-7[編集] PHPをコンパイルする #(Compile PHP.) PHPのソースコードを入手しておく。今回は php-4.3.8.tar.bz2 を入手しておいた。 PHPのソースコードを展開する: $ mkdir -p /usr/local/src/php $ cd /usr/local/src/php $ tar jxvf php-4.3.8.tar.bz2 php-4.3.8/ php-4.3.8/ext/ : : php-4.3.8/README.UNIX-BUILD-SYSTEM php-4.3.8/php4.spec.in configureを実行する: $ cd php-4.3.8 $ ./configure --with-apxs=/usr/sbin/apxs --without-mysql --enable-mbstring creating cache ./config.cache checking host system type... i686-pc-cygwin : : creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ | *** NOTE *** | | The default for register_globals is now OFF! | | | | If your application relies on register_globals being ON, you | | should explicitly set it to on in your php.ini file. | | Note that you are strongly encouraged to read | | http://www.php.net/manual/en/security.registerglobals.php | | about the implications of having register_globals set to on, and | | avoid using it if possible. | +--------------------------------------------------------------------+ Thank you for using PHP. sedを使って、Makefileの中の「libphp4.so」を「libphp4.dll」に置き換える(-i は --in-place)。diffで確認する。: $ sed -i.org 's/libphp4\.so/libphp4.dll/g' Makefile $ diff Makefile.org Makefile : : makeを実行してコンパイルする: $ make : : Build complete. (It is safe to ignore warnings about tempnam and tmpnam). $ cd libs $ ls libphp4.a libphp4.la gccを使って dll を作る。-lresolv (=/lib/libresolv.a) を追加。 (--whole-archive, --no-whole-archive の順番の根拠は不明。): $ gcc -shared -o libphp4.dll -Wl,--out-implib=libphp4.dll.a \ -Wl,--export-all-symbols \ -Wl,--whole-archive libphp4.a /bin/cyghttpd.dll \ -Wl,--no-whole-archive -lcrypt -lresolv Creating library file: libphp4.dll.a Info: resolving _ap_user_id by linking to __imp__ap_user_id (auto-import) Info: resolving _ap_group_id by linking to __imp__ap_group_id (auto-import) Info: resolving _ap_user_name by linking to __imp__ap_user_name (auto-import) Info: resolving _ap_max_requests_per_child by linking to __imp__ap_max_requests_ per_child (auto-import) Info: resolving _ap_server_root by linking to __imp__ap_server_root (auto-import) Info: resolving _top_module by linking to __imp__top_module (auto-import) 出来たバイナリを調べる。ちゃんと libphp4.dll が生成された。: $ ls libphp4.a libphp4.dll libphp4.dll.a libphp4.la[編集] PHPのモジュールをインストールする #(Install 'libphp4.dll' in Apache. ) インストールする: $ cd .. $ make install Installing PHP SAPI module: apache [activating module `php4' in /etc/apache/httpd.conf] cp libs/libphp4.dll /usr/lib/apache/libphp4.dll chmod 755 /usr/lib/apache/libphp4.dll cp /etc/apache/httpd.conf /etc/apache/httpd.conf.bak cp /etc/apache/httpd.conf.new /etc/apache/httpd.conf rm /etc/apache/httpd.conf.new Installing PHP CLI binary: /usr/local/bin/ Installing PHP CLI man page: /usr/local/man/man1/ Installing PEAR environment: /usr/local/lib/php/ [PEAR] Archive_Tar - installed: 1.1 [PEAR] Console_Getopt - installed: 1.2 [PEAR] PEAR - installed: 1.3.2 Wrote PEAR system config file at: /usr/local/etc/pear.conf You may want to add: /usr/local/lib/php to your php.ini include_path [PEAR] DB - installed: 1.6.2 [PEAR] HTTP - installed: 1.2.2 [PEAR] Mail - installed: 1.1.3 [PEAR] Net_SMTP - installed: 1.2.3 [PEAR] Net_Socket - installed: 1.0.1 [PEAR] XML_Parser - installed: 1.0.1 [PEAR] XML_RPC - installed: 1.1.0 Installing build environment: /usr/local/lib/php/build/ Installing header files: /usr/local/include/php/ Installing helper programs: /usr/local/bin/ program: phpize program: php-config program: phpextdist[編集] ApacheにPHPの設定を追加する #/etc/apache/httpd.conf に次の行が追加されたかどうか調べ、無ければ追加する: LoadModule php4_module lib/apache/libphp4.dll AddModule mod_php4.c /etc/apache/httpd.conf に以下の部分に、<IfModule mod_php4.c>AddType...</IfModule>を追加する。: # # Document types. # <IfModule mod_mime.c> # for PHP 4.x # <IfModule mod_php4.c> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule> </IfModule> # End of document types. httpd.confのエラーチェックを行う: $ /usr/sbin/apachectl configtest Syntax OK[編集] ApacheとPHPの動作を確認する #Apacheを起動する: $ net start httpd Cygwin httpd サービスを開始します. Cygwin httpd サービスは正常に開始されました。 動作を確認する。 次の内容の /var/www/htdocs/phpinfo.php を作成し: <?php phpinfo(); ?> ブラウザで http://localhost/phpinfo.php にアクセスする……と、PHPの画面が表示された。 ためしに PukiWiki 1.4.3 を入れたところ、動いた。 [編集]補足 #[編集]libresolv.a を含むパッケージ #2005-05-05 libresolv.aの由来を調べる: $ ls -al /lib/libresolv.a lrwxrwxrwx 1 username なし 25 Nov 27 2003 /lib/libresolv.a -> /usr/lib/libminires.dll.a $ cygcheck -f /usr/lib/libminires.dll.a minires-devel-1.00-1 /usr/include/resolv.hも確認。同じパッケージだ: $ cygcheck -f /usr/include/resolv.h minires-devel-1.00-1 setup.iniのminiresに関する部分を見てみる: $ grep -A 5 '^@ minires' /path/to/setup.ini @ minires sdesc: "A simple synchronous non caching stub resolver." ldesc: "A simple synchronous non caching stub resolver providing the basic functionality of bind. It interfaces to Windows to find the DNS servers. On Windows 2000+, it defaults to using the Windows caching resolver." -- @ minires-devel sdesc: "Development tools to build programs using minires." ldesc: "Development to build programs using minires, a simple synchronous non caching stub resolver providing the basic functionality of bind. Minires interfaces to Windows to find the DNS servers. On Windows 2000+, it defaults to using the Windows caching resolver." パッケージ含まれるファイルの一覧を表示: $ cygcheck -l minires /usr/bin/cygminires.dll /usr/share/doc/Cygwin/minires-1.00-1.README /usr/share/doc/minires-1.00/LICENSE $ cygcheck -l minires-devel /usr/lib/libminires.dll.a /usr/lib/libminires.a /usr/include/arpa/nameser.h /usr/include/arpa/nameser_compat.h /usr/include/resolv.h /etc/postinstall/minires-devel.sh パッケージにはシンボリックリンク/usr/lib/libresolv.aは含まれない。 しかし、 /etc/postinstall/minires-devel.sh があるので、ここで作っているはず。 試しに表示してみると: $ cat /etc/postinstall/minires-devel.sh.done #! /bin/sh set -e if [ ! -e /usr/lib/libresolv.a ] then if [ -L /usr/lib/libresolv.a ] then /bin/rm -f /usr/lib/libresolv.a fi ln -s /usr/lib/libminires.dll.a /usr/lib/libresolv.a fi /usr/share/doc/Cygwin/minires-1.00-1.README も読んでみる。なんと、/etc/resolv.confも使えるようだ。 |