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.
ammps was super easy for me and has a nice web-based configuration:
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.
FYI - if anyone experience issues with launching Apache, and getting errors about
/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument
it's because of a recent update to Apache in Snow Leopard. The fix is easy, just open
/usr/sbin/apachectl
and setULIMIT=""
http://blog.deversus.com/2010/11/mac-os-1065-apachectl-usrsbinapachectl-line-82-ulimit-open-files-cannot-modify-limit-invalid-argument/
There's a great guide here:
https://discussions.apple.com/docs/DOC-3083
However, it didn't work for me first try. I found this tip: run "httpd -t" in Terminao to check the syntax of your config files. Turns out using copy & paste from the tutorial introduced some strange characters. After fixing this, it worked great. There are some links from the guide for adding MySQL as well.
This worked much better for me than MAMP. With MAMP, I was having delays of about 20 seconds or so before changes to the .php file would be reflected in the browser when you refresh, even if you cleared the cache, history, cookies, etc.
This problem was resolved in MAMP PRO, but MAMP PRO had a new issue of its own: the .php files would be downloaded instead of being rendered as a page in the browser! I contacted support and they didn't know what was going on.
The built-in Apache server didn't have any of these issues. Definitely the way to go. The guide below is almost identical to the one above, but it has user comments that are helpful:
http://osxdaily.com/2012/09/02/start-apache-web-server-mac-os-x/#comment-572991
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.
Open a good text editor (I'd recommend TextMate, but the free TextWrangler or vi or nano will do too), and open:
Find the line:
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.