Space Cat, Prince Among Thieves

Configure Apache for PHP in OS X 10.10 Yosemite / 10.11 El Capitan

Every time I would upgrade OS X it took probably 45 minutes of fiddling with my Apache configuration to get it working properly. I'm writing this article in the hopes of saving myself and others some time.

These instructions have been tested in OS X 10.10 Yosemite and OS X 10.11 El Capitan

The Setup

For the following examples, {username} represents your username.

Firstly, if you don't already have a Sites folder, create one in your home directory.

mkdir ~/Sites

Create or update /etc/apache2/users/{username}.conf to look as follows:

<Directory "/Users/{username}/Sites/">
    Options Indexes MultiViews FollowSymLinks
    Require all granted
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Add your virtual hosts if you don't already have them to /etc/apache2/extra/httpd-vhosts.conf

ala:

<VirtualHost *:80>
  ServerName localhost
  DocumentRoot /Users/{username}/Sites/
</VirtualHost>

Configuration

/etc/apache2/httpd.conf

Search for and uncomment the following lines:

LoadModule deflate_module libexec/apache2/mod_deflate.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

Include /private/etc/apache2/extra/httpd-userdir.conf
Include /private/etc/apache2/extra/httpd-vhosts.conf

Then around line 271 add index.php to the DirectoryIndex

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

/etc/apache2/extra/httpd-userdir.conf

Uncomment the following line:

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

Almost Done

Restart apache with sudo apachectl restart, open a browser and test it out.


Comment by: Simon on

Simon GravatarThank you for taking time to share this with everyone. Saved me a lot of time :-)

Comment by: Dan on

Dan GravatarNice work - Thanks!

Comment by: Nu on

Nu GravatarThanks for posting these instructions, it's really helpful.

Comment by: Reyescult on

Reyescult GravatarThis is awesome, thanks! Can you offer any insight as to getting SSI (.shtml) working? Previously to Yosemite, I was using the following guide:

http://www.456bereastreet.com/archive/201104/apache_with_virtual_hosts_php_and_ssi_on_mac_os_x_106/

Comment by: Jesse Donat on

Jesse Donat Gravatar

There are two lines commented out as follows in /etc/apache2/httpd.conf, uncommenting them should do the trick!

    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml

Comment by: Dmas on

Dmas GravatarHi, why mi apache directory is this: /usr/local/Cellar/apache24/2.4.4/ ? i have osx yosemite and i can't add php module.

Regards

Comment by: John on

John GravatarHi, great work. Thank you. I had issues having upgraded to Yosemite and this is the only guide I found that actually solved the issue.

Comment by: Daniel on

Daniel GravatarYou are an angel, thank you!

Comment by: Radu on

Radu GravatarThank you man! Works like a charm.

Comment by: Devlix on

Devlix GravatarMan, after 2 hours of rage and fury, this post extended my mac's lifetime :D Thanks for sharing this!

Comment by: Freya on

Freya GravatarI keep getting this error: You don't have permission to access / on this server. Did everything what you told ...

Comment by: alBz69 on

alBz69 GravatarThank you very much! sweety guide, dude ^_^ All works for me.

Comment by: Roy on

Roy GravatarGreat job, saved my a lot of time! Best tutorial I've seen. I'd like to add the following for people who are not super handy with the Terminal app (like me). Use "sudo nano" before every path to open and edit the files.

Comment by: Jeff on

Jeff GravatarThanks! I wish your post came up first on Google. It would have saved me even more time.

Comment by: Fortyhands on

Fortyhands GravatarThis is probably the fifth article I've looked at regarding setting up Apache in Yosemite - and the only one that actually worked flawlessly. Thanks for your awesomeness.

Comment by: Drew on

Drew GravatarI figured it would be some work after upgrading to Yosemite but couldn't figure out what had happened to my previous set up. I followed two other tutorials and yours was the only one that worked. Totally saved my sanity.

Comment by: Denis Karanja on

Denis Karanja GravatarThank you so much man!! I have been struggling with this for two weeks now. Thanks man!!

Comment by: Mark on

  • Fixed
Mark GravatarGreat tutorial. Worked perfectly. Only thing I noticed in your instructions you have a typo /Users/{userbane}/Sites/ I thought that was some special system setting until I realized it was {username}

Comment by: KM on

KM GravatarAm able to configure Apache on yosemite successfully. Thank you

