简体   繁体   中英

Change localhost directory for Yosemite 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.

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

EDIT (thanks to Krister Andersson for the answer)

For Mac OSX 10.10 Yosemite

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

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

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

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>

Dont forgive to change the myUsername value.

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

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"

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

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

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>

to:

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

AllowOverride All
</Directory>

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

Then I restarted apache by executing sudo apachectl restart .

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

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>

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

在El Capitan上你应该用“-k”标志重新启动apache:sudo apachectl -k restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM