By: James Pelow (jamesnp) Posted: 13-Apr-05, 01:52:52 Rated: General/Experienced
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 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):
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.
Once all that’s done, we will configure and compile PHP.
The lines marked “Optional” are optional. gd, jpeg and png are to enable GD Lib – you will need LibJPEG and LibPNG installed previously. The MySQL line is if you need MySQL. You will need MySQL installed and running.
If you want a PHP.ini file then enter this. It’s not required though.
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
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 Mac OS X the usual standard is ~/Sites. If you wish to change this you need to access the httpd.conf file once again 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:
To stop Apache 2:
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.
Hope all goes well… if, however, you hit a wall or you need help, however trivial please contact support. Click Here. Please not a PHPmac login is required.
Some frequent Issues:
Q: I recieve the following error message while running the Apache configure command:
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 now required by PHP. 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. Most people should have this, it was included in an Apple Security update a while back. However, many people have been encountering this problem so I have added directions here.
First step is to download the source then Untar it. We will make a directory to do this:
We are now in the libxml2-2.6.7 source directory. From here it’s a simple compile and install.
libXML2 is now installed. Go Back and try configure PHP again, with the line –with-libxml-dir=/usr/local in your PHP configuration command.