The local setup (to rule them all)

Apple, Web development

At work I have to jump between different web (PHP) projects all the time. So having an environment that allows me to easily add something new, switch to another site and do all of that fast and with as little steps as possible is crucial for my job (and my sanity).

Before today I used a “native” setup for this: install Apache, PHP and MySQL on OS X, add a new vhost with VirtualHostX and add the new site to the /etc/hosts file. That setup ran smoothly for many months and many projects, and hardly gave me any trouble.

With Mac OS 10.10 Yosemite getting released last week, I decided to give my work machine (which is a 15″ retina MacBook Pro) a fresh start. I ran an (extra) back-up, made bootable disk and was off to the races. A formatted disk and 30 minutes later, I had a fresh Yosemite install, ready to be configured.

I decided to use Vagrant this time, because I want to separate my development environment from my operating system as much as possible. That makes it portable and share-able (but that’s a topic for a whole other post). I’ll quote vagrantup.com here:

If you’re a developer, Vagrant will isolate dependencies and their configuration within a single disposable, consistent environment, without sacrificing any of the tools you’re used to working with (editors, browsers, debuggers, etc.).

That sounds pretty good right? Here we go:

  1. Download & install VirtualBox
  2. Download & install Vagrant
  3. Using puPHPet.com I configure a VM running Ubuntu with the usual: Apache, PHP 5.6, MySQL, Mailcatcher.
  4. Make a “Sites” folder in your user profile (/Users/$username/Sites) and add the puphpet file to it
  5. Open a terminal window, go to the Sites folder and run vagrant up to download the vm and run through the install scripts

So now that we have our virtual machine up and running, we have to figure out 2 things: 1) how to direct local traffic to the VM, 2) a fast and easy way to add new virtual hosts.

Having to edit your hosts file for every new project I need to set up is a bit inconvenient (even though apps like GasMask make it super easy). Ideally I’d be able to set a wildcard for a subdomain and all that traffic would just go to the VM, where Apache figures out where to send it. This is where I introduce you to Dnsmasq. Dnsmasq provides network infrastructure for small networks – but what does that mean for this setup? I’m going to use the DNS server in Dnsmasq to route all traffic for a certain subdomain to my VM. Here’s how that’s done:

  1. I’m going asume you have HomeBrew installed
  2. run brew up to make sure everything is up to date.
  3. run brew install dnsmasq
  4. follow the instructions brew gives you at end of the installation (copying the default config files and adding dnsmasq to LaunchDaemons)
  5. find the /usr/local/etc/dnsmasq.conf file and add the follwing:
    address=/dev/127.0.0.1
    In this example we’re pointing all traffic from domains with top level .dev to 127.0.0.1

For my work setup I added the following:
address=/.local.company.tld/192.168.56.101
Note the extra dot in from of the url: that is the wildcard, which is crucial to our setup. The IP address is address of our Vagrant VM.
Lastly, we stop and start Dnsmaq:
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq

  1. Next up, we have to get OS X use Dnsmasq for any requests going to .local.company.tld. Most UNIX-like systems use the file /etc/resolve.conf to control where DNS querries go. OS X allows us to configure extra resolvers in the /etc/resolver/ directory.
    We’ll start by creating that folder: sudo mkdir -p /etc/resolver.
    Then we create run sudo vim local.company.tld to create that file (with same name as the domain we want to “redirect”) in that folder. In that file, we simply add “nameserver 127.0.0.1” to indicate that DNS querries for local. company.tld should be routed to the DNS server at 127.0.0.1 (which is where Dnsmasq runs).

  2. Lastly, we’re going to test our DNS. We’ll use a simple ping command to check if our domain names are still resolving correctly.

ping google.com
ping test.local.company.tld
ping mlkjmlkj.local.company.tld

Now we have wildcard domain pointing to our Vagrant machine, so project1.local.company.ltd, project2.local.company.tld, etc all automatically go to our VM. As a last step, we’ll look at a script to automate the creation of a new VirtualHost for Apache.

I started from this and forked it to fit my needs:

  • By default we run our sites with public/ as DocumentRoot
  • In older projects there might be /www or /html as DocumentRoot
  • Or the site can run completely in the DocumentRoot

 

You can find my version of the script here (I’ll try to keep it updated with the changes I make as I use it more).Β The script also imports a template it uses for the vhost file, that can be found (and forked) here.