Comment by: Mieke on

Mieke GravatarThanks for the quick and easy tutorial. Great

Comment by: Jeff on

Jeff Gravatarthanks, this is really helpful specially for newbies to apache like me...

Comment by: Peter on

Peter GravatarThanks for the tutorial. One quick question. I have a java war file that I'd like to deploy to apache. I'm not sure how to go about doing this on OS X. On windows, I had the Manager GUI and would upload the war file and click deploy. It was pretty easy (I'm a little disappointed as a new Mac convert to find out how much easier it is to deploy a war file to Tomcat).

I've been battling this for hours. If you have any suggestions, I'd really appreciate it. Thanks

Comment by: barfo on

barfo GravatarRemember to comment out Require all denied in httpd.conf

Comment by: Anhduc.bkhn on

Anhduc.bkhn GravatarThanks you!

Nice post

Comment by: mark on

mark GravatarThanks man! You saved me a lot of work!

Comment by: Kees de Kooter on

Kees de Kooter GravatarPlease note that the Apache version on El Capitan is 2.4 and note these configuration changes: https://httpd.apache.org/docs/2.4/upgrading.html

Comment by: Derek on

Derek GravatarYou are a legend

Comment by: Abubakar Saddique on

Abubakar Saddique GravatarI have followed the every step but still having following error in browser while access localhost.


Forbidden

You don't have permission to access / on this server.

Comment by: Tibo on

Tibo GravatarThanks a lot – worked like a charm!!

Comment by: dd on

dd GravatarI've tried everything still can't get Permalinks in Wordpress to work properly...

Comment by: Nahid on

Nahid GravatarThank you. You just save my lots of time :)

Comment by: Huiyu Lee on

Huiyu Lee GravatarHey, have you also encountered this problem: http://stackoverflow.com/questions/33532949/el-capitan-unable-to-connect-to-localhost-server-via-external-device-in-lan
this is the one that I cannot figure out till now.
I do the above things as you did. and I use my mobile phone( which is connected to the same local area network as my web server) and open the browser as the link http://ip but nothing returned.

Comment by: Jesse G. Donat on

Jesse G. Donat GravatarHave you tried turning your firewall off to see if that's the issue? Otherwise you may need to change something in your apache config to accept outgoing connections.

Comment by: Ben on

Ben GravatarThanks!! Got my virtual host working!

Comment by: A on

A GravatarThank you!

Comment by: Tom on

Tom GravatarThanks. Great help.

Comment by: Philbert on

Philbert GravatarThank you! :-)

Comment by: Tony on

Tony GravatarWas dreading updating to 10.11
This made it so easy.

Thanks!

Comment by: Joshua Pinter on

Joshua Pinter GravatarAwesome, thanks man! Clear and concise. And most importantly, worked like a charm! :)

Comment by: Kam on

Kam GravatarFor some reason I can't access plain localhost when I use this. I get a "Forbidden" message. But now it's serving the file from my Sites directory so I'm happy.

Comment by: Rufus on

Rufus GravatarYou are awesome :)
Very helpful article
it solved my problem
Thank you.

Comment by: Max on

Max GravatarExcelente tutorial!

Comment by: zhoulujun on

zhoulujun Gravatarwo copy it ^^
http://www.zhoulujun.cn/zhoulujun/index.php?m=content&c=index&a=show&catid=186&id=7855

Comment by: Ondrej on

Ondrej GravatarYou're the man. Cheers.

Comment by: Alla on

Alla GravatarHello! I am very thankful to you for this article! It saved me. I am just learning, and after more than a week of struggling with setting up AMP on my Mac OS 10.7.5, I have finally decided to upgrade to El Capitan in hope that AMP will not cause any trouble. I did so yesterday, and it took me hours before I have finally found your article that has helped me, and apache finally runs. Thank you!

Comment by: seung-kil on

seung-kil GravatarThank you! It solved my problem !

Comment by: Jose on

Jose GravatarThanks!!! It works perfect :)

Comment by: Jenoah on

Jenoah GravatarThanks!
It worked for me.
I just couldn't find a tutorial on Google on how to fix the permission issue, but now I have found one!
Thanks :)

Comment by: Jakob on

Jakob GravatarThank you Man i searched for this for about 2 Days!! Good Tutorial! Recommended!

Email address will never be publicly visible.