11

Mac OS X ships with apache pre-installed, but the files are in non-standard locations. This question is a place to collect information about where configuration files live, and how to tweak the apache installation to do things like serve php pages.

5 Answers 5

20

Apache Config file is: /private/etc/apache2/httpd.conf

Default DocumentRoot is: /Library/Webserver/Documents/

To enable PHP, at around line 114 (maybe) in the /private/etc/apache2/httpd.conf file is the following line:

#LoadModule php5_module     libexec/apache2/libphp5.so

Remove the pound sign to uncomment the line so now it looks like this:

LoadModule php5_module     libexec/apache2/libphp5.so

Restart Apache: System Preferences -> Sharing -> Un-check "Web Sharing" and re-check it. OR

$ sudo apachectl restart
3
  • Though this answer is old, the information is still true for OS X Yosemite. Dec 8, 2015 at 18:43
  • 1
    Applies to El Capitan too (OSX 10.11) Dec 9, 2015 at 1:58
  • System Preferences -> Sharing -> Web Sharing seems to be gone on OSX High Sierra
    – commonpike
    Oct 24, 2019 at 11:46
11

Running

$ httpd -V

will show you lots of useful server information, including where the httpd.conf file can be found.

2

To get SSI/includes (mod_include) to work I found I had to edit /private/etc/apache2/users/myusername.conf and change AllowOverride None to AllowOverride All.

Then add the following in a .htaccess file in the root of your site:

Options +Includes
AddType text/html .html
AddOutputFilter INCLUDES .html
2
  • This seems to be in /Library/Server/Web/Config/apache2/httpd_server_app.conf as of 10.8. it says "Filters allow you to process content before it is sent to the client... To parse .shtml files for server-side includes (SSI): (You will also need to add "Includes" to the "Options" directive.)" They add the directive as AddType text/html .shtml \ AddOutputFilter INCLUDES .shtml, but probably just out of being paranoid. What I don't understand is where do I "tell apache" where MY particular .shtml IS?
    – Alex Gray
    Mar 2, 2013 at 8:33
  • @alexgray If I'm not mistaken that path is on OSX Server and the path that I gave is for OSX (desktop). Mar 4, 2013 at 4:22
1

httpd.conf is in /private/etc/apache2

Enable PHP by uncommenting line:

 LoadModule php5_module        libexec/apache2/libphp5.so
1

/etc/httpd/users contains user-specific configuration files which can be used to override the global configuration. For example, adding "AddHandler server-parsed html" to the <Directory> block in the /etc/httpd/users/*.conf file that corresponds to one user will enable mod_include parsing of HTML files for that particular user's $HOME/Sites directory, but nowhere else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.