As a developer, one of the things you strive for is technical parity between your development and live environment, especially on big projects, a slight misalignment in a php version or apache config can often result in a bug, minor or serious, making its way though to the screens of your clients. not what you want.
For this reason it might not be feasible to run your dev environment with the likes of XAMPP or EasyPHP. A better alternative is to run a virtual box on your local machine and ensure that the settings of the virtual match the live production server, take a look at VMWare player or Oracle’s free VM VirtualBox
With running a virtual server on your machine you are of course faced with another obstacle in getting the files into the said box in a timely and efficient manner without slowing down the speed of development.
You could use SAMBA to mount the apache web root from the VM box onto your OS drive on your local machine (eg C:projxwww ). This would enable your CVS to view the files of your project, downside being your code actually lives in the files of the virtual machine.. not ideal (if you use git and something like sourcetree on a very large project with 1000’s of files this becomes impossible as SourceTree takes too long to continually read the files in your VM).
So, enter rsync.
Using rsync to synchronise your local working copy of a project to a dev server is (from my experience) by far and away the most efficient method. When you hook this up to a ‘on save’ trigger your setup will start to fly. The bonus of this method really frees you up to have your dev server instance anywhere in the world, from a VM to a cloud in the “sky”.
You can achieve the rsync on save setup with macro in Komodo Edit, or via ANT files in Eclipse. I have yet to find a straight forward was to achieve this setup with Netbeans, and after a few reach outs to the Netbeans community I am not sure it is possible.
Example rsync command to sync files from a local folder to a remote destination (previous post on this for more detail, the setup on windows and unix is different for rsync):
rsync -avz --delete -e"ssh -p 123" /work/myproj/web_files/ email@example.com:/var/www/bob.myproj.net/
The same rysnc command in an ANT file might look like:
Setup on Komodo Edit
1 – In your project, open the right hand side bar. You should see a toolbox with the name of your project next to it:
2 – Right click on the your project (in my case ‘MyProject’). Select Add / New Macro. The macro box should appear and look like this:
ko.run.runEncodedCommand(window, 'rsync -avz -e"ssh -p 123" /work/project_x/web_files/ firstname.lastname@example.org:/var/www/bob.myproj.net/');
4 – With a very simple macro written you now need to hook it up to a trigger. Head over to the ‘Triggers’ tab and set to look like this:
That’s it. Komodo will now run the rsync command (or whatever other command) each time you save (or whatever you set the trigger to be).
Of course, Komodo Edit is not an IDE.. and as such doesn’t include a while wealth of time saving tools that might want.. (I for example love working with a code navigator that shows all the methods etc that the file opened contains, Komodo does have an IDE version but is aint free: http://komodoide.com/pricing/).
Setup on Eclipse
The setup on Eclipse is done via an .ant file like the one above. Not as simple as the Komodo implementation but fairly easy non the less.
1 – Create your ant file and save into your project files as something like rsync.ant:
2 – In your project explorer bar, right click on your project, then select properties. In the dialog box that appears, choose “Builders” on the left hand side, then choose “New…”. A new box appears, choose “Ant Builder”:
2 -Enter a name relevant to the task, eg Rsync to dev. Then select your .ant file: From the “Main” tab click the “Browse Workspace” button in the “Build file” section and select your ant file:
3 – With your ant build file selected, head over to the “Targets” tab and select “Set Targets…” next to the “Auto Build” section. You will note that the only option we have to choose from is something called ‘deploy’, this is because that is all we have in the ant file: You could add more sections to your ant file and do a whole range of things.. but we’re handling rsync for now:
4 – Save/ok your way out of the properties box. The last step is to set the auto build going. Click ‘project/build automatically’
That’s it. Each time a file is saved in the project the project will “build” automatically and run your ant file which in turn will run rsync.
I failed to find a way to get Netbeans to run an rsync command on file save. I did find an alternative, which isn’t too painfull.
1 – Create your .ant file (same as above) and save at the root of your project.
2 – Find the file in the file naviagtor on the left (or where ever you placed then window). Right click on the file, select ‘Run Target’ > Deploy.
3 – After your ant file has run once you can then re-run the same process again by clicking
Run > Repeat Build / run: Myproj(deploy) Or the shortcut being ctrl + f11
The interface of Eclipse was fairly crisp and seemed to show potential, but with two crashes in the space of an hour didn’t exactly fill me with confidence.
Komodo IDE… I did give this a try too. It’s OK. There is a code navigator which is good, but one common thread between Komodo Edit and IDE is that Komodo seems to go a little funny when you also use Mozilla Firefox… it’s as is they are colliding with something behind the scenes.. Who knows.