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.
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:
"#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.
To complete your setup or MySQL:
sudo vim /etc/profile
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