We have a PHP project that we would like to version control. Right now there are three of us working on a development version of the project which resides in an external folder to which all of our Eclipse IDEs are linked, and thus no version control.
What is the right way and the best way to version control this?
We have an SVN set up, but we just need to find a good way to check in and out that allows us to test on the development server. Any ideas?
We were in a similar situation, and here's what we ended up doing:
Set up two branches -- the release and development branch.
For the development branch, include a post-commit hook that deploys the repository to the dev server, so you can test.
Once you're ready, you merge your changes into the release branch. I'd also suggest putting in a post-commit hook for deployment there.
You can also set up individual development servers for each of the team members, on their workstations. I find that it speeds things up a bit, although you do have some more setup time.
We had to use a single development server, because we were using a proprietary CMS and ran into licensing issues. So our post-commit hook was a simple FTP bot.
Here is what we do:
Each dev has a VM that is configured like our integration server
The integration server has space for Trunk, each user, and a few slots for branches
The production server
Hooks are in Subversion to e-mail when commits are made
At the beginning of a project, the user makes a branch and checks it out on their personal VM as well as grabs a clean copy of the database. They do their work, committing as they go.
Once they have finished everything in their own personal space they log into the integration server and check out their branch, run their tests, etc. When all that passes their branch is merged into Trunk.
Trunk is rebuilt, the full suite of tests are run, and if all is good it gets the big ol' stamp of approval, tagged in SVN, and promoted to Production at the end of the night.
If at any point a commit by someone else is made, we get an e-mail and can merge those changes into our individual branches.
Beanstalk has built-in post-commit hooks for deploying to development, staging, and production servers.
One way to use subversion for PHP development is too setup a repository for one or all three developers, and use this repository, more as a syncing tool, than true version control.
You could,
Make a repo
Add your entire PHP document structure of your project
Checkout a copy of this repo into the correct spot on your dev server
Use an svn hook, that activates on commit
This hook, will automatically update the contents of the dev sever, whenever anybody on the team checks in any code.
Hook resides in:
svn_dir/repo_name/hooks/post-commit
And could look like:
/usr/bin/svn up /path_to/webroot --username svn_user --password svn_pass
That will update your working copy on the dev server to the latest check in.
What about something distributed? You can start for example with Mercurial, try different workflows, and see which one fits you the best.
Each of you could run it locally, or on your own dev server (or even the same one with a different port...).
One possible way (there are probably better ways):
Each of you should have your own checked out version of the project.
Have a local copy of the server on your computer and test it there throughout the day. Then at the end of each day (or whenever), you merge together whatever you are ready to test, and you check it out onto the dev server and test it.
Another tool you can use for the builds is TeamCity which is free for 20 build configurations (enough for most small companies/projects.) This way you can run your tests as well as schedule builds.
Related
I had just implemented GIT Version Control for a Team of three people. We are managing to pull/push/fetch etc to our bitBucket repository. My only concern is how I should push live after we make an update to the repository.
On another server, I wrote a shell script to clone the repo into a directory so I would be able to test, but on the live server I cannot do the same since on some occasions I just have to push one file only.
Please note that our live server is inside a network and not accessible over the internet (thus I cannot use BitBucket's push service).
The only advise I can give is to make sure that the local repository (which concentrates changes from the developers) is up to date and in shape before pushing.
Locally you can define your workflow. Perhaps the master repo, into which only official commits are taken, branches for each developer's work once it passes local tests, and each one does as they please on their machines. Or something fancier. There are suggestions on workflows, ranging from almost centralized to completely distributed, check them out. If you adopt one way of working, git won't stand in your way if you decide later to change it.
Recently we have started exploring GIT with the target of enabling our developers to work from any place and secondly to automate the overall deployment process.
We have a central test server where we host all apps/sites for testing and/or demo purpose and once the development and testing is finalized we move the application to their respective live servers.
Whatever i have set up with GIT, is as follows
1. Create a bare repo on test server
2. Get a local clone for each involved developer, Developers will push to remote(test server) dev branch
3. Someone will merger all changes from dev branch to master branch and push it to remote
4. The test server (bare repo) has a post-receive hook, which checks out the master branch to public_html folder (using GIT_WORKING_DIR and checkout -f).
As of now, everything works good and i am able to see merge on master branch on hosted pages (on test server, of course). Now my questions are ...
1. Am I doing this right?
2. I guess the post-receive hook I have set, executes on push to dev branch as well. How to avoid this?
3. How I can ship these contents to my live server? As I have some projects with large code base, checking out everything on test server and then ship it to live doesn't looks good enough.
I've heard of CI servers, but as much as I know they check out locally and upload everything to live using 'rsync' (don't know if it just syncs changes or uploads everything) or such tools. I just want to avoid that everything part and keep an option open to rollback, if anything goes wrong. I am good with setting up git on live servers.
Yes. You can see other considerations at "reset hard on git push".
You can test the name of the branch when receiving the commits.
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
See also "Writing a git post-receive hook to deal with a specific branch"
a rsync is usually recommended for live server (where git isn't necessary): it will update only what has changed.
If you have git on live server, then various approaches are described in "Git for Websites / post-receive / Separation of Test and Production Sites"
Regarding deployment, as seen in "Deploy with rsync(or svn, git, cvs) and ignore inconsistent state during deployment?", deploying (even everything) in a separate directory and symlink the prod instance to that directory is a nice way of avoiding inconsistencies during deployment, and to facilitate rollback (symlink back to the previous live directory) in case of trouble.
I am an avid webdev hobbyist and freelance, up until now I simply edit the website live (put a maintenance message up while its being made), now all my projects up until now have also been very small.
eg I make a site, show em, take money and go, I've never had to work on a site after it's gone live.
Now my new project is pretty big and I know I will have to edit it after its gone live and maybe have a small team of devs (atm just me)
So how do people professionally handle this? I know I will need a prefix-amp app cos i run an apache server, I've also heared that people use github for versioning, but I'm not really sure because apparently its not svn?
Thanks
ps. I have a windows 7 pc, so no mac apps please
up until now i simply edit the website live
Terrible in my book ;)
so how do people professionally handle this?
First you need to setup a development server (it would be best to keep it as close as possible to the expected live environments). On this server you would install all the software you need.
You may also want to setup a staging server.
i know i will need a prefix-amp app
I hope you are not talking about those one click installers. If you would do it professionally you should install everything yourself that way you can set it up the way you need it.
ive also heared that people use github for versioning, but im not really sure because apparently its not svn?
GitHub is just a website. What you are looking for is git or svn for versioning. You could also setup a git or svn server locally instead of using services like GitHub. Basically what versioning is is that when somebody makes a change to the code he/she would need commit the changes. This way it is easy to keep track of changes in the codebase (like what was changed, when was it changed and by whom).
Local XAMP-stack (LAMP, or WAMP) for development
intranet-system for test and maybe staging
Of course the live system
Versioncontrol, I prefer git. Of course you can use SVN too, but... lets say: It's SVN.
Make changes local, test this changes local
everythings fine: Push it into the "master" vcs-repository
New version ready (or it's "sunday-night-release-time")? Push all that stuff on test/stage
Everythings fine there too: Push it into the live system
Thats very shortened of course, but it should give you an idea.
The tool where you manage your software version is not that important. Use Git, or SVN or whatever, the one you like most. But use _one_.
Equally important is that you run the "page" on two sites, a test and a live system, strictly apart. Both systems have to be very close in their layout, all changes must first be done in the test system, be verified and then done in the same manner in the live system. Do not allow changes only to be made to the live system ('cause it's just a small change'). No exceptions.
Then think about deployment: how will you transfer changed files to the target system ? You need routines for this, that run once started and don't forget a step in between.
Firstly you need some kind of versioning system: either SVN or Git. GitHub is simply an online service that provides managed Git repositories. Secondly you need a development server.
If it were just you doing development, you could host both of these on your local desktop PC, but since other developers are going to be joining, you need a remote server. If you don't want to be running a server out of your home, the best option is a VPS (virtual private server) on which you can install Git, Apache, etc. and anything else you need.
As for development software, take your pick- there are loads of options. A common choice is the NetBeans IDE and TortoiseGit combo. You use NetBeans to develop your code on, automatically uploading to your development server, then you TortoiseGit to commit and sync changes.
Only when you're ready to go live do you copy the code from the dev server to the production server.
This is the 3rd web project I have been developing and I have been a sole developer in all projects.
Now I need to change my style and don't know how to do it, so I need your suggestions.
My setup is;
Netbeans for PHP development
Github for private repository (As I am developing on Windows I found very hard to integrate Git-Windows-Netbeans so I can change it if needed)
Basecamp for project management (Even if I use GIT, I might change my GIT provider (github) and select a one which can be integrated with Basecamp)
My needs are;
For my current project, I will setup a dev server and test the changes there first. Then I will commit them to the production server. So I should be able to use netbeans while I can easily commit to my repository and apply the changes to the production server. How can I do it easily? Should I first commit to the repository and get the changes from the dev. server via command line? It seems a bit work to do this for every change. Should I directly upload to the dev. server, then commit the final changes to the repository and get the changes from there to the production server?
So, what do you suggest as a repository which can be integrated into the netbeans and how should I manage these changes?
I also would like to use one of these providers (http://basecamphq.com/extras - SOFTWARE DEVELOPMENT TOOLS). So, if you have any suggestions from these companies too, that would be great
Thanks a lot,
Everyone's tastes vary.
There are many IDE/Editors, different version control systems, and even different methods of deploying to a live server.
So really the best way is to just experiment with different methods until you find one that suits you.
I will tell you how i do it, and take from it what you want.
And im sure this will be downvoted by certain people, but its what i found to suit me best.
My editor of choice is vim, but i also like Eclipse with the PDT plugin. Eclipse isn't as "snappy" as netbeans (at least on my computer), but its very nice.
I use SVN for my version control, this is just something that i have been using for years and i am comfortable with.
To deploy the latest code to my live servers i check out the trunk of my svn repo on my live server, for small changes i just commit them directly to trunk, but for larger changes i branch off the code to change, and then merge it back into trunk when its ready.
Then all i need to do is issue a "svn update" on live, and the new code gets checked out of the svn.
To avoid ssh'ing into the machine, this can even be called from a php script, from a protected file somewhere.
<?
$svnuser = username;
$svnpass = pass;
$returnString = exec("svn --username={$svnuser} --password={$svnpass} update 2>&1",$output,$returnVal);
header("Content-Type: text/plain");
print("Return value: {$returnVal}".PHP_EOL);
print("Return String: {$returnString}".PHP_EOL);
foreach($output as $line){
print($line.PHP_EOL);
}
?>
I m setting up SVN on my local web development server and I'm wanting to create a post-commit hook that exports the repo to the production server (either via FTP, SSH, etc) when the commit message contains the word "deploy" or something similar. I know this has to be a common function for SVN but I can't seem to find anything that does just this. Maybe another set of eyes will lead me to the correct solution...
Thanks in advance!
One thing I have done (on projects specifically designed for this type of release) is to checkout the project into my production server, then do an svn update on it when the code is ready to be moved to production.
As others have suggested, I'm not a huge fan of this. I've written post-commit hooks that update third-party ticketing, etc. systems via their HTTP APIs, and I'm not thrilled at the time it takes to actually commit a revision that matches the criteria--I think I'd be less thrilled if I had to wait for it to upload actual binaries to another server, even if it were on the same subnet. We also currently check in our builds from the build server and just check them out on the deployment servers, which is easily automatable.
Check out the documentation on post-commit hooks, as well as some basic examples. A google search for "svn post-commit hook" pulls up lots of examples.