Php deployment to remote server using FTP from SVN after each commit
Asked Answered
K

9

17

I coudn't find the solution for Php deployment to remote server using FTP from SVN after each commit. How can I upload to server by FTP the only added or edited files and delete the deleted files from SVN I think about write post-commit script...

Kyliekylila answered 9/4, 2010 at 11:46 Comment(3)
Post-commit script hooks is correct, but you should not use FTP but rsync to transfer over to the new hosts. FTP cannot determine what was edited and what was not. Checkout Phing, like Pekka suggested and this blog post: blog.fedecarg.com/2008/07/21/…Lasala
If you can, consider using SVN on your remote server as well. Give it read-only restricted access and install a post-commit hook on the repository that notifies the remote server to first revert and then update its working copy. In this case, you may also want to deny web access to any .svn folders. Additionally, consider using branches to make sure the server does not check out every commit from trunk.Branny
I dont believe the solution needs to be PHP based, just for the transfer of a php website.Doom
D
13

Good question!

I'm not sure a PHP-only approach to syncronizing files that way exists.

I would usually use third-party FTP sync tools like rsync or ScriptFTP (commercial) to do the syncronizing part.

Take a look into phing, there are a number of FTP extensions (called "tasks") for it. I have no real world experience with them though.

This blog post offers a number of ideas and approaches: Using phing to sync files with shared hosting

Docker answered 9/4, 2010 at 11:51 Comment(1)
I'm not using Phing but Ant, and the result is I can only copy all new source from SVN to remote server. Not just synchronize files from the new commit. Remote servers can be Windows OS so I can not use rsync. I just want to simulate the deployment process of Springloops.com They're just perfect doing that.Kyliekylila
Z
6

You could use svn2web to upload every commited file to a server via Ftp. Svn2web is a collection of php-scripts that you can use as svn hooks. You can set the address, username and password of the ftp-server as an svn property on a directory. Works great!

Zoon answered 9/4, 2010 at 12:30 Comment(2)
Thanks for your answers. But the commit can delete some files on svn. And I need to synchronize the svn with deployment server.Kyliekylila
if you delete files in your repository svn2web will delete those on the ftp as well. Isn't that a good thing?Zoon
E
3

I use http://svn2ftp.com which is a SVN host that allows remote deployments to S/FTP on each commit!

Erikerika answered 18/1, 2011 at 13:29 Comment(0)
Q
3

If you don't want to manage the scripts by yourself, but just want something that works, you could try using a hosted service. I use Deploy, which works perfectly for the scenario you describe. And if you only have one project to deploy, it's even free.

Qatar answered 23/4, 2012 at 23:52 Comment(0)
P
2

For our php project we use Jenkins a continuous integration tool. Our repository server is subversion. Whenever we do code changes, we use jenkins jobs to merge with the Beta staging & live environment and then deploy the application.

You can find more info on PHP application deployment using Jenkins on http://www.michaelpeacock.co.uk/blog/entry/jenkins-ci-an-introduction-for-php-developers

Phenosafranine answered 26/4, 2012 at 6:30 Comment(1)
I like your answer, Thus you have my bounty.Doom
Z
1

mybe cron + bash script which will be svn up ?

Zeal answered 25/4, 2012 at 18:26 Comment(0)
O
1

Have you looked into Beanstalk? It lets you deploy your Subversion and Git projects to your FTP server in one click. Its not free though. Another free alternative would be to setup a continuous integration server which would run a rake script to do your deployments.

Oxygenate answered 26/4, 2012 at 0:6 Comment(0)
R
1

What do you say , you checkout from SVN to you'r server , ( create working copy from the SVN to the production server ) , and when ever you want to deploy a new version , you just connect to the server via SSH and type svn update , and there you go , only the latest files that have been edited are going to be deployed , and in a less then a second you have the latest version updated in production.

Recidivate answered 26/4, 2012 at 9:55 Comment(0)
R
0

The best way is (if your server is Linux based) to make an SVN Export to a new directory and then move the new directory to replace the old one (best way to do it is with symbolic links to different versions of the site). This way the site would be unavailable for a second or two, while if you rsync and have a big site, if you change drastically single file, the site would be broken until all files sync.

As for firing this procedure, the best way is to use svn hooks. Also consider doing some automated testing before release-ing (for basic functionality), because you can break your trunk pretty badly some time and the site would definitely be down :)

We are currently incorporating the approach described above in a production environment and the setup is as follows:

  • A commit goes in the trunk
    • Before it's actually commited, tests are ran on the code to see if everything works
  • After several commits a deploy comes (usually developer supervised)
    • Tests are run again
    • If they are successful - all ok
    • If they fail, old export is returned and the site is fully operational once again

It's all written in PHP, by using standart console commands.

Robbinrobbins answered 9/4, 2010 at 12:38 Comment(2)
I don't want to export all the files in new version on svn to the remote deployment folder. I just want to synchronize by upload new files, overwrite edited file and also delete files according to the commit. please show me an exampleKyliekylila
Well then, why don't you make your production web site a svn checkout and just update it when you commit? Also you should ban access to .svn folders and it will work exactly as you want it. And if the SVN repository is on the same server as the web-site it's simple as making /path/to_svn/repos/someproject/hooks/post-commit look like: #!/bin/bash <newline> svn update /path/to/website <endfile> and make it executable.Robbinrobbins

© 2022 - 2024 — McMap. All rights reserved.