mac系统使用内置的 PHP
从 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 脚本。
<IfModule mod_php5.c>
# 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
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>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 文件,其代码如下:
<?php phpinfo(); ?> - 重启 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
To work on Mac OS X Lion 10.7, I had to change /private/etc/php.ini.default to /private/etc/php.ini 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:
<IfModule mime_module>
#
# 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
</IfModule>
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.
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 </IfModule> statements)
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 -
<IfModule mod_php5.c>
# 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
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
mac系统使用内置的 PHP的更多相关文章
- 在Eclipse+ADT中开发Android系统的内置应用
转自: http://www.iteye.com/topic/1050439 在Eclipse+ADT中开发Android系统的内置应用 Android系统内置有:Browser(浏览器).Mms( ...
- Liunx运维(十二)-Liunx系统常用内置命令
文档目录: 一.Liunx内置命令概述 二.LIunx常用内置命令实例 1.help查看内置命令帮助2.查看内置命令使用方法3.":" 占位符4. "." 与s ...
- 递归生成treeview树形节点(没有用递归函数之后会有补充,这里只用系统的内置方法去生成)
using System;using System.Collections.Generic;using System.ComponentModel;using System.IO;using Syst ...
- JDK内置日志系统
1.Java应用中的日志功能 ================= 一般的Java应用程序中都有记录日志的需求,目前主流的记录日志的方法是在应用程序中引入log4j,用log4j来生成日志.其实,JDK ...
- Mac系统中各个文件夹简单介绍(转)
一.说明: Mac OS X,这是一个基于UNIX核心的系统,增强了系统的稳定性.性能以及响应能力.它能通过对称多处理技术充分发挥双处理器的优势,提供无与伦比的2D.3D和多媒体图形性能以及广泛的字体 ...
- 启用Mac系统读写NFTS磁盘
从Mac OSX 10.6系统开始苹果系统已经内置对NTFS写入功能,但苹果没有公开说明,而且在默认状态下是没有开启的.SL-NTFS是一款Mac上的小工具,它可以直接为你的Mac增加NTFS的写入权 ...
- 与众不同 windows phone (47) - 8.0 其它: 锁屏信息和锁屏背景, 电池状态, 多分辨率, 商店, 内置协议, 快速恢复
[源码下载] 与众不同 windows phone (47) - 8.0 其它: 锁屏信息和锁屏背景, 电池状态, 多分辨率, 商店, 内置协议, 快速恢复 作者:webabcd 介绍与众不同 win ...
- Java Script基础(五) 内置对象Date
在JavaScript中,系统的内置对象有Date对象.Array对象.String对象和Math对象等. 1.Date:用于操作日期和时间. 2.Array:用于在单独的变量名中存储一系列的值. 3 ...
- Python学习笔记011——内置函数exec()
1 描述 把一个字符串当成语句执行 exec() 执行储存在字符串或文件中的 Python 语句,相比于 eval() , exec() 可以执行更复杂的 Python 代码. exec函数和ev ...
随机推荐
- 我的Android六章:Android中SQLite数据库操作
今天学习的内容是Android中的SQLite数据库操作,在讲解这个内容之前小编在前面有一篇博客也是讲解了SQLite数据库的操作,而那篇博客的讲解是讲述了 如何在Window中通过DOM来操作数据库 ...
- Android常用抓包工具之TcpDump
➠更多技术干货请戳:听云博客 做为一个测试人员,工作中经常会用到数据抓包工具来进行数据分析和验证,下面就简单介绍一下工作中常用的抓包工具. TcpDump抓包 Tcpdump是一个用于截取网络分组,并 ...
- Nodejs的模块实现
在Node中引入模块,需要经历如下3个步骤:(1)路径分析(2)文件定位(3)编译执行 Node中模块分为两类: 一是Node提供的模块——核心模块.这部分在Node源代码的编译过程中,编译进了二进制 ...
- Java基础知识学习(八)
IO操作 5个重要的类分别是:InputStream.OutStream.Reader.Writer和File类 面向字符的输入输出流 输入流都是Reader的子类, CharArrayReader ...
- js中Prototype属性解释及常用方法
1.prototype的定义 javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用. 每一个构造函数都有一个属 ...
- js中的==运算: [''] == false —>true
图1 计算下面表达式的值: [''] == false 首先,两个操作数分别是对象类型.布尔类型.根据图1,需要将布尔类型转为数字类型,而false转为数字的结果是0,所以表达式变为: [''] == ...
- 各类 HTTP 返回状态代码详解
完整版 1**(信息类):表示接收到请求并且继续处理 100——客户必须继续发出请求 101——客户要求服务器根据请求转换HTTP协议版本 2**(响应成功):表示动作被成功接收.理解和接受 200— ...
- SQL Server 分页方法汇总
PageSize = 30 PageNumber = 201 方法一:(最常用的分页代码, top / not in) UserId UserId from UserInfo order by Use ...
- jquery最常用的几个方法。
jquery使用手册:http://www.eduyo.com/doc/jquery/cheatsheet.html addClass 样式: <style> .textRed { col ...
- coursera机器学习笔记-神经网络,初识篇
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...