We will bring your website (www.domain.com) under version control. This step will create the repositories and set their permissions to allow the web user access.

It’s unlikely that you’ll want anyone to be able to access your files so we can generate a password file for SVN access:

sudo htpasswd -c /svn-repositories/passwd svn-username  

We can then create a folder, a repository within the folder and import our files:

sudo mkdir /svn-repositories/www.domain.com  sudo svnadmin create /svn-repositories/www.domain.com  sudo svn import /var/www/www.domain.com file:////svn-repositories/www.domain.com  

This repository needs to be owned by the web user and be granted certain permissions:

sudo chown -R www-data:www-data /svn-repositories/www.domain.com  sudo chmod -R g+rws /svn-repositories/www.domain.com  

We can then remove our existing site directory and recreate it from our repository:

cd /var/www  sudo rm -rf /var/www/www.domain.com/  sudo svn co file:///svn-repositories/www.domain.com  sudo chown -R www-data:www-data /var/www/www.domain.com/  

We can also create a trigger so that every time you commit a change it goes live. This probably wants some modification for production use, i.e. Local -> Staging -> Production with the later step conducted manually.

sudo nano /svn-repositories/www.domain.com/hooks/post-commit  
#!/bin/bash  cd /var/www/www.domain.com /usr/bin/svn update 

This also needs the correct permissions to run:

sudo chown www-data:www-data /svn-repositories/www.domain.com/hooks/post-commit  sudo chmod +x /svn-repositories/www.domain.com/hooks/post-commit  

We also need to add this repository to a vhost file so that you can check it out. I would suggest a new one for this purpose. Multiple locations can be added, but for now we just have one.

sudo nano /etc/apache2/vhosts/svn.domain.com.conf  
         ServerAdmin webmaster@domain.com         DocumentRoot /var/www/default/         ServerName svn.domain.com                          Options -Indexes FollowSymLinks                 AllowOverride FileInfo                 Order allow,deny                 Allow from all                  domain.com>         	DAV svn         	SVNPath /svn-repositories/www.domain.com         	AuthType Basic         	AuthName "www.domain.com subversion repository"         	AuthUserFile /svn-repositories/passwd         	Require valid-user          

Before this can be tested Apache needs to be reloaded:

sudo service apache2 graceful  

You can now check out the repository from “http://svn.domain.com/svn/www.domain.com” using the command line or client (Linux / OSX) or a client such as Tortoise SVN on Windows. You will need to validate using the username / password that you created in this step. If you would rather use the .htpasswd file used for the database and mail admin just update the vhost file with that location.

 

Articolul original: aici

Tags: