Additional Useful Apache2 Config Settings

Warning: This article/tutorial is more the 45 days old. As such the information contained within could be, by now, out of date. Please read all information to make sure that this article/tutorial will work with your current version of the Operating System

After completing your install of apache2 as per the phpmac.com tutorial, here’s a couple of additional tips to help make it as Mac-compatible as possible.

These edits all take place in your apache2 config file, most likely located in /apache2/conf/httpd.conf.

Default User
The default user for OS X should be www instead of nobody. Search for:

User nobody
Group nobody

and change to:

User www
Group www

.htaccess Security Settings per Apple
Apple now has a rather longer .htaccess denial section (as of the 12-02-04 Security Update). You can duplicate it by searching for the line

# The following lines prevent .htaccess files from being viewed by

and replacing the uncommented Files directive below it with the following three directives


Order allow,deny
Deny from all
Satisfy All


Order allow,deny
Deny from all
Satisfy All


Order allow,deny
Deny from all
Satisfy All

The cgi-bin Directory
Additionally, if you’re planning to keep using the /Library/WebServer folder, don’t forget to change your cgi-bin folder settings. Search for the ScriptAlias line and make it look like this

ScriptAlias /cgi-bin/ “/Library/WebServer/CGI-Executables/”

Using the System Prefs Sharing Panel to Control Apache2
Finally, if you want to be able to use your System Preferences Sharing pane to start and stop your apache2 install, there are a couple of things to do. First is to find the PidFile section and make it look like this

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
#
#
PidFile /private/var/run/httpd.pid
#

Note that not only has the PidFile path been changed to be in the /private/var/run folder, but also, the IfModule lines have been commented out.

At this point, all necessary modifications have been made to the apache2 conf file–we just need to link up the apachectl for apache2 to replace the one that is installed by default by Apple. So save your httpd.conf file and in Terminal do the following.

cd /usr/sbin/;
mv apachectl apachectl-1.3;
ln -s /apache2/bin/apachectl apachectl;

Basically, this renames the old Apple apachectl to be apachectl-1.3 (and you can even start and stop the original Apple apachectl by using that command). Then it makes a symbolic link from our apache2 folder into the /usr/sbin folder. Now when you start and stop Web Sharing from the System Preferences panel, you should be starting and stopping apache2.

This last tip was gleaned from MacOSXHints.com, by the way.

Hope these tips helps others!

Setting up mod_gzip in Apache

Warning: This article/tutorial is more the 45 days old. As such the information contained within could be, by now, out of date. Please read all information to make sure that this article/tutorial will work with your current version of the Operating System

FYI In response to feedback from “jeanloui”, several changes have been made to this article.

Overview:
The mod_gzip module for Apache will compress the pages as it sends them. Of course, it will only do this if the browser that your audience is using is compatible. Before you do this tutorial, run your website through PipeBoost to see how fast it currently is.

Installation:

1. Download the latest version of mod_gzip from SourceForge.

2. De-compress it.

3. Using TextEdit, or your favourite editor, make the following changes to the Makefile in the folder.
Change:

APXS?=/usr/local/sbin/apxs

To:

APXS?=/usr/sbin/apxs

Change:

$(APXS) -Wc,-Wall,-O3,-fomit-frame-pointer,-pipe -c mod_gzip.c mod_gzip_debug.c mod_gzip_compress.c -o mod_gzip.so

To:

$(APXS) -Wc,-Wall,-O3,-fomit-frame-pointer,-pipe -c mod_gzip.c mod_gzip_debug.c mod_gzip_compress.c

4. Save the file.

5. Run “make” in the Terminal in the directory.

6. Run “sudo make install”, entering your password when requested.

7. Run “sudo pico /etc/httpd/httpd.conf”

8. Uncomment, that is remove the # from the front of (if it is not already done), these lines:

LoadModule gzip_module libexec/httpd/mod_gzip.so
AddModule mod_gzip.c
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz

9. Still in pico, add these lines to the end of the file:


mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_static_suffix .gz
AddEncoding gzip .gz
mod_gzip_update_static No
mod_gzip_command_version ‘/mod_gzip_status’
mod_gzip_temp_dir /var/mod_gzip_temp_dir
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 500
mod_gzip_maximum_file_size 500000
mod_gzip_maximum_inmem_size 60000
mod_gzip_min_http 1000
mod_gzip_handle_methods GET POST
mod_gzip_item_exclude reqheader “User-agent: Mozilla/4.0[678]”
mod_gzip_item_include file .html$
mod_gzip_item_include file .shtml$
mod_gzip_item_include file .htm$
mod_gzip_item_include file .shtm$
mod_gzip_item_include file .php$
mod_gzip_item_include file .phtml$
mod_gzip_item_exclude file .js$
mod_gzip_item_exclude file .css$
mod_gzip_item_include file .pl$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include mime ^text/plain$
mod_gzip_item_include mime ^httpd/unix-directory$
mod_gzip_item_exclude mime ^image/
mod_gzip_dechunk Yes
mod_gzip_add_header_count Yes
mod_gzip_send_vary Yes

10. Save the file with Control-O.

11. Run “cd /etc”. Then “ls php*” to see if there is a file called “php.ini”. If there is only “php.ini.default” then run “sudo cp php.ini.default php.ini”.

12. Run “sudo pico php.ini”. Look for:
Change:

zlib.output_compression = On

To:

zlib.output_compression = On
zlib.output_compression_level=5

13. Save the file with Control-O.

14. Restart Apache with “sudo apachectl restart”

15. Test your website again with PipeBoost and notice the difference!

Credit for this article is due to to Christoper Holland at Exordium

John Lunney marked-up and made slight changes to it.