简体   繁体   中英

How can I set up an SVN repository “on the fly” programmatically?

I'm setting up a system (PHP-based) that will let users instantly provision an SVN environment for use. It's an internal project so the users will mostly be internal users.

I haven't the foggiest idea where to even start. Are there SVN bindings for PHP, or am I going to have to use the svn console command?

Here's one possibility. You'll have a couple steps here. First, you need to create the svn repo in your PHP action script, maybe something like:

$name = $_REQUEST['name'];
// gonna need some sanity checking on $name here. no '..', no '/'s, etc
$cmd = 'svnadmin create ' . escapeshellarg('/var/svn/' . $name) . ' --fs-type fsfs';
exec('sudo ' . $cmd, $output, $exitValue);
if ($exitValue != 0) {
    // put the error message on the session, redirect out
}
$cmd = 'chown -R apache:apache ' . escapeshellarg('/var/svn/' . $name);
exec('sudo ' . $cmd, $output, $exitValue);
// error handling again

You'll need to set up sudo to allow your web server to run that svnadmin command. Then you'll need to drop in a new apache.conf snippet in /etc/httpd/conf.d:

<Location /$name>
   DAV svn
   SVNPath /var/svn/newproj
   #AuthType Basic
   #AuthName "SVN Repository"
   #AuthUserFile /var/svn/${name}.passwd
   #Require valid-user
</Location>

and restart Apache. Maybe create that newproj htpasswd file too for security. Be sure to check and sanitize all passed form values ($_REQUEST). Hope this gets you started.

Make it execute svnadmin create reponame to create the repo. I don't think there are any libraries for this because you generally only find client side SVN libraries.

Just to make a suggestion "provisioning" Git repos is much simpler. And since there is no difference between client and server, your handling through git libraries ( http://code.google.com/p/git-php/ ) etc is very straightforward. Of course you may only want SVN repos, but if you have the choice, go for git.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM