在 Mac OS X 客户版编译

以下说明将会帮助在 Mac OS X 下为 Apache 服务器安装 PHP 模块,并添加 MySQL 和 PostgreSQL 的支持。本说明是由 Marc Liyanage 提供的。

警告

请注意,在按照下面的步骤操作时,应该停止 Apache 服务器!

按照下面的步骤安装:

  1. 打开终端窗口。

  2. 输入 wget http://www.diax.ch/users/liyanage/software/macosx/libphp4.so.gz,等待下载完毕。

  3. 输入 gunzip libphp4.so.gz

  4. 输入 sudo apxs -i -a -n php4 libphp4.so

  5. 现在输入 sudo open -a TextEdit /etc/httpd/httpd.conf。TextEdit 将把 web 服务器的配置文件打开。在文件的末尾找到下面两行(使用查找命令):
    #AddType application/x-httpd-php .php
    #AddType application/x-httpd-php-source .phps
    将它们前面的两个井号(#)去掉,然后保存文件并退出 TextEdit。

  6. 最后,输入 sudo apachectl graceful 重新启动 web 服务器。

PHP 现在应该已经配置好,并且正在运行了。可以在 Sites 文件夹创建一名为 test.php 的文件。该文件的内容为: <?php phpinfo() ?>

现在在 web 浏览器浏览 127.0.0.1/~your_username/test.php。应该可以看到一个表格列出了 PHP 模块的信息。


add a note add a note User Contributed Notes
php dot developement at ipscripted dot com
25-Aug-2006 12:08
You can aslo compile php 5 from source for use with the Apache 2 and MySQL packge from server logistics:

Download the latest source (at time of writing, 5.1.5) from php.net, unpack it to any directory you have write access to (your home directory, for example). Make sure that Apache 2 is stopped. Then open a terminal.

1)If you are running as a limited user (which you should generally do), you need  to log in as a administrator by typing
         login admin
     and then entering your password
if you are running as an administrator, skip step 1

2)change to the directory in which you have php unpacked to:
   cd /directory/in/which/is/php-1.5.1
3) configure:
   ./configure --prefix=/Library/PHP5 --with-mysql=/Library/MySQL --with-apxs2=/Library/Apache2/bin/apxs
you can also append  any other configuration options you want
4) type:
   make
this will compile php. You need to have GCC installed, you can get it for free with Apple's xcode Developement environment.
5) when make finnished, type:
   make install
if you are running as a administrator (but not root), type
   sudo make install
it will ask you for your password and then install php into the specified directory
You might have to add the following lines to your httpd.conf, if you hadn't had Server Logistics php 4 installed.

6) Start Apache and test php by creating a new file test.php and saving the following line to it:
<?php phpinfo(); ?>
when you browse to that file, you should see the php info page
Michael Hawkshaw
14-Sep-2004 04:11
Please note that Marc has now compiled a PHP 5.0.1 version of his package. It can be downloaded at:

http://www.entropy.ch/software/macosx/php/

There is also a forum on his site for discussing his package should you have have any queries/issues.
BjarneDM <macintosh at mathiesen dot info>
28-Aug-2004 02:09
This will only install a precompiled PHP4 module for the Apache 1.3.x included by Apple in Mac OS X client. This will not install a cli version of PHP.

If you want to play with Apache2 and PHP the way to go is ServerLogistics < http://www.serverlogistics.com/ >, but this will still be a precompiled version. On the other hand you can both get the Apache2 module and a cli version.

ServerLogistics does include some rudimentary information on how to compile yourself on Mac OS X in the pdf documentation, but it is erroneous in some circumstances, and for newer versions of PHP will neccesiate installation of fink < http://fink.sourceforge.net/ > or darwinports < http://darwinports.opendarwin.org/ > in order to get newer libraries.