With the launch of Mountain Lion and after suffering a hard drive failure, I decided to investigate other options for my local development environment than using MAMP. MAMP has served me well over the years, but considering the number of visitors to my MAMP + Lion tutorials, it’s obviously not as easy to use as a LAMP server.
Virtual machines are great. I know many people that use commercial products like Parallels and VMWare Fusion to run Windows instances alongside their OS X environments. I’m not here today to compare the various products, just know that for me, the open source VirtualBox more than adequately fills my need.
After discussing my VM desires with some other developers I work with, I discovered that Shared Folders were the killer feature I needed.
Shared folders allow me to take my ~/Sites directory and map it to the /var/www directory on my LAMP-based VM. For the most part this has worked well for me. Obviously, though if all was well, I wouldn’t be writing this post.
I’ve got some code that generates cached templates. With some recent changes I made to an underlying templating engine I’m working on, the engine always creates cached files, but if you are in a development environment (or debug state), it will just overwrite the files with every request.
This led to a problem where the permissions of my mounted folder prevented me from writing these critical files to the shared folder. I got to a point where I could create the file the first time, but the template could not overwrite the file on subsequent saves.
Doing some searching led to a post on the ubuntu stack exchange, which led me to the correct solution. It’s different enough (at least for my setup) that I wanted to chronicle the changes I made.
Since I am mounting a folder that needs to be written to by my Apache user, I needed to set up the mounted point so that it mounts being owned by www-data. To find this information, on the VM command line, I typed:
$ id www-data
This returns the gid and uid of 33 for my VM. Using this information, I was able to update my rc.local file so that the line I use to automatically mount my shared folder reads:
sudo mount -t vboxsf -o umask=002,gid=33,uid=33 www /var/www
After doing a reboot, the shared folder now mounts using www-data as the owner. Now I can write and overwrite to my cached folder without problems!
I may write up an overall how-to on setting up a headless LAMP VM with VirtualBox, but that’ll be for another time.
You know you’re a nerd when you:
And yes, that’s me.
Packages: The Way Forward for PHP -
» Great article articulating what I’ve experienced recently.
Having played around with Composer lately, I’ve gone from a meh to a This is frickin’ awesome mentality. For my new projects, I’m building them around Composer for managing my dependencies and autoloading.
Modern MVC web frameworks often involve a lot of boilerplate code just to support the primary client type of User Agents. This boilerplate code typically does little to help with supporting the other client types of Admin Processes and Unit Tests. As a result of the overhead introduced by this extra boilerplate code, developers often find themselves creating Fat Controllers (a side-effect of The MVC Paradox). Controllers take on too many responsibilities, both vertically and horizontally. Vertically, Controllers start to handle domain logic that should be pushed down to the Model layer. Horizontally, multiple concerns get stuffed into a handful of Controllers. These different horizontal concerns should be separated out into multiple Controllers (the Single Responsibility Principle). The overhead introduced by modern MVC web frameworks leads directly to these problems. —
The MVC Paradox – Bradley Holt
» This article is a great read and something I’ve been pondering myself recently. The author references the Slim micro framework which, at least from a cursory glance, is very similar to Silex. I love Silex for the same reasons he mentions Slim:
There is very little boilerplate code involved in handling a User Agent’s request. Minting and handling new routes is incredibly simple. Placing your entire front-end application layer in one file may seem absurd at first. However, it has the nice side-effect of making it painfully obvious if you start to handle domain logic outside of your Model layer or if one route is doing too many things.
I’d recommend checking out these micro-frameworks. Silex has opened my eyes to a new way of designing web applications and services. Where Zend Framework has complexity, Silex offers simplicity.
Today I ran into a problem where my PHP Application would throw this fatal error:
Fatal error: Exception thrown without a stack frame in Unknown on line 0
… After a few minutes I found the problem: I had a class that would save itself to the Session, and that class also had a __sleep method which is invoked on serialization. —
PHP, Sessions, __sleep, and Exceptions | Justin Carmony
I had a similar problem not too long ago. My solution was to call:
at the beginning of the bootstrap process.