Setting up PHP, MySQL, and Apache in Mac OSX Leopard

One of the best features for web developers in Mac OSX Leopard is the inclusion of PHP and Apache. By default both are inactive and require you to get them ready for business. I will outline how to do this as well as get MySQL up and running so you can have a local development setup right on your Mac!

It’s all pretty easy to do but requires a little attention to detail in parts. So lets get started.


Most of the files we’ll be working with are actually hidden from Finder. If you use a text editor like Coda, BBedit, Text Wrangler, or TextMate you can choose to have hidden files “shown” so you can find them in your file structure. I personally use Coda so all that you have to do is click on the “View” menu and choose Show Invisible Files, as illustrated below:

Coda: Show invisible Files

You can also run this simple Terminal command to “show” all hidden folders in Finder:

defaults write com.apple.finder AppleShowAllFiles TRUE

Then restart Finder by typing the following:

killall Finder

You should now be able to see all hidden files.

PHP

To enable PHP browse to Apache’s http.conf file located in /etc/apache2/httpd.conf

Find this line:

#LoadModule php5_module libexec/apache2/libphp5.so

All you need to do is uncomment the line by removing the hash # symbol.

LoadModule php5_module libexec/apache2/libphp5.so

Now save http.conf. Don’t be alarmed if it asks for your system password… this is normal.

PHP 5.2.6 is the version shipped with Leopard. All the most popular extensions are already activated so you should be good to go. However if you need some of PHP’s extended features you may want to consider rebuilding PHP from source code as I’ve read the version that ships with Leopard has been problematic for some. I’ve never had any problems myself but it’s something to look out for. All relevant PHP settings are in the php.ini file. I won’t be covering any tweaks to that file in this article but you should be aware that it exists. By default, Leopard has an empty configuration file but provides a file which can be used as a template. From a new terminal window, type:

sudo cp /etc/php.ini.default /etc/php.ini

This creates your php.ini file, which is located in /etc/php.ini for your future reference.

You’ve now enabled PHP so lets move on to Apache.

Apache

Our friends at Apple were kind enough to ship a very modern version of Apache 2.2.6 for our development work. Kudos! To start up Apache click on the “Sharing” preference pane in System Preferences and enable “Web Sharing” like so:

Enable Web Sharing

You can also use the following command the start Apache from Terminal:

sudo apachectl start

You’ll be prompted for your system password. Type it in and press enter.

If you need to restart Apache, this will do the trick:

sudo apachectl restart

Keep in mind any editing you do to the http.conf or to the php.ini will require a restart of Apache. You can use the above command or simply restart “Web Sharing” in System Preferences… it’s up to you.

Testing PHP

So now hopefully if everything has gone according to plan, we’ll see some fruits of our labor. Go back to the “Sharing” Preference Pane in System Preferences and click on the URL/ IP Address below “Your computer’s website.” If all goes well you’ll see a page that says “Test Page for Apache Installation.” You can also type http://localhost/ in your browser which will take you to the same place.

Now in your text editor create a PHP file and type the following code:

<?php phpinfo(); ?>

Save it in /Library/WebServer/Documents/ (start from the top level directory of your hard drive, not the Library directory in your home directory) with the name test.php.
Now type http://localhost/test.php in your browser and you should see something like this:

PHP Info

Great success!

Setting up a personal website and virtual hosting

If you’re the curious type and tried to click on “Your personal website” in the Web Sharing panel you may have noticed that you were greeted with a “Forbidden” message. So lets go ahead and set it up so you can serve up files from your “Sites” folder. Open up your text editor and create a file named after your “Home” folder. In my case it would be StevieBenge.conf. This file will live in /etc/apache2/users/. You’ll need to replace StevieBenge with the name of your “Home” directory. I’ve heard reports that this file is created automatically on new installs of Leopard but I had to create mine manually. Add the following code to the .conf file:

<directory "/Users/StevieBenge/Sites/*/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</directory>

