Computers/Apple
Building and Installing Apache 2.2.2 and PHP 5.1.4 on Mac OS X 10.4.6
Dr.TeKtOn
2006. 7. 28. 15:56
http://www.phpmac.com/articles.php?view=252
http://www.phpmac.com/articles.php?view=214
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 2: Building and Installing Apache 2
I'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):
Step 3: Building and Installing PHP
Building
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.
If you want a PHP.ini file then enter this. It's not required though.
Step 4: Configuring Apache
The
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.
Step 5: Starting and Stopping Apache 2
If
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:
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:
.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 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
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.
http://www.phpmac.com/articles.php?view=214
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
% curl -O http://apache.mirrors.esat.net/httpd/httpd-2.2.2.tar.gz
% gnutar -xzf httpd-2.2.2.tar.gz
Step 2: Building and Installing Apache 2

% 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 PHP

Once all that's done, we will configure and compile PHP (Remember % represents the prompt, it should not be entered).% curl -O http://ie2.php.net/distributions/php-5.1.4.tar.gz
% gnutar -xzf php-5.1.4.tar.gz
% cd php-5.1.4
% sudo mkdir /apache2/php
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.% ./configure
% --prefix=/apache2/php
% --with-zlib
% --with-xml
% --with-ldap=/usr
% --enable-cli
% --with-zlib-dir=/usr
% --enable-exif
% --enable-ftp
% --enable-mbstring
% --enable-mbregex
% --enable-dbx
% --enable-sockets
% --with-iodbc=/usr
% --with-curl=/usr
% --with-mysql=/usr/local/mysql (optional, required MySQL)
% --with-gd (optional, requires jpeg + png)
% --with-jpeg-dir=/usr/local (optional)
% --with-png-dir=/usr/local (optional)
% --with-apxs2=/apache2/bin/apxs
% sudo make
% sudo make install
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 Apache

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:AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php
toDocumentRoot "/apache2/htdocs"
andDocumentRoot "/Library/WebServer/Documents"
to<Directory "/apache2/htdocs">
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<Directory "/Library/WebServer/Documents">
toUserDir public_html
UserDir Sites
Step 5: Starting and Stopping Apache 2

To start Apache 2:
To stop Apache 2:sudo /apache2/bin/apachectl start
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.sudo /apache2/bin/apachectl stop
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:
and change to:User nobody
Group nobody
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
and replacing the uncommented Files directive below it with the following three directives# The following lines prevent .htaccess files from being viewed by
<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
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
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.#
# 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>
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.
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.cd /usr/sbin/;
mv apachectl apachectl-1.3;
ln -s /apache2/bin/apachectl apachectl;