您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mac系统使用内置的 PHP

2024/4/28 19:39:43发布16次查看
从 os x 10.0.0 版本开始,php 作为 mac 机的标准配置被提供。在默认的 web 服务器中启用 php,只需将 apache 配置文件 httpd.conf 中的几行配置指令最前面的注释符号去掉,而 cgi 或 cli 默认都可使用(可以很容易的被终端程序使用)。
按照以下的使用说明,可以快速的建立一个本地 php 开发环境。强烈建议将 php 升级到最新的版本。在大多数活跃的软件中, 新的版本会修复错误和添加新的功能,php 也是如此。请参见相应的 mac os x 安装文档,以进一步了解详细的信息。以下的说明以初学者的角度来详细描述如何操作来得到一个缺省的运行环境。建议所有的用户都编译或者安装一个新的打包版本。
标准的安装类型为 mod_php,在 mac os x 的 apache web 服务器(默认 web 服务器,可以从系统设置中访问)中启用 php 包含以下的步骤:
找到并打开apache的配置文件。默认情况下,这个配置文件的位置是: /private/etc/apache2/httpd.conf。 使用 finder 或者 spotlight 来找到这个文件可能不是很容易的事情,因为在默认情况下它一般是 root 用户拥有所有权的私有文件。 note: 要打开这个文件,可以在命令行下面使用基于 unix 的文本编辑器,例如 nano,因为他的属主是 root,所以我们需要使用 sudo 来打开(以 root 用户权限)。例如我们在 terminal 程序中敲入下面的指令(操作后,会提示输入密码):sudo nano /private/etc/apache2/httpd.conf 注意 nano 中的命令:^w(搜索),^o(保存),以及 ^x(退出)。^ 表示 ctrl 键。
note: 在mac os x 10.5之前的版本中捆绑的是旧版本的 php 和 apache。因此在旧的计算机中 apache 配置文件的位置可能是 /etc/httpd/httpd.conf。
使用文本的编辑器取消注释(删除前面的 #)看起来类似于下面的行(这两行常常不在一起,需要在文件中找到这两行):
# loadmodule php5_module libexec/httpd/libphp5.so# addmodule mod_php5.c
注意位置/路径。如果在以后重新编译了 php,以上文件应被更换或者注释掉。确保将所需要的文件扩展名解析为 php(例如:.php .html 以及 .inc),否则不能正常运行。
由于以下的配置已经写入 httpd.conf(自 mac panther 版起),一旦 php 被启用则 .php 文件会被自动解析为 php 脚本。
# if php is turned on, we respect .php and .phps files. addtype application/x-httpd-php .php addtype application/x-httpd-php-source .phps # since most users will want index.php to work we # also automatically enable index.php directoryindex index.html index.php


note:
在 os x 10.5(leopard)以前版本中,捆绑的是 php 4 而不是 php 5,因此上面的配置指令稍有不同,需要将 5 更改为 4。
确保 directoryindex 加载了所需的默认索引文件。 这个也是在 httpd.conf 中设置的。 通常情况下使用 index.php 和 index.html 。默认情况下 index.php 会被启用,因为在我们上面的配置指令中写明了。根据实际情况可以做相应的调整。 设置 php.ini 的位置或者使用默认的位置。 mac os x 上通常默认的位置是 /usr/local/php/php.ini ,调用 phpinfo() 也可以得到此信息。如果没有使用 php.ini,php 将使用所有的默认值。参见常见问题中的寻找 php.ini。 定位或者设置 documentroot。 这是网站所有文件的根目录。此目录中的文件由 web 服务器提供服务,从而使得 php 文件将在输出到浏览器之前解析为 php 脚本。通常情况下默认的路径是 /library/webserver/documents,但是可以根据需要在 httpd.conf中设置为任何其他目录。另外,用户自己的缺省 documentroot 是 /users/yourusername/sites。 创建一个 phpinfo() 文件。 phpinfo() 将会显示php的相关系统信息。可以在 documentroot 下创建一个 php 文件,其代码如下:
重启 apache,然后从浏览器访问上面创建的文件。 要重启apache,可以在 shell 中执行 sudo apachectl graceful,也可以停止/启动 os x 系统首选项中的“personal web server”选项。默认情况下,从浏览器访问本地文件的 url 一般类似于:http://localhost/info.php,或者使用:http://localhost/~yourusername/info.php 来访问用户自己 documentroot 中的文件。
cli(或者旧版本中的 cgi)一般文件名为 php ,其路径可能是 /usr/bin/php。打开一个终端,参考 php 手册中的 php 的命令行模式一章,然后执行 php -v 可以检查当前运行的 php 的版本。调用 phpinfo() 也会显示相关的信息。
user contributed notes 4 notes
8 months ago
to work on mac os x lion 10.7, i had to change /private/etc/php.ini.default to /private/etc/php.ini
5 years ago
you only have to uncomment:
#loadmodule php5_module        libexec/apache2/libphp5.so
this is gone:
# addmodule mod_php5.c
the statement in 3 was changed to:
# # typesconfig points to the file containing the list of mappings from # filename extension to mime-type. # typesconfig /private/etc/apache2/mime.types # # addtype allows you to add to or override the mime configuration # file specified in typesconfig for specific file types. # #addtype application/x-gzip .tgz # # addencoding allows you to have certain browsers uncompress # information on the fly. note: not all browsers support this. # #addencoding x-compress .z #addencoding x-gzip .gz .tgz # # if the addencoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # addtype application/x-compress .z addtype application/x-gzip .gz .tgz # # addhandler allows you to map certain file extensions to handlers: # actions unrelated to filetype. these can be either built into the server # or added with the action directive (see below) # # to use cgi scripts outside of scriptaliased directories: # (you will also need to add execcgi to the options directive.) # #addhandler cgi-script .cgi # for type maps (negotiated resources): #addhandler type-map var # # filters allow you to process content before it is sent to the client. # # to parse .shtml files for server-side includes (ssi): # (you will also need to add includes to the options directive.) # #addtype text/html .shtml #addoutputfilter includes .shtml
extra mime types can either be added to the file /private/etc/apache2/mime.types or by using an addtype directive as commented on above.
5 years ago
additionally, it seems that the default installation of php on mac os x (10.5 tested) does not point to the default location of the mysql.sock file that is installed in a standard mysql 5.0 installation.
this prevents php working with locally hosted mysql databases.
adding the following line to the /private/etc/apache2/other/php5.conf file did the trick:
php_value mysql.default_socket /tmp/mysql.sock
(make sure you put it in between the statements)
5 years ago
i am using macosx 10.5.4 and only enabling the mod_php5 wasn't enough to get the php support. i had to add following block before i could use php on machine -
# if php is turned on, we respect .php and .phps files. addtype application/x-httpd-php .php addtype application/x-httpd-php-source .phps # since most users will want index.php to work we # also automatically enable index.php directoryindex index.html index.php

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product