- Version: 1.04
- Revised: 06-JAN-2005
- Disclaimer: If you break your computer it’s not my fault!
- If you find this useful or find errors, let me know!
This guide (hopefully) will tell you about how to set up a PHP4/php-cgiwrap/MySQL testing server using Mac OSX (10.3.x) based on pair Networks (http://pair.com) FreeBSD server configuration. Of course these notes could be used to set up a testing server for use with another host, just omit pair specific parts. I originally did this using FreeBSD 4.8, then again with Gentoo Linux, and then changed a few things to get it working in OS X. I’ll venture to say this setup would be impossible using any version of Windows, due to path configuration and cgiwrap (PHP, Apache, MySQL no problem). Hopefully I have not forgotten any major steps, but if I have let me know.
For this OS X setup I used the included Apache installation after getting mod_ssl running and configured. SSL is not necessary to continue, but my goal was a very close replica of my pair server, and I have/use SSL. To set up SSL follow this link:
Table of contents:
- Make some directories and set permissions
- Install MySQL server
- Compile and install PHP Apache module
- Make a virtual directory for your user
- Check to see if it’s working so far
- Compile and install your own cgi version of PHP
- Compile and install cgiwrap
- Modify /private/etc/http/http.conf to work with cgiwrap
- Test PHP cgi using cgiwrap
- Conclusion
- About this page
Make some directories and set permissions
I strongly suggest using the same username you use on pair on your host! Setting up my testing server using the same path structure as my host (pair Networks) has saved me a lot of time. If you are not using pair, just change the /usr/www/users/YOURUSER path to whatever is appropriate. The cd command with no arguments simply takes you to your home directory.
1 2 3 4 5 6 7 8 9 10 11 |
|
Install MySQL server
- http://dev.mysql.com/downloads/mysql/4.0.html
- http://www.entropy.ch/software/MacOSx/mysql/
- http://developer.apple.com/internet/opensource/osdb.html
I used “Installer package (Mac OS X v10.3) Standard 4.0.21 (11.7M)” and just followed the instructions in the readme. Unfortunately I can’t remember the exact steps…but it was easy and straightforward.
Compile and install PHP Apache module
I’m using PHP4 (4.3.10) and pair now has 4.3.10 installed as well. The osxpair.tar.bz2 file contains all of the configure scripts for PHP and cgiwrap, along with the config.* files for cgiwrap to compile.
- http://www.php.net/downloads.php
- http://darwinports.opendarwin.org/
- http://developer.apple.com/internet/opensource/php.html
Extract the configure script archive:
1 2 3 4 5 |
|
Now it is time for some decisions. Use your favorite editor (Vim!) and open conf-mod-osx. These configure options are based on what pair uses, with the following differences because I don’t use them or they are not enabled by default anymore. Modify to your own taste:
pair has these, this configuration does not:
1 2 3 4 5 6 7 8 9 10 11 |
|
This configuration has, pair does not. Remove if you want!
1
|
|
If you want your php.ini somewhere like /etc/php (I do)
1
|
|
I don’t use Fink for package management but do use Darwinports…so because pdflib and recode are not available in Darwinports I did not install or enable them. They could be installed by Fink or manually if needed.
Anyway, anything in the conf-mod-osx file with “/opt/local” means I installed it using Darwinports (for example gettext, mcrypt, gd, sablotron, etc.). Darwinports is easy to use, so check the site and install whatever you need/want first. If you don’t want a feature just remove the line from the file.
1 2 3 4 |
|
If the configure script does not complete you have probably not installed something listed in conf-mod-osx. Check the error message and see what file it could not find. Either install the package needed or remove the option…and run ./conf-mod again until it is successful.
1 2 |
|
I think the install script takes care of your Apache /private/etc/httpd/httpd.conf file, but check to make sure you have these lines:
1 2 3 |
|
Copy your php.ini:
1
|
|
Edit php.ini as needed. These are the differences between what pair uses and what is in the php.ini-recommended. First value is what pair has, second one in (parantheses) is what php.ini-recommended has.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Make a virtual directory for your user
Use your editor of choice…
1
|
|
Add this part:
1 2 3 4 5 6 |
|
Save, and then run:
1
|
|
Check to see if it’s working so far
1 2 |
|
Make a file named phpinfo.php with the following:
1
|
|
Open your browser, go to http://localhost/phpinfo.php and you should see the PHP info page. Notice the 4th item “Server API” says “Apache”. If you get an error you did something wrong or I wrote something wrong!
Compile and install your own cgi version of PHP
I try to make my cgi PHP the same as the module, which is (nearly) the same as pair’s. This means I can use it when needed, and use the faster module when not without worrying about features matching. If you changed the conf-mod-osx file, go ahead and change the conf-cgi-osx to match.
IMPORTANT! For php-cgiwrap to work you MUST keep this line in conf-cgi-osx:
1
|
|
IMPORTANT! Edit conf-cgi-osx and set YOURUSER on the second line!
1 2 3 4 5 |
|
If the configure script does not complete you have probably not installed something listed in conf-cgi-osx. Check the error message and see what file it could not find. Either install the package needed or remove the option…and run ./conf-cgi again until it is successful.
1
|
|
DO NOT RUN make install
1 2 3 4 5 6 7 8 |
|
Edit php.ini as needed. These are the differences between what pair uses and what is in the php.ini-recommended. First value is what pair has, second one in (parantheses) is what php.ini-recommended has.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Compile and install cgiwrap
The latest version is cgiwrap-3.9.tar.gz, so that is what I am using.
The config.guess and config.sub files included with the cgiwrap distribution don’t know OS X. The ones I included in the osxpair.tar.bz2 file are copies of the ones in the PHP distribution, and do know OS X, so you need to copy and overwrite the existing ones in cgiwrap-3.9 directory.
1 2 3 4 5 6 7 8 |
|
If it completes without error:
1 2 3 4 5 6 7 |
|
Modify /private/etc/http/http.conf to work with cgiwrap
Put this within your VirtualHost container:
1 2 3 4 5 6 7 8 9 10 11 |
|
If you are using SSL, put the same thing within your <VirtualHost 127.0.0.1:443>
container.
Find this line:
1
|
|
Add this line below it:
1
|
|
Save httpd.conf, restart Apache:
1
|
|
Test PHP cgi using cgiwrap
1
|
|
Create a file named .htaccess with the following:
1 2 |
|
Open your browser, go to http://localhost/phpinfo.php and you should see the PHP info page. Notice the 4th item “Server API” says “CGI”. If it says “Apache” you messed up the .htaccess file. If you get an error, ummm, it was something else.
Conclusion
If everything is working, you should have a great test system set up! Any directory you need to use the cgiwrapped PHP cgi just put the .htaccess file in it. For pair, change the .htaccess lines to:
1 2 |
|
About this page
This page was (originally) written in XML, transformed into XHTML using libxslt and made pretty with CSS. All code edited using Vim running on Gentoo Linux and Mac OSX.
In 2011 this outdated guide was semi-successfully converted from HTML to Markdown using Markdownify.