您如何配置 Mac OS X 附带的 Apache 服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/69768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you configure the Apache server which ships Mac OS X?
提问by tsellon
Mac OS X ships with apache pre-installed, but the files are in non-standard locations. This question is a place to collect information about where configuration files live, and how to tweak the apache installation to do things like serve php pages.
Mac OS X 预装了 apache,但文件位于非标准位置。这个问题是一个收集有关配置文件所在位置的信息的地方,以及如何调整 apache 安装以执行诸如提供 php 页面之类的操作。
回答by ctcherry
Apache Config file is: /private/etc/apache2/httpd.conf
Apache 配置文件是:/private/etc/apache2/httpd.conf
Default DocumentRoot is: /Library/Webserver/Documents/
默认 DocumentRoot 是:/Library/Webserver/Documents/
To enable PHP, at around line 114 (maybe) in the /private/etc/apache2/httpd.conf file is the following line:
要启用 PHP,在 /private/etc/apache2/httpd.conf 文件中的第 114 行(可能)是以下行:
#LoadModule php5_module libexec/apache2/libphp5.so
Remove the pound sign to uncomment the line so now it looks like this:
删除英镑符号以取消注释该行,现在它看起来像这样:
LoadModule php5_module libexec/apache2/libphp5.so
Restart Apache: System Preferences -> Sharing -> Un-check "Web Sharing" and re-check it. OR
重新启动 Apache:系统偏好设置 -> 共享 -> 取消选中“网络共享”并重新选中它。 或者
$ sudo apachectl restart
回答by Patrick
Running
跑步
$ httpd -V
$ httpd -V
will show you lots of useful server information, including where the httpd.conf file can be found.
将向您显示许多有用的服务器信息,包括可以找到 httpd.conf 文件的位置。
回答by Scott Willeke
To get SSI/includes (mod_include) to work I found I had to edit /private/etc/apache2/users/myusername.confand change AllowOverride Noneto AllowOverride All.
为了让 SSI/includes (mod_include) 工作,我发现我必须编辑/private/etc/apache2/users/myusername.conf并更改AllowOverride None为AllowOverride All.
Then add the following in a .htaccess file in the root of your site:
然后在站点根目录的 .htaccess 文件中添加以下内容:
Options +Includes
AddType text/html .html
AddOutputFilter INCLUDES .html
回答by Michael Cramer
/etc/httpd/userscontains user-specific configuration files which can be used to override the global configuration. For example, adding "AddHandler server-parsed html" to the <Directory>block in the /etc/httpd/users/*.conffile that corresponds to one user will enable mod_include parsing of HTML files for that particular user's $HOME/Sitesdirectory, but nowhere else.
/etc/httpd/users包含用户特定的配置文件,可用于覆盖全局配置。例如,将“ AddHandler server-parsed html”添加到/etc/httpd/users/*.conf文件中对应于一个用户的<Directory>块将启用 mod_include 解析该特定用户的$HOME/Sites的 HTML 文件目录,但没有其他地方。
回答by Larry OBrien
httpd.conf is in /private/etc/apache2
httpd.conf 位于 /private/etc/apache2
Enable PHP by uncommenting line:
通过取消注释行启用 PHP:
LoadModule php5_module libexec/apache2/libphp5.so

