Re-enable Apache & PHP Web Sharing on OS X Yosemite

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:

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

13 thoughts on “Re-enable Apache & PHP Web Sharing on OS X Yosemite

  1. Maria C

    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.

    Reply
    1. Glen Scott Post author

      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

      Reply
    1. Glen Scott Post author

      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

      Reply
  2. Wojciech

    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?

    Reply
    1. Glen Scott Post author

      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.

      Reply
    1. Glen Scott Post author

      Not essential — you would only have this if you have upgraded from an older version of Mac OS X.

      Reply
  3. Mark

    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.

    Reply
  4. Mark Meyer

    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.

    Reply

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.