Apache on Mac OS X
The following is a couple of notes about using the standard Apache
distribution on Mac OS X (as of version 10.5.6).
Useful Links
- Document Root:
/Library/WebServer/Documents
- CGI Scripts:
/Library/WebServer/CGI-Executables
- User Documents:
~/Sites
- Configuration File:
/private/etc/apache2/httpd.conf
- Service Control:
/usr/sbin/apachectl
- Binary:
/usr/sbin/httpd
- Error Log:
/private/var/log/apache2/error_log
- Access Log:
/private/var/log/apache2/access_log
Restarting
If you make changes to the configuration file (noted above),
you will need to restart your web server. While you could turn off
"Web Sharing" in your System Preferences, a better option
is to restart the web server by typing the following command
in the Terminal
application:
sudo apachectl restart
Typical Changes
Most things like server-side includes and CGI scripts are turned on,
but I often like to know details about my server, so I often shove the
following in the configuration file:
#
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
ExtendedStatus On
#
# Allow server status reports, with the URL of http://servername/server-status
# Change the ".your-domain.com" to match your domain to enable.
#
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .local, localhost, 127.0.0.1
</Location>
#
# Allow remote server configuration reports, with the URL of
# http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".your-domain.com" to match your domain to enable.
#
<Location /server-info>
SetHandler server-info
Order deny,allow
Deny from all
Allow from .local
Allow from localhost
Allow from 127.0.0.1
</Location>
If you attempt to go to your personal directory, e.g. http://localhost/~myname
and it returns with a permission denied error, you can fix this by adding
the following entries to your configuration file:
#
# UserDir: The name of the directory which is appended onto a user's home
# directory if a ~user request is received.
#
<IfModule mod_userdir.c>
UserDir Sites
</IfModule>
#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory /Users/*/Sites>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS PROPFIND>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
Getting Version Information
sudo apachectl -V
Will give you all sort of goodies for seeing what options and default
values were specified when Apache was compiled.
Connecting Apache to Tomcat
If you install an app server like Tomcat, Jetty or jBoss, you may want
to have Apache be the front-man for it. The simplest way is to use
the built-in mod_proxy
. For each "web application" you want to
expose, add the following lines to the Apache configuration file:
ProxyPass /myapp http://localhost:8080/myapp
ProxyPassReverse /myapp http://localhost:8080/myapp
<Location /myapp>
Order allow,deny
Allow from all
</Location>
Tell others about this article: