Install Apache PHP and MySQL on your Mountain Lion OS
Currently, there seems to be a lack of posts out there on how to get Mac Mountain Lion setup with a *AMP stack. I mean, there’s a lot of posts out there, but they’re not all helpful. The best post I’ve found is this – so I’ll be jumping into this as soon as I get apache working. Let’s try and consolidate that because at present – this mac ignorant (re: me) – has looked at too much junk to just get a dev stack running on his laptop
Mountain Lion, and a few previous versions – already have Apache and PHP installed. So absolute win on that front. Sadly when you search for MAMP or Mac Apache PHP MySQL – all you end up with is 3 odd packages you can “install” to give you what you already mostly have. Massive PITA imo.
Start by creating a new apache configuration file that it’s going to include. And use vim, because that’s what all the cool kids use, and I need to use it more.
sudo vim /etc/apache2/users/darrennolan.conf
<Directory "/Users/darrennolan/Dropbox/public_html"> Options Indexes MultiViews AllowOverride All Order allow,deny Allow from all </Directory> <VirtualHost _default_:80> ServerName localhost DocumentRoot /Users/darrennolan/Dropbox/public_html </VirtualHost>
Go ahead and restart apache
sudo apachectl graceful
That’s pretty much it. WINNING!
Now, it’s important to note – I put in my username “darrennolan” in this post, so replace that with your own username, and replace the directories I used to whatever you want to use. I like to have my dev machine’s public_html sync’d between all my machines – and use dropbox to do so. That is, until I start to use git properly like a boss.
Now, apache is going to be running as a user that’s not you, so whatever files you make ensure they have read permissions opened up so the apache user (_www) can read them. Typically that means files 644 and directories 755. Chmod accordingly – fix some groups up or install yourself suphp. Which I might do yet.
Next up – continue at this blog post to get PHP enabled and MySQL installed. Please note, that link is for lion and not mountain lion – so I’m sure I’ll run into some small inconsistencies like I did getting to get apache running, so standby for updates.
Update: While installing MySQL via homebrew – I didn’t want the MySQL process to run as myself, as a solution – where you need to run the following;
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
Instead I ran
sudo mysql_install_db --verbose --user=mysql --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
I also did not update my.cnf to give myself the huge 2G connection limit. I don’t think any production server I use will ever have such a large limit, therefore my dev machine won’t either.
Because it’s going to run as mysql – you need to chown the data files under /usr/local/var/mysql if it’s not already the right permissions.
sudo chown mysql:admin /usr/local/var/mysql/ib*
To get your PHP SQL stuff working on the Homebrew’s default socket location of /tmp (you could change it) – open up /etc/php.ini and find all instances of ‘default_socket’ and update the path to /tmp/
Lastly to make MySQL automatically start each time you boot up your mac, and as the user mysql – the file link you made in ~/Library/LaunchAgents – you’ll need to put ~/Library/LaunchDaemons – edit the file – and where username says your username, change it to MySQL.