Configure Apache for PHP in OS X / macOS
- Comments:
- 57
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.
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
$ sudo apachectl restart
open a browser and test it out.
Comment by: Simon on
Comment by: Reyescult on
http://www.456bereastreet.com/archive/201104/apache_with_virtual_hosts_php_and_ssi_on_mac_os_x_106/
Comment by: Jesse G. Donat on
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
Regards
Comment by: John on
Comment by: Devlix on
Comment by: Freya on
Comment by: Roy on
Comment by: Jeff on
Comment by: Fortyhands on
Comment by: Drew on
Comment by: Denis Karanja on
Comment by: Mark on
Comment by: Peter on
I've been battling this for hours. If you have any suggestions, I'd really appreciate it. Thanks
Comment by: Kees de Kooter on
Comment by: Abubakar Saddique on
Forbidden
You don't have permission to access / on this server.
Comment by: Huiyu Lee on
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
Comment by: Joshua Pinter on
Comment by: Kam on
Comment by: zhoulujun on
http://www.zhoulujun.cn/zhoulujun/index.php?m=content&c=index&a=show&catid=186&id=7855
Comment by: Alla on
Comment by: Jenoah on
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
Comment by: Mekaeil on
my OS is MAC OS Sierra version 10.12.4
I did step by step your article... but when i want to create the folder in Sites folder it 's redirected to XAMPP dashboard !
and when Uncomment the line :
( /Applications/XAMPP/xamppfiles/etc/httpd.conf )
#Include etc/extra/httpd-vhosts.conf
when Uncommented , the Sites folder worked but the localhost Access forbiden 403!
Comment by: ALEXEI ZOUBOV on
Forbidden
You don't have permission to access /~alexeiz on this server.
I've searched and tried all recommender solutions for hours - the result is still the same.
I have a fresh install of El Capitan on a separate bootable disk
Comment by: tim on
One issue I was having was syntax issues. Somewhere things got broken.
Tip: "Check Apaches syntax", in my case, I had a few issues in some files.
sudo apachectl configtest
It's best to start over with a fresh default httpd.conf or httpd-vhosts.conf file. Get a clean copy from the originals directory... /etc/apache2/original
Comment by: John Clarke Au on
This worked fine for Mojave, except I have to use PHP7 instead of PHP5.
Comment by: Juan Andrade on
Comment by: Francisco on
Have no idea what's wrong, I have MacOS Mojave 10.14.4.
When I go to http://localhost I keep seeing "Apache!! It works!"
Comment by: Antoine on
You did such an amazing tutorial. You're a star :D
Everything worked properly for me on Mojave.
Comment by: Stevik on
I will continue looking at documentation to figure this out as I am building a site and this is quite frustrating lol...I am from the electrical engineering degree and have not been coding for a while. So be patient if you choose to answer me.
Cheers! Good Tutorial.