The Web Sharing feature is a useful way of testing out simple sites and applications using the built-in Apache server in OS X. Although I don’t recommend using it for complex projects (I recommend Vagrant for those cases), it’s still a useful thing to have.
After upgrading from from Mavericks to Yosemite, the built in web server no longer was configured to serve content from /Users/(username)/Sites. Here are some brief instructions on getting it back up and running:
First, it’s worth noting that Yosemite is now using Apache 2.4 rather than 2.2, which was included in Mavericks. This has an effect on some authorisation settings, which you will see below.
As an administrator, load the following file in an editor:
/etc/apache2/extra/httpd-userdir.conf
Uncomment the following line:
Include /private/etc/apache2/users/*.conf
Edit the following file
/etc/apache2/httpd.conf
Uncomment the following lines:
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule php5_module libexec/apache2/libphp5.so
Include /private/etc/apache2/extra/httpd-userdir.conf
Edit your user configuration under /etc/apache2/users/username.conf
Change any instances of:
Order allow,deny
Allow from all
to
Require all granted
(this was one of the major changes between Apache 2.2 and 2.4 — see more details here http://httpd.apache.org/docs/2.4/upgrading.html)
Re-instate your previous PHP configuration:
sudo mv /etc/php.ini-5.2-previous /etc/php.ini
If you want to have Apache startup automatically when you Mac boots, enter the following:
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Finally, start Apache:
sudo apachectl start
If all goes well, you’ll see a message similar to this logged in /var/logs/apache2/error_log
:
[Mon Oct 20 07:26:42.063040 2014] [mpm_prefork:notice] [pid 4412] AH00163: Apache/2.4.9 (Unix) PHP/5.5.14 configured -- resuming normal operations
You should also now be able to access your shared files in your browser via http://localhost/~username/
Any questions? Please use the comments section below!
P.S. – Looking for reliable hosting for your PHP projects? I recommend Clook: