1) Cài đặt Apache http://docs.congthoidai.com/?p=105
2) Cài đặt SVN server
yum install -y subversion mod_dav_svn
3) Tạo thư mục cho SVN
mkdir -p /var/www/svn/
3.1) Tạo repository để lưu dự án
svnadmin create /var/www/svn/congthoidai
3.2) Sau đó cấp quyền cho Apache để quản lý thư mục & tập tin của SVN
chown -R apache.apache /var/www/svn/congthoidai
4) Tạo user cho SVN và lưu trong file svn-account-users (file này bạn có thể đặt tên bất kỳ)
htpasswd -cm /etc/svn-account-users tuan
-cm là tạo ra và sửa đổi. Nếu bạn tạo từ user thứ 2 trở đi bạn dùng dòng lệnh tương tự mà bỏ đi -c
htpasswd -m /etc/svn-account-users tuan1
5) Cấu hình subversion.conf
Mở file cấu hình theo đường dẩn “/etc/httpd/conf.d/subversion.conf”
Xem 2 dòng này đã được mở ra chưa
LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so
6) Sau đó vào cấu hình cho svn chạy trên port nào.
Mở file config của apache lên “/etc/httpd/conf.d/httpd.conf”
<VirtualHost *:80> ServerName my-domain.com DocumentRoot "/var/www/html/my-domain.com" <Location /svn> DAV svn SVNParentPath /var/www/svn AuthType Basic AuthName "Subversion repositories" AuthUserFile /etc/svn-account-users Require valid-user </Location> </VirtualHost>
Lưu ý AuthUserFile : chính là file user lúc nảy tạo ra và lưu vào
7) Cấu hình svnserve.conf
Bạn mở file “/var/www/svn/congthoidai/conf/svnserve.conf” để tìm các dòng sau :
- anon-access = read sửa thành anon-access = none và bỏ dấu comment (#) phía trước
- authz-db = authz bỏ dấu comment (#) phía trước
8) Tạo cấu trúc SVN Repository cơ bản
mkdir -p /tmp/svn/{trunk,branches,tags}
svn import -m 'Initializing basic repository structure' /tmp/svn/ http://xx.xx.xx.xx/svn/congthoidai/
7) Thử check out với dòng lệnh
svn co [đường dẫn cần checkout] [thư mục chứa trên máy] --username [username]
sau đó bạn nhập mật khẩu đăng ký trên SVN
Bạn có thể tạo SVN auto update
# go to the web root folder cd /home/username/public_html/ # delete all existing files in the web root. back them up first ;) rm -rf * # do an initial checkout of the repository head svn checkout file:///svn/repo/path/to/trunk .
RewriteEngine On
RewriteRule /\.svn /some-non-existant-page
<IfModule autoindex_module>
IndexIgnore .svn
</IfModule>
# Create a new folder and c source file mkdir /svn/autoupdate cd /svn/autoupdate nano autoupdate.c
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
execl("/usr/bin/svn", "svn", "update",
"/home/username/public_html/",
(const char *) NULL);
return(EXIT_FAILURE);
}
Build file C
# Compile the c binary make autoupdate # Change the owner to the user that owns the website chown username:username autoupdate # Make the binary executable chmod +s autoupdate # Now change some files in your personal working copy and commit them to the repository so the executable can be tested # Then run the executable, it should update the files that have changed since the checkout and print out which changes were made ./autoupdate
Bỏ vào thư mục SVN
# Go to the hooks folder and edit the post-commit file, or create a new one if it does not yet exist cd /svn/repo/hooks nano post-commit
Tạo shell script file
#!/bin/sh /svn/autoupdate/autoupdate
Phân quyền cho apache thực thi file
chown apache:apache post-commit chmod 744 post-commit