Here are some example of what the script can do for you:

  • vhost.sh facebook will give you a vhost called facebook.local.company.tld, which /var/www/facebook/public for its webroot and a facebook folder in /var/www (which maps to ~/Sites/facebook on your mac)
  • vhost.sh -www facebook will do the same thing, expect the webroot will be www instead of public
  • vhost.sh -root facebook will make a vhost called facebook with /var/www/facebook as its webroot.
  • vhost.sh -l will list all vhosts available on the system
  • vhost.sh -rm facebook will remove the vhost called facebook from your Apache config.

I’ve been running this configuration for about a week now and I’m quite happy with it. It’s stable, fast and easy to add new projects.

If you have your own setup for PHP development or have suggestions for how I can improve this configuration further, feel free to leave them in the comments section.

Happy coding πŸ™‚

Advertisements

Creating a bootable 10.10 Yosemite volume

Apple, Tools

With the release of Mac OS 10.10 Yosemite earlier this week, I wanted to share a fast and easy way to create a bootable volume from which you can install Yosemite (that can be a harddrive or a usb key).

  1. Download Yosemite from the Mac App Store.
  2. Plug in your external disk/volume and make sure it’s either empty or can be formatted in the next step.
  3. Open terminal.app and enter the following command:
    sudo /Applications/Install OS X Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/*your volume here*/ --applicationpath /Applications/Install OS X Yosemite.app

    This will convert your volume install a bootable installer based on the application path you provided, which is the Yosemite “app” in this case

  4. Enter your administrator password,
  5. You’ll be prompted to confirm that the volume can be erase, press ‘y’,
  6. And done.

 

Now connect the drive to machine you want to upgrade/reinstall, boot it up while holding the ‘c’ key and select the “Install 10.10. Yosemite” volume.

β˜… 2012 MacBook Air review.

Apple

Apple released an update to their MacBook Air line last week at WWDC and I’m pretty convinced that one of these will be my next machine.

I have my mind set on the 11″ model, 8gb RAM, 128gb ssd (lots of people I talk to are getting the 256 or more version but I’m currently running on a 120gb drive with 30gb of free space). The only thing I’m still doubting on is wether or not I’ll get the i5 of the i7 model. Either model will be a speed bump from my current Core 2 Duo 2.26 Ghz machine, but with the i7 I could probably switch to the 11″ as my only computer when my current 13″ MBP fails/becomes too slow.

β˜… Redownload your purchased music from iTunes.

Apple, OSX

Not sure if this is new or not but I haven’t notice it before so here goes:

A couple of months ago, Apple added the “Purchased” option to the iTunes store. That option gives you a list of all the apps and books you’ve purchased in the past and gives you an easy way to download those again (for example when you change computers).

ITunes

Screen Shot 2012 01 14 at 20 50 45

Now, Apple has added Music to the Purchased-tab. It show you a list of all the music you’ve purchased through iTunes (either sorted by track or by album) and allows you to download them per track, per album or all music at once.

Screen Shot 2012 01 14 at 20 51 48

I seem to remember that getting the music you purchased from iTunes back after a crash used to be a pain in the backside but with this feature that is no longer the case.

β˜… Flaky Home Button Syndrome.

Apple

Since a week or so, the home button on my iPhone 4 is been acting very strange. From time to time, it does not react when I press it. Pressing it once, twice, 30 times in a row, nothing. So I reboot the device (have you tried turning it off and on again?) and it works again. For a while. I haven’t been able to determine how long or what triggers it to stop working.

Really annoying. You pick up the phone and you want to wake it up, you press the home button. You’re in an application and you want to go back to the home screen, you press the home button. You want to go the the task manager, you press the home button twice. Only it doesn’t respond.

After a quick google search, I found out that I’m not the only one having this problem and that Apple knows about it too. So off I went to my local Apple dealer.Β They had heard about the problem but they couldn’t help me, I’d have to take my phone back to the store in which I bought it and get it fixed through them.Β This is because Mobistar has the sole right to import iPhone in Belgium, so all repairs have to go through them as well. (or something along those lines)
But god knows how long that’s going to take…. (and the great experience I’ve had with Mobistar in the past isn’t really helping)

But since the problem doesn’t occur 100% of the time and since some sources online state that reinstalling the iPhone’s OS might help, I’m going to try that first.
I’ll keep you posted.

β˜… iPad 2: Thoughs and why I’m not getting one.

Apple, Technology

