For
anyone that has been wishing to switch to Apache 2 on their Mac, this
is the time to do it. PHP 5 has also recently been updated to 5.1.3 and
this tutorial describes in detail, the best method to both build and
install these programmes on your Mac.
Since Apple don't
include Apache 2 with OS X yet I have felt it better to keep Apache 2
in its own directory, and to keep PHP for Apache 2, etc. confined the
that directory too.
Step 1: Downloading Apache 2The
first step, as in any build like this, is to download the source and
uncompress it. To do this we open the Terminal and enter the following
commands. FYI: the % represents the Command Line Prompt and should not
be entered
Step 2: Building and Installing Apache 2I've
decided to install to a new directory which we will make /apache2. It's
nice and convenient. To do this enter the following commands (sudo is
required as the directory doesn't already exist):
% cd httpd-2.2.2 % sudo ./configure % --prefix=/apache2 % --enable-module=most % --enable-shared=max % sudo make % sudo make install
Step 3: Building and Installing PHPBuilding
and Installing PHP with Apache 2 is fairly simple. We want to install
it into the same directory as Apache... just for sanity's sake.
The lines marked "Optional" are optional. lib jpeg and png are to
enable jpeg and png support in GD Lib - you will need LibJPEG and
LibPNG installed previously to enable GD. Please note, due to a bug
with PHP, 64bit MySQL will not compile in, revert to 32bit. Also, due
to a different bug, the latest version of MySQL should not be used.
Please revert to an older version.
If you want a PHP.ini file then enter this. It's not required though.
% sudo cp php.ini-dist /apache2/php/lib/php.ini
Step 4: Configuring ApacheThe
next bit is to configure Apache to load PHP files properly. Add it
below the file's current contents. The httpd.conf file is located at
/apache2/conf/httpd.conf. Make sure to use a flat text editor like
BBEdit or Pico in the command line.
Also, You now have a choice. By default your new document root will be
/apache2/htdocs. If you want to change this back to the Apple default
of /Library/WebServer/Documents you need to open the httpd.conf file
(/apache2/conf/httpd.conf) and change the following:
DocumentRoot "/apache2/htdocs"
to
DocumentRoot "/Library/WebServer/Documents"
and
<Directory "/apache2/htdocs">
to
<Directory "/Library/WebServer/Documents">
Similarly, Apache 2 will now point to the UNIX standard user directory.
Which means if you type http://::1/~user/ it will point to the
~/public_html directory in your user folder. In Mac OS X the usual
standard is ~/Sites. If you wish to change this you need to access the
/apache2/conf/extra/httpd-userdir.conf file and change
UserDir public_html
to
UserDir Sites
Step 5: Starting and Stopping Apache 2If
all went well you should now have a working Apache 2 installation.
However, this will not work with the Web Sharing option in System
Preferences. Before you continue, please make sure the option in System
Preferences is set to "Off".
To start Apache 2:
sudo /apache2/bin/apachectl start
To stop Apache 2:
sudo /apache2/bin/apachectl stop
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
<Files ~ "^.([Hh][Tt]|[Dd][Ss]_[Ss])"> Order allow,deny Deny from all Satisfy All </Files>
<Files "rsrc"> Order allow,deny Deny from all Satisfy All </Files> <DirectoryMatch ".*..namedfork"> Order allow,deny Deny from all Satisfy All </DirectoryMatch>
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
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. # #<IfModule !mpm_netware.c> PidFile /private/var/run/httpd.pid #</IfModule>
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.