Easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard), 10.7 (Lion), 10.8 (Mountain Lion)?
Solution 1
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. There are reports that this is fixed in 10.6, but that doesn't appear to be the case for all of us, given some of the comments below.
Solution 2
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
Solution 3
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.
Solution 4
I strongly prefer HomeBrew over MacPorts for installing software from source.
HomeBrew sequesters everything in /usr/local/Cellar so it doesn't spew files all over the place. (Yes, MacPorts keeps everything in /opt/local, but it requires sudo access, and I don't trust MacPorts with root.)
Installing MySQL is as simple as:
brew install mysql
mysql_install_db
To start mysql, in Terminal type:
mysqld&
There's a way to start it upon boot, but I like to start it manually.
Solution 5
This help me a lot:
http://maestric.com/doc/mac/apache_php_mysql_snow_leopard
It also works for Mac OS X Lion :D
.:EDIT:. On my case the prefepane only allows to start and stop mysql, but after some issues i've uninstalled him. If you need a application to run queries and create DB, you could use: Sequel Pro (it's free) or Navicat
If you need start and stop mysql in ~/.bash_profile you can add these lines:
#For MySQL
alias mysql_start="/Library/StartupItems/MySQLCOM/MySQLCOM start"
alias mysql_stop="/Library/StartupItems/MySQLCOM/MySQLCOM stop"
After reloaded the console just call:
$mysql_start
or
$mysql_stop
agreding the desired action. Hope helped you.
Related videos on Youtube
Matt Sephton
Former Apple Technology Evangelist I type stuff into computers to make them do cool things.
Updated on July 28, 2021Comments
-
Matt Sephton almost 3 years
What is the easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard), 10.7 (Lion), 10.8 (Mountain Lion)?
I'd prefer to use any bundled versions before resorting to downloading from the PHP or MySQL websites. That also rules out MAMP and similar.
I'm comfortable at the command line in Terminal.
-
Matt Sephton over 14 yearsOut of interest - Snow Leopard is 64-bit capable, so why choose the 32-bit of MySQL?
-
machuga over 14 yearsLeopard, 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.
-
Matt Sephton over 14 yearsThat is exactly the information I was looking for. Thanks Mr/Mrs Unknown!
-
Matt Sephton over 14 yearsthere's a typo /etc/apache2/httpd.conf
-
mdskinner about 14 yearsbeautiful!.. who would do it any other way!.
-
Dave DeLong about 14 years+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): red91.com/2007/12/14/installing-mysql-on-leopard
-
cregox about 14 yearsif 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
-
cregox about 14 yearsand the "It works" page is under
/Library/WebServer/Documents/index.html.en
-
apaderno almost 14 yearsI followed the steps reported here, but still PHP is not working; using a URL like example.local/dr61/install.php, the browser shows the code source. I guess it is necessary to change something in the php.ini file.
-
apaderno almost 14 yearsAt 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.
-
apaderno almost 14 yearsTo use MySQL, I had also to change the default socket, which in my case was /tmp/mysql.sock (I installed MySQL 5.5).
-
aaaidan over 13 yearsAlso, after saving the .conf, you can just use the command
sudo apachectl restart
instead of turning web sharing off-on. -
Duke over 13 years"brew link mysql" will create a number of symlinks in /usr/local/bin etc.
-
Ethan over 13 yearsI'm not sure I understand the 'messily spew files' comment. MacPorts sequesters everything in /opt/local, so it seems equivalent. I suppose occasionally I've seen something placed in /Applications/MacPorts (e.g. AquaTerm for gnuplot), but this is the very rare exception and usually for a good cause (e.g. AquaTerm is a .app bundle), and even then it's keeping it organized under a single directory...
-
Ethan over 13 yearsOh, and I find it easier to simply add /opt/local/bin to my $PATH, and -I/opt/local/include to CPPFLAGS, -L/opt/local/lib to LDFLAGS, and then not have to remember to set up links for every single package that gets installed...
-
Duke over 13 yearsMy use of the symlink was based partially on ignorance; it's completely unnecessary. I just don't trust large installation scripts with root. And if you don't think MacPorts spreads files over many directories, just look at the uninstallation instructions: guide.macports.org/chunked/…
-
brutuscat over 13 yearsI like this! Instead of messing with the PATH add an alias +1
-
Eric Bloch almost 13 yearsTo test the setup, you can put the line <?php phpinfo(); ?> inside ~/Sites/foo.php and browse to host/~user/foo.php
-
Matt Sephton over 12 yearsDoes the MySQL prefpane work for you in Lion? That is, can it switch MySQL on/off?
-
workdreamer over 12 yearsi don't need the prefpane, but this solve your question? : stackoverflow.com/questions/3027479/…
-
gravyface over 12 yearsAlso, remember to close/re-open your Terminal session for your aliases to take effect.
-
workdreamer over 12 yearsBut the prefpane only allows you to start and stop the mysql. I re-edited my post because here its not formated.
-
Behrang over 12 years@Cawas what's the difference between
/etc/php.ini.default
and/private/etc/php.ini.default
? -
cregox over 12 years
-
Matt Sephton about 11 yearsI prefer the standard bundled versions, please see the question.
-
pojda over 8 yearsWorked like a charm on El Captain. Btw this link helped me a lot too coolestguidesontheplanet.com/…