The no hassle guide to installing PHP and MySQL on OS X 10.3 | February 23, 2005
In preparation for last weekends PHP workshop I decided to set up a development environment on my iMac. It was pretty easy to do and only took about an hour. Since then I’ve had a couple of people ask about developing on OS X so I thought it would be worth going through my process.
Install PHP
Panther (OS X 10.3) comes bundled with PHP 4.3.2 and enabling it is as simple as uncommenting a couple of lines in the Apache configuration file (httpd.conf). However I chose instead to install the PHP5 package supplied by Marc Liyanage which comes with a number of additional libraries. Being a regular OS X installer package, all you need to do is double click the package and follow the on screen instructions.
Once installed, turn web sharing on in the sharing control panel and drop a file containing the following code in your shared folder.
<?php phpinfo(); ?>
Then you can then test your php installation by accessing that file through your browser at http://127.0.0.1/~username/filename
Install mySQL
To install mySQL, grab the latest OS X package and follow the installation instruction. In older versions of OS X you needed to create a mysql user for the program to run under. Luckily 10.3 comes with a mysql user already set up, making installation a bit easier.
The package contains the mySQL installer and also a startup item installer which makes sure mySQL is running when you reboot your computer. With both items installed you need to do a couple of things in the command line to finish off.
First you’ll want to add the path to mysql as an environmental variable, so you won’t have to type the full path out each time. The install instructions explain how to do this in the tsch shell (Jaguars default shell) but to do the same thing in Panthers bash shell, run the following commands.
shell> echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
Then you’ll want to run mySQL to remove the anonymous user and to set the root password.
shell> mysql -u root
mysql> DELETE FROM mysql.user WHERE User = '';
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');
For more info see the post installation documentation.
mySQL frontend
If you’re not a hard core command line user you’ll probably want a nice front end to manage mySQL. Most hosts use phpMyAdmin, an easy to install php front end. Simply download the files, move the folder to your shared directory and then edit the config files (phpmyadmin.conf) with your mySQL username, password and path to phpMyAdmin. You can then simply navigate to that folder in your browser to manage mySQL.
Keeping your password as clear text in the config file isn’t very secure, so you’ll probably want to use HTTP authentication instead.
Alternatively if that’s too much messing around for you, try CocoaMySQL instead. It’s a really nice freeware mysql administration application which allows you to manage all your mySQL databases, both local and remote.
Apparently there is a problem connecting to MySQL 4.1 with CocoaMySQL because of a change in encryption mechanisms. However there is a simple fix for this.
Apache configuration
Lastly it’s really handy to set up Virtual Hosts in Apache. This allows you to access your sites directly via a virtual hostname or port number e.g.
http://mysite
http://127.0.0.1:8080
instead of via your home directory
http://127.0.0.1/~username/sitename.
This makes developing a little easier as you can use absolute rather than relative urls in your html, css etc so you won’t have to change paths when you move your files to the live server. There are a number of ways to do this, so have a look at theses articles and the resulting comments for more info.
Posted at February 23, 2005 8:11 PM
Matt Heerema said on February 23, 2005 9:57 PM
ouu… very helpful, thanks. For some reason I’ve been too lazy to RTFM on how to do this, so I’ve been putting it off. Now I have no excuse.