更改优胜美地Apache 2.4的本地主机目录 [英] Change localhost directory for Yosemite Apache 2.4

查看:91
本文介绍了更改优胜美地Apache 2.4的本地主机目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经全新安装了Mac OSX Yosemite,但无法像以前在旧版OSX上一样配置Apache 2.4.

I have clean installed Mac OSX Yosemite but I cant configure the Apache 2.4 like I have always done on older OSX versions.

这是我想做的:将"localhost"目录设置为"/Users/username/Public/". 但是,我尝试的所有方法都无法正常工作,我总是收到禁止访问,无法访问/",或者得到默认的它有效!".页面...

Here is what I want to do : set the "localhost" directory to "/Users/username/Public/". But, everything I tried won't work, I always get a "Forbiden, can't access to /" or I get the default "It works!" page...

如何简单地重新引导我的本地主机?

How to simply reroot my localhost ?

Thx

编辑(感谢Krister Andersson的回答)

对于Mac OSX 10.10 Yosemite

For Mac OSX 10.10 Yosemite

我还发布了为保持运行状态所做的更改.

I also post the changes I had to do to keep things running.

在"/etc/apache2/users/"中,我创建了一个用我的用户名命名的文件,例如"myUsername.conf".

In "/etc/apache2/users/", I created a file named by my username like this "myUsername.conf".

您可以通过在终端中键入"id"来获取用户名.您应该在"uid = 501(myUsername)"开头找到您的用户名.

You can get your username by typing "id" in terminal. You should find your username at start in "uid=501(myUsername)".

在这个新的"myUsername.conf"文件中,只需复制以下内容即可:

In this new "myUsername.conf" file, just copy past this:

<Directory "/Users/myUsername/Sites/">
    AllowOverride All
    Options Indexes MultiViews
    Options +FollowSymLinks
    Require all granted
</Directory>

请勿原谅更改myUsername值.

然后,在"/etc/apache2/httpd.conf"文件中,取消注释所有这两行:

Then, in the "/etc/apache2/httpd.conf" file, uncomment all these two lines:

167 #LoadModule userdir_module libexec/apache2/mod_userdir.so
169 #LoadModule php5_module libexec/apache2/libphp5.so

第236行,将"DocumentRoot"的目录更改为所需的目录. 在第250行中,将选项"设置为选项"选项索引FollowSymLinks多视图". 在第258行中,将"AllowOverride None"设置为"AllowOverride All". 在第263行中,将要求所有被拒绝"设置为要求所有被授予"

Line 236, change the directory of "DocumentRoot" to whatever you want. Line 250, set "Options" to "Options "Options Indexes FollowSymLinks Multiviews". Line 258, set "AllowOverride None" to "AllowOverride All". Line 263, set "Require all denied" to "Require all granted"

在终端中,通过键入"sudo apachectl restart"来重新启动apache.

In Terminal, restart apache by typing "sudo apachectl restart".

它适用于Mac OS X 10.10 Yosemite全新安装.

It work's for me on Mac OS X 10.10 Yosemite clean install.

推荐答案

我刚刚安装了Yosemite,并且设法成功更改了DocumentRoot.首先,我在/private/etc/apache2/httpd.conf中修改了以下几行:

I've just installed Yosemite and I managed to change the DocumentRoot without any problems. First I modified the following lines in /private/etc/apache2/httpd.conf:

DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
Options FollowSymLinks Multiviews

AllowOverride None
</Directory>

收件人:

DocumentRoot "<CUSTOM_PATH>"
<Directory "<CUSTOM_PATH>">
Options Indexes FollowSymLinks Multiviews

AllowOverride All
</Directory>

以上内容将设置自定义DocumentRoot,启用目录列表,并允许配置被.htaccess文件覆盖.

The above will set a custom DocumentRoot, enable directory listing and allow configurations to be overridden by .htaccess files.

然后我通过执行sudo apachectl restart重新启动apache.

Then I restarted apache by executing sudo apachectl restart.

另一种方法是设置虚拟主机.首先确保在/private/etc/apache2/httpd.conf文件中取消注释以下行:

Another approach would be to set up a virtual host. First make sure so that the following line is uncommented in your /private/etc/apache2/httpd.conf file:

# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

然后,您可以在httpd-vhosts.conf文件中添加以下内容:

Then you can add the following in the httpd-vhosts.conf file:

<VirtualHost *:80>
   ServerAdmin webmaster@example.local
   DocumentRoot "/Library/WebServer/Documents"
   ServerName example.local
   ErrorLog "/private/var/log/apache2/example.local-error_log"
   CustomLog "/private/var/log/apache2/example.local-access_log" common

   <Directory "/Library/WebServer/Documents">
     Options Indexes FollowSymLinks Multiviews
     AllowOverride All
     Order allow,deny
     Allow from all
   </Directory>
</VirtualHost>

以上内容将为名为example.local的新虚拟主机设置文档根目录,并启用目录列表,并允许配置被.htaccess文件覆盖.当然,您还需要重新启动apache才能使更改生效:

The above will setup a document root for a new virtual host named example.local and enable directory listing and allow configurations to be overridden by .htaccess files. Of course your also will need to restart apache for the changes to take effect:

sudo apachectl restart

这篇关于更改优胜美地Apache 2.4的本地主机目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