下面由Centos入門教程欄目給大家介紹centos上搭建SVN并將項目同步到PHP項目的系統(tǒng)根目錄的方法,希望對需要的朋友有所幫助!
一、SVN安裝
這里采用yum安裝方式:
1、rpm -qa subversion //檢查是否安裝了低版本的SVN
2、yum remove subversion //如果存儲舊版本,卸載舊版本SVN
3、開始安裝yum -y install subversion
安裝好后查看版本svnserve –version
4、創(chuàng)建版本倉庫:
mkdir -p /data/svn/project svnadmin create /data/svn/project/
查看/data/svn/project 文件夾可以發(fā)現(xiàn)有conf, db,format,hooks, locks, README.txt等文件,說明一個SVN庫已經(jīng)建立。
5、配置權限
cd /data/svn/project/conf/ //進入配置目錄 vim svnserve.conf //編輯配置文件,加入下面五行內(nèi)容 ``` [general] ### The anon-access and auth-access options control access to the`` ### repository for unauthenticated (a.k.a. anonymous) users and ### authenticated users, respectively. ### Valid values are "write", "read", and "none". ### Setting the value to "none" prohibits both reading and writing; ### "read" allows read-only access, and "write" allows complete ### read/write access to the repository. ### The sample settings below are the defaults and specify that anonymous ### users have read-only access to the repository, while authenticated ### users have read and write access to the repository. # anon-access = read # auth-access = write anon-access = none auth-access = write password-db = passwd authz-db = authz realm = /data/svn/project ```
6、編輯密碼文件,添加用戶test 密碼123456:
vim passwd ### This file is an example password file for svnserve. ### Its format is similar to that of svnserve.conf. As shown in the ### example below it contains one section labelled [users]. ### The name and password for each user follow, one account per line. [users] # harry = harryssecret # sally = sallyssecret test = 123456
7、編輯權限文件,添加用戶test權限
vim authz [groups] # harry_and_sally = harry,sally # harry_sally_and_joe = harry,sally,&joe [/] test = rw
8、配置防火墻
vi /etc/sysconfig/iptables
加入:
``` -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp -dport 3690 -j ACCEPT ```
重啟防火墻:service iptables restart
9、啟動SVN:svnserve -d -r /data/svn/
查看端口狀態(tài):netstat -ln | grep 3690
二、給svn添加鉤子同步文件到PHP測試環(huán)境 (這里PHP項目目錄為/var/www/html/project/)
1、進入版本庫下的hooks目錄
cd /data/svn/project/hooks/
2、將post-commit.tmpl 復制為 post-commit
cp post-commit.tmpl post-commit
3、給post-commit可執(zhí)行權限
chmod 0777 post-commit
4、編輯post-commit,注釋掉#mailer.py……這一行,添加下面四行,編碼問題,如果錯誤的話可能導致無法同步 成功,可選的有en_US.UTF-8、zh_CN.UTF-8、zh_CN.GB2312,可以一個個試。
vi post-commit #mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf export.GB2312 SVN=/usr/bin/svn STATIC_DIR=/var/www/html/project/ ${SVN} update ${STATIC_DIR} --username "test" --password "123456"
5、在提交之前,進行一次checkout代碼到指定目錄
svn checkout svn://localhost/project /var/www/html/project/
注:如果一直出錯:“由于連接方在一段時間后沒有正確答復或連接的主機沒有反應,連接嘗試失敗”;可能是網(wǎng)絡端口開放設置問題,因為端口問題導致無法成功checkout項目,可以進入阿里云看看看看有沒有允許3690的端口,如果沒有3690的端口就添加一條安全組規(guī)則。