|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|
|Usual stuff… Full Developers’ Tool installation is required as well as up to date system. At this time it means Mac OS X 10.4.6 for PPC or INTEL WITH ALL latest Security Updates. Special Note for Intel Macs: Please make sure you install the developers’ tools that came with your mac, do not use old PPC developers’ tools. Mac OS X Server is not supported|
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.oss-mirror.org/httpd/httpd-2.2.4.tar.gz
% gnutar -xzf httpd-2.2.4.tar.gz
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.4
% sudo ./configure \
% –prefix=/apache2 \
% –enable-module=most \
% 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.
|% 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
Once all that’s done, we will configure and compile PHP (Remember % represents the prompt, it should not be entered).
|% ./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)
% sudo make
% sudo make install
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.
|AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php
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:
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
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|
You will need to switch this on everytime your restart your Mac. Or, you can use another PHPmac tutorial to enable Apache 2 as the default OS X server. Additional Useful Apache2 Config Settings. This tutorial also contains important settings to secure your server, all are recommended to follow this
Hope all goes well… if, however, you hit a wall or you need help, however trivial, please contact support. Click Here. Please note; a PHPmac login is required.
Some frequent Issues:
Q: I receive the following error message while running the Apache configure command:
|Creating Makefile in src
+ configured for Darwin platform
Error: could not find any of these C compilers
anywhere in your PATH: gcc cc acc c89
A: You need to install the Apple supplied Developers’ Tools. These come on a CD in your Mac OS X box or in the Applications folder if you’ve just bought your Mac recently
Q: I received an error message regarding the absence of LibXML2
A: Building and Installing libXML2 (Required for PHP 5)
libXML2 is required by PHP. It comes bundled in Tiger and if you met the requirements of the article then you shouldn’t have this problem. The building of libXML2 is releativly simple, but it takes for ever and a day to compile. So be prepared to go and make yourself a coffee and maybe dinner.
First step is to download the source then Untar it. We will make a directory to do this:
|% cd ~/Desktop
% mkdir libxml2build
% cd libxml2build
% curl -O ftp://gd.tuwien.ac.at:21//pub/libxml/libxml2-2.6.22.tar.gz
% gnutar -xzf libxml2-2.6.22.tar.gz
% cd libxml2-2.6.22
We are now in the libxml2-2.6.22 source directory. From here it’s a simple compile and install.
% sudo make install
% sudo ranlib /usr/local/lib/libxml2.a
libXML2 is now installed. Go Back and try configure PHP again, with the line –with-libxml-dir=/usr/local in your PHP configuration command.