views:

36901

answers:

14

What is the easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard)?

I'd prefer to use any built in versions before resorting to downloading from the PHP or MySQL websites.

I'm comfortable at the command line in Terminal.

+2  A: 

http://www.mamp.info/

Mr. Smith
I'd really rather stick with the standard installs, if possible.
matt
Thank you! Why not use the standard installs? There are there for a reason else why ship them.
Stephen Cox
+1  A: 

I'm not quite sure as I'm not so familiar with MacOSX, but I think this will work in Snow Leopard too: http://www.macosxhints.com/article.php?story=20071030153912813

x3ro
A: 

Considering it hasn't been released yet, I'm assuming this is a question for ahead-of-time or you have a developer's build. As Benjamin mentioned, MAMP is the easiest way. However, if you want a native install, the process should be like 10.5. PHP comes installed on OS X by default (not always activated for some), just download the 32-bit version of MySQL, start Apache, and you should be good to go. You may have to tweak Apache for PHP or MySQL, depending on what builds are present. I didn't have to tweak anything to have it working.

machuga
Out of interest - Snow Leopard is 64-bit capable, so why choose the 32-bit of MySQL?
matt
Leopard, and even Tiger for most things I believe, are 64-bit capable. 64-bit MySQL has some issues with some other packages, not directly related to PHP necessarily, but lets say he tried Python down the line - 64bit MySQL causes some serious grief with the MySQLDB package. It's completely usable, just not all things have caught up yet, sadly.
machuga
+1  A: 

I would agree with Benjamin, either install MAMP or MacPorts (http://www.macports.org/). Keeping your PHP install separate is simpler and avoids messing up the core PHP install if you make any mistakes!

MacPorts is a bit better for installing other software, such as ImageMagick. See a full list of available ports at http://www.macports.org/ports.php

MAMP just really does PHP, Apache and MySQL so any future PHP modules you want will need to be manually enabled. It is incredibly easy to use though.

simonrjones
+31  A: 

Open a good text editor (I'd recommend TextMate, but the free TextWrangler or vi or nano will do too), and open:

/etc/apache2/httpd.conf

Find the line: "#LoadModule php5_module libexec/apache2/libphp5.so"

And uncomment it (remove the #).

Download and install the latest MySQL version from mysql.com. Choose the x86_64 version for Intel (unless your Intel Mac is the original Macbook Pro or Macbook, which are not 64 bit chips. In those cases, use the 32 bit x86 version).

Install all the MySQL components. Using the pref pane, start MySQL.

In the Sharing System Pref, turn on (or if it was already on, turn off/on) Web Sharing.

You should now have Apache/PHP/MySQL running.

In 10.4 and 10.5 it was necessary to modify the php.ini file to point to the correct location of mysql.sock. This has been fixed in 10.6 and the MySQL installs now.

SerpicoLugNut
That is exactly the information I was looking for. Thanks Mr/Mrs Unknown!
matt
there's a typo /etc/apache2/httpd.conf
matt
this worked great for me too, thanks
Craig Nakamoto
beautiful!.. who would do it any other way!.
mdskinner
+1 this is the way to go. I've also found the instructions here to be amazingly helpful (even though it says 10.5, it works for 10.6): http://www.red91.com/2007/12/14/installing-mysql-on-leopard
Dave DeLong
if anyone else is wondering where's the `php.ini`, there isn't any! but you can add one to `/etc` by copying **`/etc/php.ini.default`** to `/etc/php.ini`
Cawas
and the "It works" page is under `/Library/WebServer/Documents/index.html.en`
Cawas
I followed the steps reported here, but still PHP is not working; using a URL like http://example.local/dr61/install.php, the browser shows the code source. I guess it is necessary to change something in the php.ini file.
kiamlaluno
At the end, I had to copy the file php.ini.default in php.ini, and PHP files started to be executed as they should be.
kiamlaluno
To use MySQL, I had also to change the default socket, which in my case was /tmp/mysql.sock (I installed MySQL 5.5).
kiamlaluno
Also, after saving the .conf, you can just use the command `sudo apachectl restart` instead of turning web sharing off-on.
aaaidan
A: 

I got a problem running mysql it simply does not start. Preferences panel "start" button does not start it. and I get : 2:etc nacho4d$ /usr/local/mysql/bin/mysql -bash: /usr/local/mysql/bin/mysql: Bad CPU type in executable

by the way I have the first generation intel iMac (the White) and downloaded the 64-bit version of mysql. do i need a 32-bit version?

here is my the original post: http://stackoverflow.com/questions/1334272/cant-start-mysql-in-mac-os-10-6-snow-leopard

HELP please.

nacho4d
I've left a reply to your original question.
matt
A: 

You've got a typo! It should be:

/etc/apache2/httpd.conf
I stated that above in the comments
matt
+2  A: 

I've summarized all the necessary steps (tested with a clean install of Snow Leopard).

Jerome Jaglale
your link is a blank page, for me
matt
Try this: http://maestric.com/doc/mac/apache_php_mysql_snow_leopard
Jerome Jaglale
+3  A: 

to complete your setup or mysql:

sudo vim /etc/profile

add alias

 alias mysql=/usr/local/mysql/bin/mysql
 alias mysqladmin=/usr/local/mysql/bin/mysqladmin

then set your root password

mysqladmin -u root password 'yourPassword'

then you can login with mysql -u root -p

mdskinner
A: 

Tried to edit /etc/apache2/httpd.conf but got a message "The document “httpd.conf” could not be saved. You don’t have permission."

I'm the only user on this computer - I'm the admin.

??

shenrichs
you need to use sudo to edit the conf file. eg. sudo pico /etc/apache2/httpd.conf
matt
A: 

I'm new to Mac and I can't seem to find /etc/apache2/httpd.conf in my Mac OS X Snow Leopard.

BreakClinic
you won't find it in the Finder, you have to access using the terminal, for example:sudo pico /etc/apache2/httpd.conf
nacho4d
+2  A: 

it's an invisible folder. Just hit Command-Shift "G" (takes you to the Go to Folder menu item) and type /etc/ Then it will take you to inside that folder.

asdf1
A: 

Has anyone tried XAMPP? http://www.apachefriends.org/en/xampp-macosx.html

Drak
For some people that's fine. I just prefer to use the stuff that comes with OS X as standard.
matt
A: 

I strongly prefer HomeBrew over MacPorts for installing software from source.

brew install mysql

HomeBrew sequesters everything in /usr/local/Cellar so it doesn't messily spew files all over your machine, but you'll have to symlink it to /usr/local so mysql.sock is in the expected place:

ln -s /usr/local/Cellar/mysql/5.1.xx /usr/local/mysql

(Be sure to replace 5.1.xx with your installed version.)

Then in ~/.profile I put:

alias mysql.server=/usr/local/mysql/share/mysql/mysql.server

So that you can then start and stop mysql by typing:

mysql.server start
mysql.server stop
Duke
"brew link mysql" will create a number of symlinks in /usr/local/bin etc.
Duke