Like above, replace StevieBenge with the name of your “Home” directory. Save the file. This will allow Apache to serve files out of your “Sites” folder. Sweet! You’ll also need to restart Apache for this to take effect.

Moving right along, lets set up Apache for virtual hosts. Virtual hosts are essential if you want to serve multiple websites from your “Sites” folder. You can choose pretty much any “domain” name you want or mirror any production sites you have hosted on a live server. I like to name all of my local development sites with the extension .dev to keep easy track of things. Getting virtual hosts to work in Leopard was a huge stumbling block for me because of a lot of misinformation I read around the internet. I was was really happy to finally get this working. And as you’ll see it’s pretty straightforward.

So to get started, browse to /etc/hosts and add the following to the end of the file:

# Local aliases
127.0.0.1 steviebenge.dev

Remember to change steviebenge.dev to the name of a site in your “Sites” folder. 127.0.0.1 is an IP Address that tells your Mac that your site is hosted locally. The site will only be accessible on your Mac. Now we’ll need to reopen the.conf file we created earlier in /etc/apache2/users/:

<directory "/Users/StevieBenge/Sites/*/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</directory>
 
NameVirtualHost *:80
 
<virtualhost *:80>
    DocumentRoot /Users/StevieBenge/Sites/steviebenge.dev
    ServerName steviebenge.dev
</virtualhost>

Again make sure to change the directory structure above to reflect your “Home” folder and the folder within your “Sites” folder you want to serve files out of. Restart Apache for the changes to take effect. So to test it out and make sure everything’s working properly, go ahead and move the test.php created earlier into your new directory in your “Sites” folder. If it’s successful you’ll again see:

PHP Info

Too add more virtual hosts run through the above steps again. Simple as that!

MySQL

Now here is where the fun begins. It’s odd that Apple didn’t include MySQL with Leopard as it’s pretty much synonymous with PHP. Anyway, you have a couple options for installing MySQL on Leopard. You can roll your own and compile and install from source code or use MySQL’s package installer for Leopard. I won’t discuss how to compile MySQL here but I did find an excellent tutorial on how to do this over at Dan Benjamin’s Hivelogic site. I came pretty close to giving this a shot but I opted for the MySQL package installer. Dan brings up many salient points on why it’s beneficial to compile your own install in his tutorial, so I’d highly recommend checking it out.

So head over to the MySQL downloads page and grab a copy of the Mac OS X 10.5 (x86) installer (currently 5.0.67). You can also optionally download the MySQL GUI Tools, which I would recommend as that is how I prefer to administrate MySQL. The Mac Installer is labeled MAC OSX 10.4 (Universal binaries) but, in my experience, it will work without issue on Leopard.

Install MySQL and the GUI Tools. There’s also a Preference Pane that you can install that allows MySQL to be stopped and started from System Preferences. Go ahead and install that as well.

After you install the MySQL Preference Pane, find it in System Preferences and start MySQL like so:

MySQL Preference Pane

If you prefer starting MySQL from Terminal, you can do so with this command:

sudo /usr/local/mysql/support-files/mysql.server start

And you can use this command to stop MySQL:

sudo /usr/local/mysql/support-files/mysql.server stop

Now we’ll need to put the mysql.sock in the proper directory so MySQL can communicate with PHP.

Getting MySQL and PHP to communicate

The default location of mysql.sock is in the /tmp/mysql.sock directory. We’ll need to change this to /var/mysql/mysql.sock as this is where PHP will look for it.
So first off, create a my.conf (or in this case my.cnf) file in your text editor and save it as my.cnf in the /etc folder with the following code:

[client]
socket = /var/mysql/mysql.sock
 
[mysqld]
socket = /var/mysql/mysql.sock

Next move mysql.sock to it’s new directory by typing the following code in a Terminal window:

sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Believe it or not, that’s pretty much it. One thing to keep in mind is the MySQL GUI Tools will still look for the mysql.sock in the old location so when you log in to MySQL Administrator enter /var/mysql/mysql.sock in the “Connect Using Socket” box under More Options:

MySQL Administrator

