4

I have two scripts.

  1. running an update and calling shell_exec('svn update') and shell_exec('svn st')
  2. running a mysqldump shell_exec('mysqldump params')

The svn script is not running the update command, the svn st is printing results but not the svn update

I tried to declare parameters when calling svn update eg 'svn update ' . dir . ' --username myuser --password mypasswd --non-interactive'; -- still nothing Played with most of the params

If this is something related to binaries/permissions/groups, I don't see it. The mysqldump command works fine and is producing a file, so why isn't the svn updating the filesystem?

Please do not advise using core SVN classes in PHP. This is not an option, I don't have complete control over the server and the module is not available.

Thanks for your help,

-hbt

PS: important thing to mention here. The scripts works when called via the command line. It only fails when called via a web browser.

hbt
  • 1,011
  • 3
  • 16
  • 28
  • Are you sure that result of `shell_exec('svn update')` is empty when called from web browser? Most likely it is permission problem (different users for svn working directory and http processes), but in this case there should be error like "svn: Can't open file '.svn/lock': Permission denied". – Alexander Konstantinov Jun 01 '10 at 07:25
  • Have you already tried capturing the output and dumping that to the screen/look at the output when debugging? ie. `$output = shell_exec('svn update ...'); print_r($output);`. Are you sure you didn't forget to reference the folder as a variable (since the example given contains dir instead of $dir, unless dir was defined as a named constant of course). – wimvds Jun 01 '10 at 07:25
  • @alexander Issue with permission indeed. It was the .svn directory. The svn update command is trying to write stuff in there. Thanks for your help – hbt Jun 02 '10 at 10:58
  • @wimvds Yes, the example was written on the fly. print_r returns empty for `exec` command , var_dump returns null for `shell_exec` command. I figured it out though. Posted answer below. Thanks for your help – hbt Jun 02 '10 at 10:59
  • I have found another way that works smoothly. http://stackoverflow.com/a/8532448/2805783 – donquixote Jan 26 '14 at 23:12

6 Answers6

4

I was also encountering the same problem but not even permissions solved it.

Based on some of the other advice here, I did:

<?php
echo shell_exec('2>&1 svn update /path/to/checked/out/directory/ --non-interactive');

I then got an error dumped into my browser:

svn: warning: Can't open file '/root/.subversion/servers': Permission denied
svn: OPTIONS of 'http://my.svn.server/svn/project/trunk': authorization failed: Could not authenticate to server: rejected Basic challenge (http://my.svn.server)

Not sure why my web server user tried to access /root but I fixed the problem without changing any permissions by adding --config-dir to the svn up command:

<?php
echo shell_exec('2>&1 svn update /path/to/checked/out/directory/ --non-interactive --config-dir /path/to/my/home/.subversion');

*Note that /path/to/my/home/.subversion exists because the initial checkout was done on the command line

Deadpan110
  • 63
  • 5
3

to get the standard error in the return value use :

shell_exec('2>&1 svn update')

it doesn't work if you put the 2>&1 at the end

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
Cactusbone
  • 1,056
  • 8
  • 20
1

It might be permission problem: script called via a web browser runs under different username than svn working directory's owner, therefore it has read-only access. Read-only access should be enough for svn status to execute, but not for svn update (though in this case there should be an error like "svn: Can't open file '.svn/lock': Permission denied").

Alexander Konstantinov
  • 5,406
  • 1
  • 26
  • 31
1

Have you tried the PECL svn extension? You don't need to use shell_exec for this.

Artefacto
  • 96,375
  • 17
  • 202
  • 225
1

OK. I got it. It is an issue with permissions. The .svn directory must have the right permissions because the svn update command is using those directories to write stuff.

So! ---Make sure you run all chmod commands as sudo or root----

  1. run a chmod 777 on .svn directory
  2. run an svn update via command line
  3. call script

If nothing. You must run chmod 777 recursively for all .svn directories then run another svn update

Still nothing?

Make sure you don't have two svn clients In my case, the svn client used by the UI is different from the svn (command line) If you have two clients, make sure they are running the same version Or update your script to call the client directly.

Still nothing?

Run a chmod 777 -R * svn update and try again

If you can make it work with another set of permissions, please let me know. I know that 777 is not ideal, but I can't make it work with something lower.

Thanks again guys.

hbt
  • 1,011
  • 3
  • 16
  • 28
1

Yes, the problem is the permissions with the .svn directory.

Make sure it has the correct permissions for the user that PHP is running as (in my case it was apache) and chmod it to 775.

jrouquie
  • 4,315
  • 4
  • 27
  • 43
Octavio
  • 11
  • 1