LAMP on Mountain Lion with Homebrew

I got my Retina Macbook Pro last week and migrated from my [t]rusty 2007 Whitebook. I had been using MacPorts on that machine and decided to give a try to Homebrew instead. To setup the LAMP stack with homebrew, the best guide to follow is Roland Atvar’s guide .

Then, Mountain Lion happened. And my LAMP stack started to act up.

Because Web Sharing is Gone

The handy web sharing option inside System Settings is gone, or more exactly OS X Server has swallowed it. You can get it for 20 bucks but just to start Apache is not worth it.

Being a smartass, I just went to the terminal and started apache:

sudo apachectl start

But for some reason apache was trying to load files from /usr/htdocs instead of the DocumentRoot I had setup at /Users/joaquin/Sites, from the apache error logs:

[Wed Aug 01 13:09:54 2012] [error] [client ::1] File does not exist: /usr/htdocs

After poking around in apache’s configuration, I noticed that the DocumentRoot configuration was enclosed in IfDefine tags:

<IfDefine !MACOSXSERVER>
<IfDefine WEBSHARING_ON>
    [...]
</IfDefine>
</IfDefine>

After reading a bit about Apache’s IfDefine I noticed that they check for parameters set while launching Apache:

The parameter-name argument is a define as given on the httpd command line via -Dparameter- , at the time the server was started.

So launching apache in the following way solved the issue:

sudo apachectl -D WEBSHARING_ON -k start

If you want apache to load automatically on login, you’ll need to modify the file /System/Library/LaunchDaemons/org.apache.httpd.plist to send the parameter:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <true/>
    <key>Label</key>
    <string>org.apache.httpd</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>XPC_SERVICES_UNAVAILABLE</key>
        <string>1</string>
    </dict>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/sbin/httpd</string>
        <string>-D</string>
        <string>FOREGROUND</string>
        <string>-D</string>
        <string>WEBSHARING_ON</string>
    </array>
    <key>OnDemand</key>
    <false/>
    <key>SHAuthorizationRight</key>
    <string>system.preferences</string>
</dict>
</plist>

Setting up PHP with Homebrew

Following the instructions in José Gonzalez’s Homebrew-PHP GitHub repo worked, mostly.

Mostly?

Another piece of software that Apple removed from OS X is X11 which Homebrew requires (or likes):

Warning: X11 not installed.

You don’t have X11 installed as part of your OS X installation.

This is not required for all formulae, but is expected by some.

Apple directs you to install XQuartz as a replacement .

After this, the Homebrew-PHP instructions worked. To get mysql support in PHP, do:

brew install php53 --with-apache --with-mysql

Cycling

cy·cling /ˈsīk(ə)liNG/
Noun: The sport or activity of riding a bicycle.
Synonyms: bicycling

For the last 3 or 4 years I’ve been gaining weight at a rate of about 2kg per year, I knew it wasn’t all about a bad diet and that I had to exercise more but never found a sport that I could stick to.

I tried yoga at home, a paid gym (that worked well but we moved), a gym at home. All of which I stopped doing. The common theme with these activities: I dreaded doing them. When the time was approaching for me to go to the gym or turn on the TV to view the Yoga DVD I was anxious and felt bored.

Today it was snowing/raining and 2°C and couldn’t wait to go outside and pedal. I bought my bike just 3 weeks ago and started commuting a third of my trip to work on my bike (I’m not ready for the 25k that is the complete trip). Yes, it’s 3 weeks only so it may well be a fad, but I’m liking it until now.

My trip consist mostly of cycling through bike paths which makes it very safe and because the path goes along a river is an treat of nature. And that is one of the nicest things about cycling, you get to enjoy nature. As opposed to the isolation we experience inside a car .

My ride

I bought a Specialized Crosstrail Hybrid Bike, which like my car expect to have for 10 years (too much? we’ll see).

I hadn’t ride a bike since I was 10 (the coolest black BMX in the world) so I’m not sure how to tell if the bike is the best or I missed on something better. I have read a couple of reviews about being hard and requiring more effort to maintain speed. I guess they are right as it’s no road bike but I will just assume I’m not strong enough yet.

All I can say is that I love the design, it takes me to and from work without problems and I’m getting exercise.

Paraphrasing a Reddit comment: a lighter bike won’t be as much improvement as a lighter you. So I’m happy with what I chose.

Logging

I bought an iPhone app called cyclemeter which basically tracks your route and time and estimates your calorie consumption and other nifty things.

I’d recommend it to anyone doing any work out that requires you to travel. It has allowed me to see that I am getting better at it aside from the muscle soreness.

It is also cool to see graphs of your speed compared to your best times.

Still Learning

I’m still learning a lot about my specific bicycle and cycling in general: maintenance, repairs, clothing, etc.

I plan to bike year-round so I’ll probably learn a lot more about cycling in the cold when the time comes.

A great resource for learning that I’ve found is Reddit , the community is great there and discussion and help is always there.

Savings?

A lot of people ride a bicycle as a way to save money monthly in transportation (gas, public transit). I’m not seeing savings yet as I’m still driving my car for about 40 km every day which is a lot more money than public transit. Add to that all the expenses of a new cycling life (bike, clothing, tools, etc. and I’m far from saving money. But the savings are offset by my healthier lifestyle.

To date I have bought a couple of cycling shorts, a pair of tights, a jacket, helmet, multitool, tire patch kit, u-lock, fenders, pump and a pair of lights (front and rear).

I have seen some nice things while cycling mostly having to do with nature. I was thinking of getting a helmet camera to record my rides and maybe post them to YouTube but I haven’t found one that is cheap-ish.


CakePHP Migrations 2.1, migration guide

https://github.com/CakeDC/migrations/tree/2.1

I’m in the process of moving a CakePHP 1.3 app into the 2.1 world.

One thing that changed that I could not find documented anywhere is that the new migration plugin doesn’t use the map.php file anymore but relies on a naming convention.

VersionNumber-name.php

Where_VersionNumber_ is the version number of the migration. For example on my app:

001_initial.php
002_chapter_word_count.php
003_story_disclaimer_field.php
004_follows.php
005_reviews.php
006_chapter_review_count.php

You can pad with as many zeros as you feel you’ll need. Are 999 migrations not enough? Also each class name needs to be changed to the camelized version of the file name without the version number, so 001_initial.php should start like this:

<?php
    class Initial extends CakeMigration {

And that way CakeDC’s migration plugin will detect the migrations again.

Phantomjs: headless webkit

http://code.google.com/p/phantomjs/

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, SVG.

PhantomJS is an optimal solution for fast headless testing, site scraping, pages capture, network monitoring and many other use cases.

Very useful.


Retracting Mr. Daisey and the Apple Factory

http://www.thisamericanlife.org/blog/2012/03/retracting-mr-daisey-and-the-apple-factory

This American Life is a great podcast, the stories they air are greatly produced and they go to great lengths to research them.

The episode “Mr. Daisey and the Apple Factory”, aired on January, started a big backlash against Apple’s manufacturing operations and the fact they turn a blind eye to the terrible conditions the manufacturing workers are subjected to.

Today they are retracting that story.

[a Marketplace] China correspondent for the public radio show Marketplace tracked down the interpreter that Daisey hired when he visited Shenzhen China. The interpreter disputed much of what Daisey has been saying on stage and on our show. On this week’s episode of This American Life, we will devote the entire hour to detailing the errors in “Mr. Daisey Goes to the Apple Factory.”

The backlash this story generated did change the attitude of Apple, now they have become members of the Fair Labor Association and have become even more vocal about their standards of social responsibility across our worldwide supply chain.

Mike Daisey was wrong of abusing the loudspeaker that This American Life is, but I think he doesn’t really regret it, from his blog:

What I do is not journalism. The tools of the theater are not the same as the tools of journalism. For this reason, I regret that I allowed THIS AMERICAN LIFE to air an excerpt from my monologue. THIS AMERICAN LIFE is essentially a journalistic ­- not a theatrical ­- enterprise, and as such it operates under a different set of rules and expectations. But this is my only regret. I am proud that my work seems to have sparked a growing storm of attention and concern over the often appalling conditions under which many of the high-tech products we love so much are assembled in China.

It’s going to be interesting to listen to next week’s TAL and find out what “creative licenses” Daisey took and what is the truth.

I agree with Daisey’s take that his stunt shaked the status quo. That is good. Lying to TAL and Ira Glass. Not cool.


Binding A Backbone View To A Model

http://lostechies.com/derickbailey/2011/06/15/binding-a-backbone-view-to-a-model-to-enable-and-disable-a-button/

I’m learning Backbone.js and this article has helped me to get a first grasp on how to manage the separation of Views and model and how to wire them up to update each other as necessary: changes in the view will update the model which triggers the validation of the fields which in turns has to update the view.

It’s very refreshing to finally have MVC on the client side, no more crazy jQuery wires all over.