10.5: How to enable PHP and MySQL in 10.5
Nov 12, '07 02:30:00PM
Contributed by: ryanleary
Getting a working an Apache, MySQL, and PHP environment running in Leopard Client is quite easy. Included with OSX 10.5 are Apache2 and PHP 5.2.4, although PHP is disabled by default. So let's start by enabling PHP.
- Open Terminal and navigate to the apache2 directory by typing cd /etc/apache2
- Using your text editor of choice, open httpd.conf; in this case, we'll use pico. We must use sudo, however, as root is the owner of httpd.conf: sudo pico httpd.conf
- Press Control-W and search for php; uncomment the line that loads the php module by deleting the # at the front, leaving this: LoadModule php5_module
- Save the changes by pressing Control-X, then press Y, then press Enter.
Get MySQL Ready
Apple was kind enough to compile php with support for MySQL, so we simply need to download the proper Tiger install package for your Mac. Run the package installer, and follow the onscreen instructions to install mysql. Cool! Done, right? Not quite, we must tell php the proper location of the mysql socket. Open up Terminal again, and navigate to the php.ini.default file by typing cd /etc.
In its current state, php.ini.default does nothing; php launches with its default values. In order for php to read the ini file, it must be renamed to php.ini. We will do a copy to retain the default file, just in case:
sudo cp php.ini.default php.ini
Open the newly-created php.ini file in pico by typing sudo pico php.ini. Press Control-W and search for mysql.default_socket, and make it look like this:
mysql.default_socket = /tmp/mysql.sock
Save the changes by pressing hen pressing Control-X, then press Y, then press Enter.
Now simply navigate to the Sharing pane of System Preferences, and either start web sharing or stop and restart web sharing. You now have fully functioning PHP and MySQL in Apache2. Further configuration of MySQL is beyond the scope of this tutorial.
[robg adds: This didn't quite work on my (clean) 10.5 install. Instead, I had to follow the steps in this tutorial -- in particular, the part about creating /var/mysql (setting it to 777 perms), then editing the php.ini file to point to that directory. Once I did that, mysql started and ran as expected.]
Comments (3)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20071030153912813