Tuesday, June 10, 2008

PHP on the Mac

If you have a Mac with Leopard and want to use PHP, most of what you need is already installed. It's just a matter of making it work.

First you need to turn on apache. Just go to your "System Preferences", "Sharing" and turn on "Web Sharing". That's it, apache is running. You can check if all is ok by going to http://localhost.

You'll probably want MySql too. Just go to their site, download and install. No big fuss, but make sure you install the StartupItem if you want MySql to start when the system boots.

Next you must enable PHP. Launch a terminal and use your favorite text editor to edit /etc/apache2/httpd.conf. Look for LoadModule php5_module and uncomment the line. Restart apache with sudo apachectl graceful.

Now let's say your username is john, and you have on your home folder a ~/dev/phpproj where your php code is. One way to make this available (and there's lots of others) is to edit /etc/apache2/users/john.conf and add the following to the bottom of the file (replace [ with "lesser than" and ] with "greater than". Blogger doesn't like those symbols):
Alias /phpproj/ "/Users/john/dev/phpproj/"
[Directory "/Users/john/dev/phpproj/"]
Options Indexes MultiViews
Order allow,deny
Allow from all
[/Directory]
Now you can access http://localhost/phpproj/ to view your app.

At this point you might get a MySql error stating that you /var/mysql/mysql.sock does not exist, just go back to your terminal window and type:

cd /var
sudo mkdir mysql
cd mysql
sudo ln -s /private/tmp/mysql.sock mysql.sock

That's it!

I bought a Mac!

About a year ago I wrote some reasons why I wasn't buying a Mac. Well, a year has come and gone an I bought a Mac! And so far, I'm very happy with it!

I could go on forever about what's so great about my Mac, how cool it is just to unpack it, how beautiful the hardware and software are, and all that. But you can read about a million posts on the web about that, so I won't bother.

Instead I'm going to focus on the parts that aren't so good. This way people switching from Ubuntu to Mac will know what to expect.
  1. You have to pay for the software: Oh yeah, most software is closed source and payed for. I really miss doing apt-get and it just works, no payment, no registration...
  2. The keyboard is... different: I have a portuguese keyboard. The Mac doesn't have a } anywhere visible on the keyboard! It took me a while to figure I had to type --9
  3. X11 compatible... kind of: You can run X apps on the Mac. I installed Gimp, and it works. But the UI is a bit clumsy... For starters, the keyboard shortcuts aren't the same for X and Mac (e.g. in Mac you copy with -c, in X with -c). Second, the windows interaction is awkward. In "X mode" you have to click the window to get the focus, then click the button on the window to make it work. Since the Gimp has multiple windows, this is very annoying.
  4. No out of the box NTFS write support: C'mon! I have an external 500Gb HD formatted in NTFS! I had to install MacFUSE from google to make it work!
  5. Only 2 USB ports: Good thing I have a hub!
  6. Strange video output: It has a mini-DVI. Never seen one before. Oh well, I don't have another monitor, so it's not a big problem.
And I can't remember anything else... but I only have the laptop for 4 days!

Don't get me wrong, I love my Mac! But, like all things, it has some downsides. And the biggest one AFAIK is the non-open nature of this platform. Still, if I was going shopping again today, I would still buy the Mac!