Map "Sites" folder to http://localhost on OS X
Solution 1
You want to change the "DocumentRoot" setting in the file /etc/apache2/httpd.conf, and restart web sharing.
Solution 2
Go to /etc/apache2/httpd.conf
Find
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
Change it to:
DocumentRoot "/Users/bob/Sites"
<Directory "/Users/bob/Sites">
Where bob
is your username. Now you can access localhost/mywebsite
instead of localhost/~bob/mywebsite
You might need to restart apache sudo apachectl restart
Solution 3
I have also just changed DocumentRoot in /etc/apache2/httpd.conf
. But another option is to use vhosts:
- Uncomment
Include /private/etc/apache2/extra/httpd-vhosts.conf
in/etc/apache2/httpd.conf
Add this to
/etc/apache2/users/username.conf
or/etc/apache2/extra/httpd-vhosts.conf
:<VirtualHost *:80> DocumentRoot "/Users/username/Sites" ServerName localhost </VirtualHost>
sudo apachectl restart
If you get an error like You don't have permission to access / on this server
, try adding this to /etc/apache2/users/username.conf
:
<Directory "/Users/username/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Related videos on Youtube
Sindre Sorhus
Updated on September 17, 2022Comments
-
Sindre Sorhus almost 2 years
I'm using the built-in server on my Mac.
The URL to my Sites folder is:
http://localhost/~username/
with MAMP I had just
http://localhost/
.Is there any way to get just
http://localhost/
with the built-in server?I have only one user account on my Mac.
-
Admin over 5 yearsI am using the localhost/~username. Is there a way to access it with the IP address. Currently when i access it with IP adress, I get Forbidden You don't have permission to access /~username/ on this server.
-
-
Sindre Sorhus almost 15 yearsI want to have the files in the Sites folder, can I create an hardlink/symlink or something?
-
Christian Studer almost 15 yearsYes, you can. But do it in the Terminal, the Finder doesn't really create real hard/symlinks.