macOS Apache – How to Set Up Document Root as ‘Sites’ Folder

apachemacoswebserver

I have an index.html in my /Users/igor/Sites/MySite folder (igor is my username on Mac). Links (for example: <a href="/page">Page</a>) all go to localhost/page instead of http://localhost/~igor/MySite/page. http://localhost reports It works!, in http://localhost/~igor/ I see all my files and folders.

My /private/etc/apache2/users/igor.conf file:

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

My /private/etc/apache2/extra/httpd-userdir.conf file (without comments):

UserDir Sites  
Include /private/etc/apache2/users/*.conf
<IfModule bonjour_module>
       RegisterUserSite customized-users
</IfModule>  

Also I uncommented lines in httpd.conf as described here.

Some lines from my httpd.conf:

User _www
Group _www


 <Directory />
    AllowOverride none
    Require all denied
</Directory>  



<Directory "/Library/WebServer/Documents">
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any

    AllowOverride None

    Require all granted
</Directory>

httpd -V output:

Server version: Apache/2.4.23 (Unix)
Server built:   Aug  8 2016 16:31:34
Server's Module Magic Number: 20120211:61
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

How to fix links so they correspond to Sites/MySite/MyLink and not localhost/MyLink? Thanks.

Update: httpd -t -D DUMP_RUN_CFG returns:

[Thu Oct 13 16:55:24.277291 2016] [so:warn] [pid 46810] AH01574: module php5_module is already loaded, skipping
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist
ServerRoot: "/usr"
Main DocumentRoot: "/Library/WebServer/Documents"
Main ErrorLog: "/private/var/log/apache2/error_log"
Mutex default: dir="/private/var/run/" mechanism=default 
Mutex mpm-accept: using_defaults
PidFile: "/private/var/run/httpd.pid"
Define: DUMP_RUN_CFG
User: name="_www" id=70 not_used
Group: name="_www" id=70 not_used  

Best Answer

You have to set the DocumentRoot directive in your httpd.conf. First, using your favorite editor, search for the DocumentRoot directive and add the following:

 DocumentRoot "/Users/igor/Sites/MySite/MyLink"

Restart Apache so that it reads the updated directive from httpd.conf