I got PHP and MySQL working together on my MacBook Pro with Mac OS X Lion tonight. I’m using the MySQL server that I installed with Homebrew. Homebrew doesn’t come with Apache or PHP due to its policy of avoiding including packages that are already installed on OS X. Because of that, I’m using the included Web Sharing, which I enabled in the Sharing Preference Pane under System Preferences.
I’m posting what I did below. I found a more thorough guide when I got stuck on a step. Please consider using that, as it covers much more, including getting PEAR set up.
Here are the steps that I remember taking, to get WordPress running locally:
- Install MySQL using Homebrew (
brew install mysql) - Since I added something to my
/etc/apache2/httpd.confthat caused Web Sharing to fail to start, I copied/etc/apache2/original/httpd.confto/etc/apache2/httpd.conf, and that fixed it. - Turn on Web Sharing in the Sharing Preference Pane
- Uncomment the line that starts with
LoadModule php5_modulein/etc/httpd/httpd.conf - Since I didn’t want all of my files in
~/Sites, I enabled redirects in my user php file,/etc/apache2/users/bat.conf, by addingFollowSymlinks to the Options. - Add a symlink to the WordPress directory (
~/Sites/blogin my case) and set up the database - Go to the directory in the browser (
http://localhost/~bat/blog/in my case) - My database connection didn’t work despite my username, password, and hostname being correct. After some googling I found that I needed to change all instances of
/var/mysql/mysql.sockin/etc/php.inito/tmp/mysql.sock - Fix the WordPress site url in the database
Ben, great article. Especially thanks for bulletpoint #2.
With regards bulletpoint #4, I don’t have that file in that path. I do have it at: /etc/apache2/httpd.conf
Is that what you meant?
hcabbos,
Yes, that’s what I meant. Thanks for pointing that out.
[…] Apache is installed but not started by default; run apachectl -k start to start it. Here’s more on setting up LAMP. […]
[…] Apache is installed but not started by default; run apachectl -k start to start it. Here’s more on setting up LAMP. […]