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

Comments

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.

Stuart Church said on February 23, 2005 11:01 PM

It might also be worth taking a look at MAMP . It’s basically Apache, PHP, MySQL & phpmyadmin rolled into a single install for OS X. Pretty neat really.

Tore said on February 24, 2005 8:39 AM

Great man! I just got a Powerbook - my first Mac since my Performa 630 - and was about to find out how to install php and mySQL. This is so helpful.

Martin said on February 24, 2005 9:18 AM

Anyone know of a no nonsense guide to installing mySQL on Windows XP? I just keep getting error after error when I try to start or connect.

Ilija Studen said on February 24, 2005 2:20 PM

Main installation page is here (also take a look at user comments). Windows installation page is here .

Try running c:/mysql/bin/winmysqladmin.exe and then shut it down (the tool, not the service). If this works (service is up and running, take a look at Control Panel > Administration tools > Services) remove winmysqladmin from Start Menu > Programs > Start up and that’s it.

Maybe there is the better way to register MySQL service but I always used winmysqladmin to do it for me.

Good luck ;)

PS: Sorry for poor english.

Tim Yang said on February 24, 2005 4:11 PM

I installed MAMP (Macintosh, Apache, Mysql and PHP) too. It’s brilliant. I just opened the application and it took only a few seconds before I had my ibook functioning with both PHP and MySQL.

MAMP website: http://www.mamp.info/en/home/

Shawn Rice said on February 25, 2005 12:36 AM

For a MySQL frontend, I’ve been using YourYourSQL, a nice little GIU mentioned on Marc Liyanage’s site. Fairly simple, easy to use, and free.

Thordur Arnason said on February 25, 2005 6:42 PM

If you really want a powerful frontend you should try out Aqua Data Studio - a great query and admin tool thats also works with oracle, ms sql, db2, sybase, informix and postgresql.. personal usage is free.
http://www.aquafold.com/

ian said on February 25, 2005 8:56 PM

marc liyanage rocks and so does phpmyadmin :)

Ryan Nichols said on March 1, 2005 6:44 PM

I was curios if there were any percieved slow-down with having these services running? Are they resource intensive or get in the way for an everyday use computer?

Chiradeep Chhaya said on July 23, 2005 1:20 AM

Andy, awesome tutorial man!!

And Tim, MAMP rocks!! All-in-all, a 2 minute installation procedure, from the moment you download the installer to changing the mysql root password and adding users.

No hassles, and the best part is it’s free.

DL Byron said on October 11, 2005 3:06 PM

NAMP rocks and I just used it to install Wordpress in under 10 minutes, but a note that it doesn’t have any perl libraries, so it’s not going to work with Movable Type.

Nick Lazar said on April 18, 2006 11:46 PM

I have Apache, MySQL & PHP5 set up on both XP & Tiger.

For XP, I found the easiest and most painless way of installing all 3 (Plus Perl & Analog) was to use the http://developerside.net Web Server Suite package. This saved me hours! Just be aware that you need to uninstall IIS, as it will conflict with Apache. (I’m sure there is a work around for this, but it wasn’t worth the effort for me, as Apache is what my hosting providers use).

The Mark Liyanage package worked very nicely for me on OSX (which is what I use for 90% of the PHP/MySQL development work I do).

I’ve tried many different MySQL front ends, but found that Navicat (which is available for both Mac & PC) has by far been the best. It’s great for testing, backing up, scheduling and connecting to multiple web servers. The Only downside is that it ain’t free! ($168 for the Mac/XP bundle last time I looked).