Now you’re ready to create your first MySQL Database. The MySQL Administrator makes this really easy, which I will cover in a future article. You can also administer your MySQL databases from Terminal. As I stated earlier, I prefer the GUI Tools but learning how to do things from Terminal is a useful skill to have. It’s totally up to you.

Bonus Information

I’ve read that you can also deal with the mysql.sock issue by editing the mysql.default_socket = line in your php.ini file to reflect the location of mysql.sock. I chose not to do this, but it may work for others

You may want to to change php.ini to report all PHP errors while you are in development. This can be done locating the following line:

error_reporting = E_ALL & ~E_NOTICE

And changing it to:

error_reporting = E_ALL

This is fine in your local development setup but of course not advised for a production server.

At the beginning of this article I illustrated how to “show” hidden files in Finder. Here’s that Terminal command again:

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

You can also “hide” those same hidden files with this command:

defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder

Another great resource for an all-in-one development setup is MAMP. Using MAMP negates the need to do any of the above tweaking as it has its own versions of Apache, PHP, and MySQL. It’s perfect for those that want to get up and running quickly with a minimum of fuss.

Conclusion

Well this should get you started with PHP, MySQL, and Apache in Mac OSX Leopard. My inspiration for writing this article was to combine a lot of the information I read from other sites while getting my MacBook Pro set up. Many of the articles I came across were written around the time Leopard was released last Fall so some of the information was a bit out of date. Not that any of the above methods are terribly original on my part, but I’d like to credit some of the sources that helped me:

procata.com: This was the best resource I found and well worth checking out as it shows you how to install the PEAR extension. Has some great tips that I didn’t cover here.

Installing MySQL on Mac OS X: MySQL’s own how-to guide.

adactio.com: Jeremy Keith’s guide.

foundationphp.com: Excellent screen shots with this PHP and Apache tutorial.

Thanks for reading and check back as I’ll be writing more articles about working with PHP, MySQL, and Apache. Feel free to keep the discussion going in the Comments below.

