Setting up for web development on OS X
Posted by Jason on June 16, 2007 at 4:12 pm
I’ve been slowly working through all of the bits I usually use for web development on my MacBook, attempting to get it set up in a similar way to my PC. No particular reason for that, it’s just what works for me and means I can swap between machines whenever I like - PC for the working week and Mac for out-of-hours seems to be my pattern…
On the whole it has gone fairly smoothly, though it hasn’t been entirely without problems. Here is the detail of what I have set up and where I came across issues. It might help someone if they come from a similar background to me of PC development.
Apache 2
Thanks to it already being set up on OS X this was no bother at all. System Preferences > Sharing > Services and set Personal Web Sharing to on. You should be able to browse to your home page straight away and it even gives you the URL of your home page at the bottom of the tab. It’s little touches like that that really make you think Apple love you!
Don’t think you won’t come across set up issues later though. It will need some tweaking to get it running properly with the other stuff coming up.
PHP
It doesn’t really matter what version as long as it’s 4.3 or later. Before that it was not quite so easy to install PHP on a Mac, but now it’s a doddle. Apple have a nice tutorial:
http://developer.apple.com/internet/opensource/php.html
MySQL
I thought this would be the most difficult area but, again, Apple have a nice tutorial:
http://developer.apple.com/internet/opensource/osdb.html
I also installed the MySQL GUI tools. To be honest I still think they’re a bit poor compared to other admin tools for other databases (or even for MySQL for that matter). For instance, MS SQL Server’s management console is far superior, in my opinion. Unless you’re really good with command-line SQL (and I’m not even though I’ve worked with databases for over 7 years!) then the tools will be necessary for setting up databases and database users. As I’m sure you know, it’s never a good idea to use root for applications. That reminds me, the first thing you should do is give root a password as it will be blank by default.
CakePHP
Not that you have to install CakePHP, it just happens to be something I’ve used on a couple of projects recently and contains some quite complex components. I figured that if I could get this up and running my environment would be ready. The installation is fairly straight-forward, but certainly not without problems. This was not necessarily down to CakePHP or any other component, just the set up between them.
The first thing you really should use with CakePHP is .htaccess which is turned off by default in Apache. However, what I didn’t know is that changing the setting for AllowOverride from ‘None’ to ‘All’ in /etc/httpd/httpd.conf is not enough. There are also your local configuration settings in /etc/httpd/users/<username>.conf which require the same change.
That certainly made a difference as I immediately received 403 forbidden errors - ‘You don’t have permission to access /’. It turns out, after some trawling around, that the issue is with the FollowSymLinks option not being available. Check that ‘Options FollowSymLinks’ is enabled in your personal .conf file. Mine now looks like this:
<Directory “/Users/Jason/Sites/”>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all</Directory>
I also had problems with Apache locating my files, probably because I was working directly from my /Users/ folder and Apache was set to use /Library/WebServer/ since I’d left it at the default. Rather than mess around with that I just created a link folder from the console. This seemed to sort the problem nicely.
ln -s /Users/ /Library/WebServer/Users/
Finally I had my web application running, .htaccess redirection was working nicely and the right files were being served up on request. But then it was failing to talk to the database, spewing out ‘Can’t connect to local MySQL server through socket …’. That took me a while to work out since most of the time Google searches just tell you that the MySQL db server hasn’t been started. I knew it had otherwise the client tools wouldn’t have been able to do much. It turns out that the database configuration file in my CakePHP application was incorrect. Not in an obvious way either. It just happens that you cannot refer to the local database as ‘localhost’ which works fine on my Windows environment. If you get the problem try 127.0.0.1 instead.
database.php:
class DATABASE_CONFIG
{var $default = array(’driver’ => ‘mysql’,
‘connect’ => ‘mysql_connect’,
‘host’ => ‘127.0.0.1′, /* NOT ‘localhost’ */
‘login’ => ‘login_name’,
‘password’ => ‘login_password’,
‘database’ => ‘database_name’,
‘prefix’ => ‘md_’);}
And that seems to be it at the moment. I haven’t done much actual work yet so I’m sure things will crop up as I go along. Hopefully I won’t forget these issues the next time though.