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:
Hi, I’ve tried to enter /etc/apache2/extra/httpd-userdir.conf into my terminal application and it says “access denied” not quite sure where to go from here.
Thanks, this was helpful. But how to I configure the Mac to automatically start the web server with every reboot?
Make sure Apache is not running and then enter the following in your Terminal:
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
I have the same problem in terminal. It says permission denied
Hi,
You need to open the /etc/apache2/extra/httpd-userdir.conf file in a text editor such as Sublime Text — it’s not an executable command.
Glen
Hi,
some time ago there was an option in OS X that I could share my web site by IP, so I could access my site from another device. It worked like a server, not only locally. This option is no longer available in System Preferences in Yosemite but maybe is there any way to fix it?
You can still access your website via an IP address. Just go into the Network preference pane and look for the IP address assigned to your machine. If you are connected via Wifi, for example, it will say “Wi-Fi is connected to XXX and has the IP address XXX.XXX.XXX.XXX” Use that IP address to access your website from other devices on your local network.
Worked perfectly. Even restored my vhosts!
Thank you for this invaluable service.
I don’t have any `/etc/php.ini-5.2-previous`
Not essential — you would only have this if you have upgraded from an older version of Mac OS X.
I’d like my Yosemite server to “Automatically create” the Sites folder for all the users I create.
Is that at all possible? Basically so that all users have a website folder that is live on that server.
I can’t do that one at a time.
I would also like to have the “Sites” folder be created with user creation. That would make things work without having to edit all 1200 users individually.
Great Post! Thank you very much.