Setting up Per-user web directories for Apache in macOS High Sierra

In this article we will see how to setup per-user web directories in macOS High Sierra. Once per-user web directory is configured for Apache web server, each user can setup a local website in their home directories and it can be accessed via the url http://localhost/~username

1. Backup configuration files
In order to configure the per-user web directories, we need to edit two apache files namely httpd.conf httpd-userdir.conf. Before editing these files, initially let us create a copy of the files. For this, issue the given below commands in terminal.

1. sudo $cp /private/etc/apache2/httpd.conf /private/etc/apache2/httpd.conf.bak
2. sudo $cp /private/etc/apache2/extra/httpd-userdir.conf  /private/etc/apache2/extra/httpd-userdir.conf.bak

2. Open the file /private/etc/apache2/httpd.conf

Uncomment the given below lines and save

LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf

2. Open the file /private/etc/apache2/extra/httpd-userdir.conf

Uncomment the given below lines and save

UserDir Sites
Include /private/etc/apache2/users/*.conf

3. Add the file username.conf into the directory /private/etc/apache2/users, if not exists

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

4. Create a directory called Sites in the home directory, if not exists

$mkdir Sites

5. Create a file called index.html in the Sites directory, if not exists

<html>
<body>
Welcome
</body>
</html>

6. Restart Apache Web Service

sudo apachectl restart

7. Access the site

Now we can access the site at the url http://localhost/~username via an internet browser. Replace username with the user name of the login user. If username is not known, then issue the command whoami in a terminal window to get the username.

Comments on this post

No comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

Trackbacks and Pinbacks on this post

No trackbacks.

TrackBack URL