I was only going to get the new iPad it it had a high resolution retina display (comparable to the display in the iPhone 4). That was the only new feature that would really make me want one. I don’t care for cameras, either front or back facing or both, because I just don’t see the usefulness of video-calling. When have you ever done that? (I have myself, on occasion, skyped with video but that’s it)

When presenting the new model during the keynote, Steve started with the new processor. Dual core, 5 times faster, 9 times better graphics compared to the previous/current model. That sounds an awful lot like new display right? Nope. (as was expected/predicted by most tech/news sites)
So no new iPad for me.

Another reason why my current iPad will do just fine is because I don’t use it *that* often. I basically only use it for reading (feeds/instapaper/email). And because every time I use and hold the iPad, it still feels a bit of magical. Such a small device and so different from the other ‘computers’ I use.

If you’re doubting whether or not you should get one, I can’t really help you πŸ™‚
But if you’re waiting because the next model will be even better, you’ll never buy it. So if you don’t currently own an iPad, there’s no real reason not to get this one. (rumor is that we’ll see iPad 3 released this year as well, but that’s far from confirmed)

β˜… Syncing iPad apps only

Apple, Technology

When you connect your iPad and you want to app/remove/rearrange apps, you get a list of both iPad apps and iPhone/iPod Touch apps (off course, only if you own the later).
Allthough iPhone/iPod Touch apps will work on your iPad, you’re probably not going to want to sync them.
But going to through the list and figuring out which app is for iPad and which is for iPhone/iPod Touch is a bit of a hassle….

I had this ‘problem’ as well, but have recently discovered a neat feature to fix this πŸ™‚
Connect your iPad, go the the ‘apps’-tab and click ‘Sort by …..’
Check the latest option ‘Show iPad apps only’, et voila, solved πŸ™‚

(This might seem kind of trivial, but I’ve told a couple of people and they didn’t know about this so I wanted to share it with everyone :))

β˜… Apps on my iPad

Apple, Internet, Software, Technology

In the wake of the iPad’s release here in Belgium (which is tomorrow), I wanted to write something about the apps I use on mine. (if no price is added means the app is free. For none-native apps, clicking the name will take you straight to the app in iTunes)

We’ll start top left and go right and down from there.
– Calendar
– App Store
Pages (for ?7,99 you get Pages (just like on your Mac) on your iPad, I used this for all my writing)
WordPress (I (co)author a couple of WordPress blogs, just like this one, and this app makes that very easy)
– Settings (placed top right so I can easily tap it with my right hand when hold the device)

Gowalla (location-based social network, app looks great but I don’t use it that much)
Dash Four (?1,59. Foursquare app, another location-based social thing on which I am rather active)
– Facebook (not an app, just a bookmark to the website)
– Tumblr (same as above, just a bookmark)
Flightcontrol HD (?3,99. Awesome game in which you have to guide airplanes with your fingers :))

iBooks (from Apple, with in-app bookstore. Also allows you to add your own pdf-files, big plus!)
Zinio (App for digital magazine subscriptions, with some free samples)
Instapaper (?3,99. If you use Instapaper on your computer, this is a good app to catch up on reading)
De Standaard (?3,99. App for Belgian newspaper De Standaard, yes it ain’t free, but it comes with 5 free newspapers (complete newspaper, if you decide to get the weekend edition, you also get all the extras. Without a subscription to the newspaper, you can access the news of the day and the best photos from the newspaper)
Wide Angle (?2,99. If you like photoblogs like the Boston Big Picture, get this app. The images look great and flicking through them with your finger is a joy)

Then, onwards to the apps I keep in the dock:
– Mail (quite self-explanatory :))
– Safari (for browsing)
Echofon Pro (?3,99. For Twitter off course. This is the best twitter-app for the iPad I’ve come across so far (and before this I tries Tweetdeck, Twitterific and Osfoora HD). Plus, if you already own Echofon Pro for your iPhone, you get the iPad version for free)

NewsRack (?3,99. My RSS-reader of choice, mostly because I already owned the iPhone-version and thus got it for free on my iPad. I like the interface, it has lots of sharing option and it syncs with Google Reader, what more could you want?)

– Photos (my photo-portfolio, this is a great way to show my work to others)
– iPod (music, because where would we be without that :))

That’s what’s on my home-screen for now, these are the apps I use the most. If I discover any other things I think you should know about, I’ll get back to you πŸ˜‰