Home

Enabling apache web server on OS X Sierra (10.12)

Assuming apache has never been installed on the mac before (i.e. with a prior version of the system)

Open the terminal application from /Applications/Utilities/Terminal

(Note: your system prompts may be different - they are not part of what you type into the Terminal as a command - for simplicity I will use "$" below - yours will likely be your user name)

Determine certain field values to be substituted in the instructions below.

To determine your login user name per osx, in Terminal, type:

$ whoami

This should be used where ever yourusername appears in these instructions

To determine your login group name per osx, in Terminal, type:

$ cd /Users

then type

$ ls -lag

Look as the line that ends with yourusername, then find the group name in the 2nd column

(ex. it may be "staff")

This value will be used where ever yourgroupname appears in these instructions

Now setup apache web server files

Change to the apache2 directory

$ cd /etc/apache2/

Backup the current httpd.conf file

$ sudo cp httpd.conf httpd.conf~previous

(Note: you can make the target name anything you want, esp. if you already have an existing ...~pervious named filed)

Edit httpd.conf

$ sudo vi httpd.conf

Change the line:

#LoadModule php5_module libexec/apache2/libphp5.so

to

LoadModule php5_module libexec/apache2/libphp5.so

Change the line:

DocumentRoot "/Library/WebServer/Documents"

to

#DocumentRoot "/Library/WebServer/Documents"
DocumentRoot "/Users/yourusername/Sites"

Change the line:

<Directory "/Library/WebServer/Documents">

to

#<Directory "/Library/WebServer/Documents">
<Directory "/Users/yourusername/Sites">

Change the line:

User _www

to

User yourusername

Change the line:

Group _www

to

Group yourgroupname

Save and quit vi (type ESC, then :, then wq)

Create the file: /etc/apache2/users/yourusername.conf

$ sudo vi yourusername.conf

Then add the following content:

<Directory "/Users/yourusername/Sites/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
Require all granted
</Directory>

Save and quit vi (type ESC, then :, then wq)

Change the privileges on your new file

$ sudo chown root:wheel /etc/apache2/users/yourusername.conf

In /etc/apache2/extra/httpd-userdir.conf add line to enable UserDir:

Make a backup of the httpd-userdir.conf file

$ sudo cp /etc/apache2/extra/httpd-userdir.conf /etc/apache2/extra/httpd-userdir~previous.conf

Edit the httpd-userdir.conf file

$ sudo vi /etc/apache2/extra/httpd-userdir.conf

Add this line (I put it just before the line that says "UserDir Sites")

UserDir enabled

Save and quit vi (type ESC, then :, then wq)

Restart the apache server

$ sudo apachectl stop

$ sudo apachectl start

To see if there are any errors, you may want to examine the tail end of the system log file

$ tail /var/log/system.log

$ sudo apachectl configtest