MAMP and Dynamic Virtual Hosts
I recently came across a blog post by David Coallier which detailed a cool way to deal with local development with Apache. You can read his blog post at Wildcard /etc/hosts, an alternative, this is something I have been after for a very long time so decided to try it for myself.
I don't use homebrew but instead I use macports so here is how I managed to achieve the same thing.
First things first make sure you have Macports installed and working.
Then lets install dnsmasq using Macports so open up a terminal shell and type
sudo port install dnsmasq
This will download and install dnsmasq to /opt/local/sbin
Next up you need to edit the dnsmasq.conf file to setup your local DNS entries. To do this type
sudo vim /opt/local/etc/dnsmasq.conf
I then added the following 2 lines to the configuration file
address=/com.local/127.0.0.1
listen-address=127.0.0.1
After saving the file I then needed to make sure that dnsmasq was started automatically when my macbook was restarted. I did this by typing
sudo port load dnsmasq
Next up I needed to add the new DNS server to my network configuration so that it would be used when trying to resolve domain names. I did this by going to
System Preferences -> Network -> Selected My Network Interface -> Advanced -> DNS
By clicking the + symbol and adding 127.0.0.1 to the list of DNS servers I was now all set.
I tested this was working by going back to the terminal window and first off tried an external domain to make sure I hadn't screwed my DNS up
ping google.com
PING google.com (173.194.37.104): 56 data bytes
And then trying my new local addresses
ping mark.com.local
PING mark.com.local (127.0.0.1): 56 data bytes
I was now all set. Next up to configure MAMP so that I didn't need to setup a virtual host for every site I was working on.
I did this by editing /Applications/MAMP/conf/apache/httpd.conf and added the following lines to the end of the file
NameVirtualHost *:80
UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon
VirtualDocumentRoot /Applications/MAMP/htdocs/%1
VirtualScriptAlias /Applications/MAMP/cgi-bin
After a quick restart of MAMP I was now able to use any .com.local domain name and it would map correctly to a folder inside /Applications/MAMP/htdocs/
To test this I created a new folder inside /Applications/MAMP/htdocs/ called testsite
And added a simple index.php file which just did an echo "Hello World"
Then booting up a browser I went to http://testsite.com.local and voila I was treated to the simple words "Hello World". My life was now complete, no more faffing around with vhosts and /etc/hosts!
Thanks to David for helping me realise just how easy it could be to set all this stuff up.
Love Thy Project
I've been planning to write again for a while but things such as "life" have gotten in the way, today however I decided to stop finding reasons to avoid writing and actually sit down and write about something which has been bothering me for a while.
Being part of an open-source project can invoke a wide range of emotions, from feeling proud you are creating something cool for others to benefit from, to the deep despair of trying to get a release ready whilst your family/friends compete for your attention.
A majority of people in the community are pretty understanding about the dedication you bring to a project and understand when you don't provide firm commitments on when something will be ready (a.k.a "it will be ready when its ready"), there are however a minority of people who think that you "suck" and have no idea how an open-source project should be run.
See Exhibit A:
I've lost count the number of times I've read comments similar to the following
- Version X is dead, no-one cares anymore
- You suck because you don't know when version X will be ready
- You should stop wasting your time, project X is doing it better
From the posters perspective some or all of the above maybe true, however from the projects perspective some or all of these statements maybe false, there are most likely people who do care about version X and who prefer that a release is done right rather than done quickly.
Enter the conundrum of what vocal users want vs what the project/silent users want.
Finding the right balance is never easy for a project, there is no magic formula to follow so that they get it right every time, all a project can can do is follow what it believes is the right course of action and hope the community agrees and follows.
This can sometimes be misinterpreted as the project not listening or ignoring feedback, but rest assured that for most projects all constructive feedback is noticed and used to help formulate decisions even if a project doesn't reply to every single post you make.
Posting comments like
- Don't bother your comment will likely be ignored
- The project team don't care so why even bother
- I wonder if the team will even bother to read this
Is a real simple way of making all of your points however valid irrelevant and easily forgettable.
So when giving feedback to a project, remember they are run by people, powered by motivation, so make sure to keep it on topic, detached from emotion and constructive, and the rest assured it will be heard.
So, to sum up the theme of this post in as few words as possible.
You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist. - Friedrich Nietzsche
PHP 5.3 and the Future
One of the topics at the front of my mind at the moment is PHP 5.3 and how I should be handling it with applications I write on a day to day basis.
It has not escaped my attention that a number of frameworks are requiring PHP 5.3+ some noticeable ones that I use or intend to use are
- Pear2
- Doctrine 2.0
- Symfony 2.0
- Zend Framework 2.0
With this comes a number of new features such as namespaces (view a complete list of changes in the Migration Guide) which I would love to start using in my own code. Whilst most of the code I write is fully forward compatible with PHP 5.3 taking advantage of the new features is where I would like to be aiming.
For the commercial applications where I am (or the customer is) in control of the environment this is a pretty simple thing to achieve. Where it becomes more difficult is when you want an application to be installable anywhere as shared hosting companies are still a long way behind.
I can understand the reasons for this as they have potentially thousands of end users to support with all sorts of different applications installed which could potentially break. It does leave application developers in a bit of a pickle though, wanting to take advantage of the latest features whilst still appealing to the large user base which open-source software attracts. I am sure most people remember the GoPHP5 campaign.
I thought I would throw some questions out there to the community to see if anyone has any thoughts:
- How can the migration path for shared hosting companies be made easier?
- If you were writing a new open-source application would you go purely 5.3+?
- Do you know of any other open-source applications requiring 5.3+?
Any feedback is gratefully received.
Jump in Camp – Day 2
Day 2 is where things start to get interesting, after a brief introduction by Yuriy Zaytsev on the hopes for the camp we got underway.
First up was Josh Holmes with an overview of Windows Azure
Whilst I had briefly looked at Windows Azure before I never really took the time to understand what it was, the overview from Josh was enlightening and made me realise that in my brief look earlier I had totally missed the point of Windows Azure.
I had foolishly grouped all cloud platforms into a single group along with Amazon EC2 when in fact Windows Azure is much more than that. Where are EC2 is almost like a dedicated server in that you control (and have to maintain/upgrade/patch) the entire software stack, Windows Azure removes all need to deal with patching of operating systems and runtime libraries leaving you to concentrate on your application.
I will be digging deeper into Windows Azure in coming blog posts.
Next up was Faith Allington with IIS / Windows Deployment. This demonstration took me a little by surprise as I had not heard of the Web Platform Installer or Web Deploy. It had also been about 6 years since I'd even dared to try and get PHP working with IIS so I was intrigued by how easy it would be since before it was a real pain in the ass.
I was pleasantly surprised however that Microsoft had been spending quite some time making the deployments easier and the tools they showed us made deploying even complicated applications incredibly simple.
By creating some simple XML files you can easily create an installation package which can handle everything from installing dependencies (MySQL for example), creating databases, configuring permissions and actually dealing with your own application configuration all from a simple Windows based UI.
This makes installing PHP applications a breeze which is an awesome thing for all the open-source PHP applications out there. Again I will be digging deeper into this cool technology in a later blog post and will also cover how we got osCommerce working via the Web Platform Installer with just a few hours work.
After some coding and lunch we back back into the thick of it with a presentation from Maarten Balliauw on SQL Azure
One of the interesting things which came out of this is that you can move your application from running on SQL Server Express (Free) to SQL Server Full Version and even to SQL Azure all without changing your database layer. The only thing which needs to be changed is the connection string for SQL Azure.
Once again it was back to some coding and quite a lot happened quite quickly. There were a few issues getting the Windows Azure for Eclipse tools working properly but once we managed to navigate over the initial issues progress quickly ensued.
After a couple of hours coding it was time for a quick break and then some fun for the afternoon. This took the guise of "Alpine Olympics" in the farm next to the Spa we were staying in.
The events which we took part in were
- Milking a Cow (Plastic not real fortunately)
- Ski-ing
- Cow-pat Golf
- Horseshoe Throwing
- Crossbow Shooting
- Blow Darts
The afternoon was a great team building exercise and allowed us plenty of time to get to know the other attendee's in much greater detail. After all teams had completed all 6 events it was time for the awards ceremony, unfortunately my team didn't win but we all got to share in the celebration drinks. Then it was time for a shower and dinner at which again the food was simply amazing.
After consuming what must of been an entire lamb by myself along with a few glasses of wine and good conversation it was time to hit the sack for the next morning we were starting at 8.30.
Jump in Camp – Overview
One of the first things I wanted to get online was a post about an exciting event which I attended recently.
I was one of the lucky developers to be chosen to attend a Microsoft "Jump in Camp" in the beautiful surroundings of Lake Zurich, I was promised interesting discussions and a good time, and I have to admit both were provided in ample measure.
Over the 4 days a number of topics were presented and discussed, these involved
- Windows Azure
- Web Platform Installer
- Windows Azure Storage platform
- Azure SDK for PHP
- SQL Server
- Silverlight
- Microsoft Live Labs Pivot
- SQL Server Reporting Services for PHP
But the camp wasn't just a talking shop, we also had time to get down to the serious business of coding some of these things into our respective projects, I will post more details on each of these things separately in the coming weeks.
I would like to thank everyone who organised and attended the camp, over the 4 days I met talented people, undertook some strange challenges and learnt more about the steps Microsoft are taking to work towards interoperability between differing technologies than I could ever of imagined.
I hope they do something like this again as I believe its a very important and productive way to get face-to-face time with the key open-source projects and people within Microsoft for the benefit of the most important people for us all "the users".
