Running SVN commands from PHP webpage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
selahlynch
Forum Newbie
Posts: 5
Joined: Tue Jan 25, 2011 8:40 am

Running SVN commands from PHP webpage

Post by selahlynch »

Hello,

I am trying to run the command "svn info" from a php webpage.

Code: Select all

exec("svn info /var/www/html/appdir", $stddout, $succ);
The svn command works if I paste it into a terminal, however, when I run it from my PHP code, it fails.

Here is the error message...
svn: Can't open file '/root/.subversion/servers': Permission denied

I understand that when I run these commands from the webpage, I am running them as apache, not as myself, so that is why the same command works in my terminal, but doesn't work from my webpage.

How can I overcome this?
selahlynch
Forum Newbie
Posts: 5
Joined: Tue Jan 25, 2011 8:40 am

Re: Running SVN commands from PHP webpage

Post by selahlynch »

And to follow that up, I see there are some suggestions on the web:

1) There is an svn option --config-dir where one can specify an alternate config directory for apache to use. The problem is I do not know of any available config directory that apache can access.

2)I also saw some recommendations having to do with using putenv() but I'm not sure just what environmental variable I should set.

3)I saw a recommendation to "configure apache user for subversion" but I do not know how to do this either.

Any advice would be very much appreciated!!
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Running SVN commands from PHP webpage

Post by Weirdan »

what kind of svn operations you're planning to use? Can you install additional extensions on your server?
selahlynch
Forum Newbie
Posts: 5
Joined: Tue Jan 25, 2011 8:40 am

Re: Running SVN commands from PHP webpage

Post by selahlynch »

I'm planning on using the command "svn info".
I am able to run this command just fine on the server when I am a normal user. It only does not work when I am the apache user.
I'm not sure why I would need any additional extensions.
selahlynch
Forum Newbie
Posts: 5
Joined: Tue Jan 25, 2011 8:40 am

Re: Running SVN commands from PHP webpage

Post by selahlynch »

Okay a solution, maybe not the best, but a solution none the less.
I copied the entire .subversion directory from a normal user's home directory and put that in my /var/www/html html directory.
Then I altered my command to be

Code: Select all

exec("svn --config-dir /var/www/html/.subversion info /var/www/html/appdir", $stddout, $succ);
Now it works.
selahlynch
Forum Newbie
Posts: 5
Joined: Tue Jan 25, 2011 8:40 am

Re: Running SVN commands from PHP webpage

Post by selahlynch »

Today I discovered the PHP SVN module and that proved to be a better solution than my previous one.
Perhaps that is what you were suggesting, Wierdan? I'm sorry I didn't investigate further at the time... but thank you for the response.
http://us.php.net/manual/en/book.svn.php

Now I have code that looks like this:

Code: Select all

$loginfo = svn_log("/var/www/html/selahtemp/includes");
$lastrev2 = $loginfo[0]['rev'];
echo "<br />Last Revision from svn_log() = $lastrev2 <br />";
Hooray :D
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Running SVN commands from PHP webpage

Post by Weirdan »

selahlynch wrote:Today I discovered the PHP SVN module and that proved to be a better solution than my previous one.
Perhaps that is what you were suggesting, Wierdan?
That was one of the options I had in mind, yes.
Post Reply