gabe
gabe

Reputation: 1950

How can I use svn+ssh in a PHP script?

i can't figure out how i should access the repository from a CakePHP project called fredistrano (you can do CakePHP deploys with a web 2.0 interface). i have fredistrano in my web broadcasting directory on a shared unix web server. when i use tortoisesvn from my laptop, i have to use svn+ssh://[email protected]/svnpath/trunk/. i tried using the same thing in fredistrano, but i keep getting the svn command error "svn: Network connection closed unexpectedly". i copied and pasted the command: svn export --non-interactive --username myusername --password mypwd svn+ssh://[email protected]/home/myusername/svn/mydomain.com/trunk tmpDir 2>&1 into my SSH terminal connected to the shared server and i get a prompt for a password, which i believe is actual a prompt for the SSH password and not the SVN password (see this post). fredistrano is failing because it can't deal w/ the SSH password prompt. i noticed in the fredistrano documentation that the example uses http://ipaddress/svn/test for the SVN URL. i copied my svn to my web broadcasting direrctory and tried this but get a connection refused error. my shared hosting provider is pretty strict and i doubt that i can use that. is there a way i can get svn+ssh to work w/ a PHP script like this (fredistrano is just using shell_exec() to execute svn commands)? is there a way i can get just get svn, http, or https working (or any other method that i don't know about)?

Upvotes: 3

Views: 951

Answers (4)

Martin Zeitler
Martin Zeitler

Reputation: 76749

maybe check out the Subversion PHP Module (1.0.3) instead of wrapping shell_exec; it requires building from source, with phpize, ./configure and make (just built it against PHP 5.6 and Subversion 1.9.5)... while the Apache Module mod_dav (Subversion via HTTP/HTTPS) is not required for version control, rather an optional method of accessing the repository.

Upvotes: 0

Oliver Maksimovic
Oliver Maksimovic

Reputation: 3262

I am interested in this problem, too, and I hope that I'm close to the solution.

I haven't tried to put it into work in my application due to the lack of time and other high-priority tasks, but I guess that it should look something like this:

shell_exec(svn something svn+ssh://...)

$response = trim(fgets(STDIN))

[then check if the response contains password prompt text]

fwrite(STDOUT, 'yourpassword');

[analyze the next response and see if SVN has returned the requested information - log, info, whatever]

Upvotes: 1

troelskn
troelskn

Reputation: 117567

How do you authenticate from your dev machine to the svn-server? You might be using a key to authenticate (Do you have putty pageant running?)

Upvotes: 0

Koraktor
Koraktor

Reputation: 42923

"svn: Network connection closed unexpectedly" most probably means that your host has restricted/forbidden access to other hosts. This might imply using sockets at all (SVN, HTTP, etc.) or maybe only non-HTTP. In this case you should try setting up your SVN server to allow HTTP requests (e.g. using mod_dav_svn for Apache).

This is only a guess - see my comment to your question.

Upvotes: 0

Related Questions