71 Responses to “Setting up PHP, MySQL, and Apache in Mac OSX Leopard”

  1. Jim

    Stevie,
    I’m stuck at trying to get MYSQL to start either in the pref panel or in terminal. The Pref panel prompts for the password, I enter it and nothing happens. In terminal:
    imac:~ myname$ sudo /usr/local/mysql/support-files/mysql.server start
    Password:
    Starting MySQL
    …… ERROR! Manager of pid-file quit without updating file.

    When I first d//l the mysql and installed it yesterday it was working because I even had the widget on the dashboard showing server local status running a green line graph.

    I’ve kept a text file of what I’ve done. Can I email you?

    THanks,
    Jim

  2. Jim

    Stevie,
    Thanks for the prompt reply. I’m not on SnowLeopard yet. I’m currently running 10.5.8 (I should have mentioned that earlier). I downloaded mysql-5.1.43-osx10.5-x86_64.dmg, mysql-gui-tools-5.0-r12-osx10.4-universal.dmg

    When I first started this process, I could not even edit httpd.conf so I found a tip online about using pico in Terminal and that worked just fine.

    1. Open terminal.
    2. sudo pico /etc/apache2/httpd.conf
    3. Make changes and save.

    So I assumed I could do the same with the hosts file. Now yesterday I could not do that. This morning I could. Go figure. Obviously a finger problem :) So now my /etc/hosts file looks like this:

    #
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting. Do not change this entry.
    ##
    127.0.0.1 localhost
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost
    127.0.0.1 myname.dev

    Is that right? Two 127.0.0.1 listed? Anyway, I’m rolling through the steps again to see what happens.

    Thanks,
    Jim

  3. Stevie

    Hi Jim. First off, you must have Administrator rights to edit and save UNIX files. Make sure your user account includes admin rights. If you’re on Snow Leopard, I had a similar problem where Coda (as well as TextEdit) wouldn’t allow me to save UNIX files either. I rectified the problem by purchasing a copy of TextMate. This was right when Snow Leopard came out so this may issue may have been rectified. I think I may have just edited the hosts file with Terminal before I purchased TextMate.

    Yes you are correct… MacHDD/etc/hosts and MacHDD/private/etc/hosts are the same. The former is just a symbolic link to the latter.

    As for your MySQL issues, I would reinstall to be sure it is installed correctly. Luckily I’ve never really had any weird issues with MySQL on any of my computers so I have almost no experience in debugging it. Again if you’re on Snow Leopard, make sure you install the 64-bit version. Good Luck…

  4. Jim

    Hi,

    Good tutorial but I’m stuck at trying to edit the /etc/hosts file. I can open the file using pico and edit but I can’t save the file. Must be a permissions thing but I checked the file permissions of the etc folder and it does say system: read/write. Can you help? I have another question too…you say edit the etc/hosts file but is that the mMacHDD/etc/hosts or is it the MacHDD/private/etc/hosts ? Or are they the same?

    I skipped that section and proceed through to get php to work.Then I worked on mysql but I can’t get it to start in either the admin pane or the terminal. In teh erminal I get this:

    imac:~ me$ sudo /usr/local/mysql/support-files/mysql.server stop
    ERROR! MySQL manager or server PID file could not be found!
    imac:~ me$ sudo /usr/local/mysql/support-files/mysql.server start
    Starting MySQL
    …… ERROR! Manager of pid-file quit without updating file.

    Comments or ideas?

  5. Augusto

    Hi Again Stevie,

    Thanks for your answer…

    Im logged in as Administrator and still cannot edit the httpd.conf file. How can I give the Administrator account the rights to write/edit this file?

    Im sorry, but besides that Im not a programmer I am new to Mac. :)

    Thanks Again.

  6. Augusto

    Hello Stevie,

    Im not a programmer so this question may be stupid, but anyway. All these settings have to be done using the root user when logging into my Mac? or my Administrator user?
    Because if Im logged as Administrator I can’t edit the httpd.conf file.

    Thanks for your help

    • Stevie

      @Augusto: Yes that is correct… you need to be logged in as an Administrator to make changes to system files.

  7. Stevie

    @Arjen: Thanks for visiting. If you look on or around line 151 in your httpd.conf file, you’ll see:

    ServerAdmin you@example.com

    Change the example email address to your desired address, then restart apache. I think that should do it.

  8. Arjen

    In some error messages from Apache, it asks the user to contact the system administrator and shows an email address.

    Do you know how to change the email address that is shown in this error message from Apache? Where does it get it from?

  9. Ashley

    Thanks so much for the tutorial. I had to modify the php.ini file, to change MySQL to /tmp/mysql.sock.

    I also changed the directories in my.cnf to /tmp/mysql.sock so mine looked like:
    [client]
    socket = /tmp/mysql.sock

    [mysqld]
    socket = /tmp/mysql.sock

    Without these changes, I was getting an error everytime I tried to start MySQL

  10. Caleb

    This is an excellent tutorial on how to setup PHP, MYSQL, and APACHE on a Mac. Thank you so much for this!! :)

  11. Ruth

    Thanks very much! I’ve just moved over from Tiger to Leopard and was having real issues getting virtual hosting to work. Your instructions on editing the my.conf file have done the trick and solved my 403 error. Much appreciated.

  12. Martha

    This article, http://superfancy.net/coding/mysql-administrator-on-mac-osx-leopard-tips-and-tricks/, was helpful!

    Ok. So I did set up MySQL administrator but was unable to start the server via the administrator. Maybe that’s not it’s function. I am able to start the server via the System Preferences Pane as well as from the command line.

    I was also able to access my database, nativeplants, as well as it’s individual tables, commonname and grasstable, via the MySQL administrator. And… I made the connection without needing to put in a password for root, even though I set up a root password through the MySQL administrator when I edited the account.

    I am still baffled though, as to why the following file:

    <?php
    $dbhost='localhost:/tmp/mysql.sock';
    $dbuser='mvanorshoven';
    $dbpass='';

    $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecto to mysql');
    print "Connected to MySQL “;

    $dbname=’nativeplants';
    mysql_select_db($dbname) or die (‘Unable to select database’);
    ?>

    produces the following message
    Connected to MySQL
    Unable to select database

    I’m very new at this so I’m wondering if I am connecting to the database but erroneously printing out the wrong error messages or visa versa.

  13. Martha

    Thanks for the link! I think I”m getting closer:

    I was unable to start via the MySQL administrator but when I start either through the command line
    sudo /usr/local/mysql/support-files/mysql.server start or through the system preferences pane and then I go into the system administrator the detail shows:

    User: root
    Host: localhost
    Socket: /tmp/mysql.sock

    Server info:
    MYSQL Version: mySQL 5.1.35-log via socket
    Network name: localhost
    IP: 127.0.0.1

    Client information

    Version: MySQL Client Version 5.1.8
    Network name: mvanorshoven.local
    IP: 192.168.1.108
    Operating System: Darwin 9.7.0

    ok. so now when I’m in the MySQL Administrator world I added a password to root user, I added myself as a user and when I clicked on catalogs, the database that I had created along with the tables are there! this is exciting.

    Uh oh, now when I go back to the Schema Privileges page and attempt to expand the user ‘martha’, the only item below it is %. However, below root I have localhost, root@mvanorshoven.local and root@127.0.0.1.

    Ok, I highlighted ‘martha’ and then added ‘localhost’ (two buttons next to the sillhouette icons) and I added 127.0.0.1 as well as mvanorshoven.local.

    So that all looks great but still, when I’m in firefox and run the following php file:
    <?php
    $dbhost='localhost:/tmp/mysql.sock';
    $dbuser='mvanorshoven';
    '$dbpass=' ';

    $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connect to mysql');
    print "Connected to MySQL”;

    $dbname=’nativeplants';
    mysql_select_db($dbname) or die (‘Unable to select database’);
    ?>

    The message I receive is:
    Connected to MySQL
    Unable to select database

    So where to next? I did put passwords into the MySQL admin screen but when I entered that password in the $dbpass field the error was:
    Access denied for user ‘mvanorshoven’@’localhost’ (using password: YES)…

  14. Brian

    Extremely helpful. You included everything into one place, made it very simple to understand. I thank you deeply for this great info. Had it set up in 30 min!

  15. Stevie

    @Martha: Ok sounds like mysql.sock wants to be in tmp/mysql for some reason. This is interesting because on the PowerPC machine I use at work it is like that too. Strange. I’m going to take a stab in the dark and recommend that check if you have rights assigned to the MySQL account trying to connect to the database. I wrote an article detailing how to assign privileges and working with MySQL Administrator. Check it out and see if that helps…

    http://superfancy.net/coding/mysql-administrator-on-mac-osx-leopard-tips-and-tricks/

  16. Martha

    I’m running MAC with Intel processor

    Ok. Yesterday, I moved mysql.sock to /var/mysql/mysql.sock and I changed the my.cnf file but mysql failed to start after the move. I moved mysql.sock back to /tmp/mysql and still, no luck. So I reinstalled Mysql. Mysql was running this morning and php was running until I moved mysql.sock back to /var/mysql/mysql.sock again at this point mysql failed to start. I moved the mysql.sock file back to /tmp/mysql.sock and everything is working except… my ability to access a database.

    Before I moved the mysql.sock file I did attempt to edit php.ini and the socket path there but this file is a read only even when I use the sudo command.

    any thoughts?

  17. Stevie

    @Martha: I would give that a shot yeah. Are you running a Mac with and Intel or PowerPC processor?

  18. Martha

    I attempted to restart MySQL after I moved mysql.sock to /var/mysql/mysql.sock and it would not start. Do you suggest that I try moving it again and restarting again?

    Please advise and thank you.

  19. Stevie

    @Lucas: Make sure you restart Apache before accessing your virtual hosts. I’m unsure about the second problem you’re having. Sounds like MySQL could be corrupted perhaps?

    @Martha: Did you restart MySQL after you moved mysql.sock to /var/mysql/mysql.sock? Off the top of my head that would seem to be a likely culprit.

  20. Martha

    This article was EXTREMELY helpful. However, I was unable to make mysql work when I moved the mysql.sock file to /var/mysql/mysql.sock

    I had to move the file back to /tmp/mysql.sock

    even after changing the my.cnf file.

    I’m interested in any ideas as to why this is.

    Martha

  21. Lucas

    Hello all,

    I’ve got multiple problems with running both virtual hosts and mysql. Let me bother you with it, as some of you may have already gone through it.. :
    1. After following all steps about VH, I have a permission problems and error 403.
    2. After downloading all files needed to work with mysql I cannot connect to the server neither through mysql preferences in system preferences nor through terminal. In both cases my Mac is working through my command for about 1M, and then nothing happens..

    I am the only owner/user of my mac, so I assume I have access to all files and permission to display them.

    I hope somebody can help me with it.

    Best,
    Lucas

  22. Gary

    Hi Stevie,
    a quick thanks. Your instructions were right on the nail, especially for a first time user like me so I am happily up and running now.
    Cheers,
    Gary

  23. Sean

    Hey, I figured out my problem. It turns out I have a few things to learn about editing in Dreamweaver. I’m used to my IDE that I use in Windows. When you create a new php file in it you start out with a blank page, the way it should be.

    However when I opened up Dreamweaver on my macbook pro and said to create a new php file it turns out that I was initially in live view mode but didn’t realize it. When I sent to split view mode I saw that even though I said to create a new blank php file Dreameweaver actually created an html template file and so the phpinfo() function I was trying to execute was simply being output to the screen. Once I got rid of all of the html code everything ran just fine.

  24. Sean

    Hello. I’m having a problem. I’m so used to setting up PHP and what not on Windows machines that I’m having trouble on my macbook pro. This is my first time using a macbook pro by the way.

    Anyway, after doing the initial test to get PHP and Aapache up and running everything was initially fine. I then followed the part about sharing the web services and adding the line to the hosts file. I got all the way to making the test.php file and putting it in my Sites folder and that’s where I’m stuck.

    Every time I try to go to http://localhost/test.php all that shows up is that actual text of the file test.php. It doesn’t run the phpinfo() function. It’s almost as if php isn’t running.

    Any suggestions because I’m at a complete loss.

  25. Stevie

    @werner: Thanks for the nice words. I use WP and Drupal for most sites that I do, but I am curious about Joomla. I will definitely check out your blog. Thanks!

  26. werner

    Stevie,
    You are welcome, I just went to the same discovery reading – I don’t know how many – mostly incomplete “tutorials” about this on the web. My angle is that I develop Joomla websites and I am setting up my Mac for debugging with Eclipse and XDebug. I am about to publish a blog when I came accross your article. It confirmed what I had seen except that I don’t have to do anything with the mysql socket. After I installed mysql it worked…
    Anyway, good luck with your web design biz. Check out my blog if you have a minute… http://www.theglinkacompany.com/blog

  27. Stevie

    @werner Thanks for clearing this up. I will edit the article to reflect this.

  28. werner

    Steve,
    the comment box doesn’t take the code tage either. I mean first line with the path “/Users/StevieBenge/Sites”. The path sould be “/Users/StevieBenge/Sites/*/”
    Werner

    ps if this doesn’t work send me your email and I’ll send you a PM

  29. Stevie

    @werner Yeah WP drives me nuts some times. I will email you…

  30. werner

    Steve,
    In the part of your article where you talk about virtual hosts the first line of the code segment should read:

    Note the /*/ at the end of the path. That might have been the problem for the people that couldn’t make their virtual hosts work.
    Regards,
    Werner

  31. Stevie

    I removed the syntax highlighter on phpinfo(); for better cut and paste action…

  32. Stevie

    @Mike WordPress for some reason adds a space between the opening php bracket and the question mark. Trying to track down the issue but that is a good point nonetheless.

    I occasionally have permissions issues as well.

  33. Mike

    A very useful document.

    A couple of things to note that gave me trouble in my setup:

    1) In the “Testing PHP section” you have the line:

    My computer didn’t like it until I changed it to:

    (deleted the first space) and then everything was fine.

    2) Once website sharing was enabled, I still didn’t have access to my personal website, despite everything looking fine. Eventually tracked the problem down to permission on my home directory (eg. /Users/ ) being wrong – they were 700 instead of 755. Once that was fixed, I could move on.

  34. Chris V

    Stevie,

    Thanks for the response. I appreciate the time you took. =)

  35. Stevie

    Chris:

    Yeah the file is just called my.cnf and is placed in the /etc folder. At least this is how it is on my machine. My experiences with setting up PHP and MySQL in the past have all been subtly different, but this is what worked for me.

    Basically and too the best of my knowledge, all the my.cnf does is tell PHP where the to look for the MySQL connection.

    Hope this helps…

  36. Chris V

    Stevie, I still need a little clarification please. From your following instructions.

    “create a my.conf file in your text editor and save it in /etc/my.cnf with the following code:”

    Am I creating a my.conf or a my.cnf file? and am I just installing it in the /etc/ folder (i.e. /etc/my.conf – or – /etc/my.cnf)? A post above spoke about a my.cnf folder (i.e. /etc/my.cnf/my.cnf)

    The reason I ask is that when I create a my.cnf file and copy it to the /etc/ folder, mySQL stops running, but when I create a my.conf file with the same information in it mySQL continues to run.

    Is there a reason why this would be the case?

    This is the code I used:

    [client]
    socket = /var/mysql/mysql.sock

    [mysqld]
    socket = /var/mysql/mysql.sock

    What exactly does this file do?

    Thanks. =)

  37. Stevie

    Darren… that’s a great point. One that I didn’t make clear in my article. Thanks…

  38. Darren

    Just so it’s clear sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock doesn’t move the mysql.sock file it just creates a sym link to it. That is all that is needed to get mysql going with php on leopard.

  39. JC

    with regard for this error: (ERROR! Manager of pid-file quit without updating file)

    try this:

    sudo chown _mysql /var/mysql

  40. spiftic

    Fantastic!!
    The best and the easiest method so far and i have looked everywhere. This worked like a charm.

    Cheers :)

  41. John

    Stevie,
    Thanks so much for putting this stuff on the web. It is very straightforward. Unfortnately, I am experiencing the same difficulty that April did on September 22nd. Please advise.
    Sincerely,
    John

  42. Stevie

    Kevin… thanks for dropping by. My main inspiration for writing this article was the lack of any MySQL setup tutorials pertaining to OSX. Glad you found it useful!

  43. Kevin

    Stevie, just wanted to say thanks for the detailed guide. Managed to get all the way up to the MySQL install, but couldn’t find good documentation on what to do. This worked like a charm. Definitely appreciate it!

  44. Stevie

    Hey Scott. Thanks for the nice words. Here’s something you can try…

    Go into the root directory of your Mac and find the private folder. There you’ll find the etc folder. Right-click on it and click Get Info and verify that the system has Read & Write permissions. If it has both then you should be able to create a my.cnf file…

  45. Scott

    Hi Stevie

    Thumbs up for a very helpful site.

    I have stumbled across one problem which is to do with
    “create a my.conf file in your text editor and save it in /etc/my.cnf with the following code:”
    I don’t seem to have the my.cnf folder and when tying to make a new folder to save the my.conf file in I get the message that the /etc folder is read only

    I’m a complete newbie so any pointers would be great.

  46. cosmoanut

    hi leopardnewbie,
    I have the same error (ERROR! Manager of pid-file quit without updating file), did found a solution for this?

  47. Stevie

    Excellent. I was going to recommend reinstalling as a last resort. I know that worked for me on my G5 tower at work which used to have Tiger on it. Cool man glad you got it working… now you can finally do some real work.

  48. leopardnewbie

    Hi Stevie,

    So I finally got my mysql running..

    I dumped the previous version of mysql and re installed again.

    Your site surely gives a lot of insight to any newbie like me… I must reiterate…

    Thanks

  49. leopardnewbie

    BTW, to revoke the chown 755 issued earlier to the mysql/data folder , I used the command:

    sudo chown -R root:wheel data

    which changed the owner to root again

    …just in case it would be useful to someone reading this

  50. leopardnewbie

    Thanks a lot for your comments… I am all set to troubleshooting…

  51. Stevie

    Whoa… never seen that error before! I am unsure how to revoke the above command. There’s a syntax for doing those types of Terminal commands but I can’t remember off the top of my head.

    Man sounds like you’re having some problems. I struggled too getting this stuff working in previous attempts in the past. I spent many hours and days googling and doing things by trial and error.

  52. leopardnewbie

    I get the error
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ERROR! Manager of pid-file quit without updating file
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    when I try to start the mysql server thru the terminal like:

    sudo /usr/local/mysql/support-files/mysql.server start

    Meanwhile in an attempt to view the data folder in mysql, I issued the command
    chown 755 to that folder, which I guess is not right. How do I revoke it.

    Thanks again for your time

  53. Stevie

    I would concentrate on getting MySQL up and running as you won’t be able to add any users till it successfully starts up…

  54. Stevie

    Hey. Well my first question is, did you install the MySQL Preference Pane? If so, head over to System Preferences and at the bottom under Other, click on MySQL. From there you’ll be able start MySQL.

    In Jeremy Keith’s article I link to above, he set’s up a Terminal command that automatically starts MySQL when your Mac boots up.

    I just start MySQL manually because I don’t use it everyday.

    Hope this at least gets you on the right track…

  55. leopardnewbie

    Some add-ons to the troubleshooting situation requested above :

    I did not complete the steps you had mentioned in

    ” MySQL Administrator on Mac OSX Leopard: A Few Tips and Tricks · superfancy on 08.23.2008″

    like

    1. Setting password for root
    2. Adding a new mysql user
    3. creating a new db
    4. assigning privileges to user

    Would these activities influence for the connection error?

    Thanks for any suggestions

  56. leopardnewbie

    Hi Steve,

    Could you sense what could be wrong, when my MySql does not connect after I restarted my MBP.

    I did use MySql Administrator which you had described above. The first time the connection went thru, used the MySQl Query browser to work on Northwind schema and got my php stuff to work.

    Now I get Connection Error : Could not connect to MySQL instance at localhost.
    Error:Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock'(2)(code 2002)

    I tried it thru terminal, it does get the same error.

    Pinging the Host is not successful either

    Would very much appreciate your trouble shooting, yourself being a pro…

    Thanks

  57. Stevie

    Thanks… glad people are getting some use out of it. I had a tricky time getting things all squared away so I’m more than happy to share. Thanks for stopping by…

  58. leopardnewbie

    Thanks a lot for your awesome work !

    Your comments were indeed very helpful

  59. Stevie

    Hi April. Thanks for stopping by. I would recommend getting MySQL up and running first and then deal with the Virtual Hosts. When I was setting up my G5 at work I had a really difficult time getting the Virtual Hosts to work as it had previously been running Tiger. I had no such issues on my MacBook Pro though.

    An important detail to not overlook is anytime you make any changes to Apache files, remember to restart Apache to activate the changes. It’s an easy thing to forget and the root of many frustrations.

    If you have any specific questions, feel free to use my contact form and I’ll do my best to help you out…

  60. April

    Stevie,
    I feel like such a goofball, but I can’t get this to work. I’ve tried so many times, it’s crazy. No matter what I do, I get to the virtual hosting part and get a “can’t find the server” or “can’t find local host” every time. I updated to Leopard, so I’m wondering could it be older apache files are messing me up? I also have mysql already installed, though its not running yet cause I haven’t been able to get beyond running virtual hosts. Help. I’m wondering if anyone else has this problem and if you’ve come across a solution? Thank you for this post, the descriptions are fantastic.
    April