Create a Subversion server by Michael

Source: Internet
Author: User
Tags version control system tortoisesvn

I learned about SVN when I was doing an embedded experiment in my junior year. However, the code is usually written at will without proper management. As a result, version management is very messy and many modifications are untraceable. Recently, I just want to help my lab write something, and it is just because the Spring Festival is full of time. I plan to take some time to study it. So I found a good article on the Internet and specially reproduced it for future reference. Original article from:

Http://bemike.org/posts/258

Http://bemike.org/posts/260

Http://bemike.org/posts/261

Http://bemike.org/posts/262

**************************************** **************************************** **


Create a Subversion server


Directory:
· Preface
· Create your own repository
· Use svnserve to create a Subversion server
· Create A Subversion server under Apache

1. Preface

As I have said before, subversion is a very good version control system. If you are not familiar with version control, let me explain it briefly. For example, I have a project with hundreds of files, including project-related documents, charts, and video and audio files, all of which are placed in a folder on my computer. As the project develops, new documents, charts, and other files will be added to the folder, the old files will be modified, and some files may be deleted. In the version control system, every change to the project folder is recorded. If a file is deleted incorrectly or you want to restore the file to a previous version, it can be easily achieved. What's more, if the project is executed by a team, every member of the team can manage and synchronize the files in the project, in this way, you can always on the same page.


If I am not clear, refer to the revision function of Google Docs. For a document, you can go back to the previous version. This is a simple version control. In essence, subversion is the same as Google Docs, but the difference is that subversion is more flexible and powerful.

For ordinary personal applications, subversion servers can be built on their own computers, and they are very simple, because there is no need to consider security factors, therefore, you do not need to set related authentication programs. If you want to put the "project folder" (I don't know how to translate it, I want to change it to repository or repo) on the LAN or even on the Internet, it will be more complicated.

In addition to this preface, I have prepared three articles to explain how to create a Subversion server. Both Windows and Linux are applicable, because I have been using Linux for the past few days, the same is true in windows. You only need to change the path format to Windows.


2. Create your own repository

2.1 Basic Knowledge


Subversion (SVN) has two concepts: Repository (repo) and working copy (WC ). The former is where the project is located, and the latter is where you make changes. The content of the two can be identical or different, both are displayed as folders or directories on the computer. The changes you made in WC can be commit to repo. If you successfully commit the content in wc to repo, the repo will automatically update a version (revision ). If you do not perform the commit operation, any modifications you make on WC will not affect the project. If you want to, you can replace WC with any revision (including earlier versions) at any time ).

To use SVN, install it first. For Ubuntu users, enter the following directly at the terminal:
Sudo apt-Get install Subversion
To download the Windows version, go to the download page for windows. We recommend that you download the. Zip package and decompress it directly.

In Windows, it is best to add the svn execution file path to the PATH environment variable so that it can be used normally in any path. You will soon find out that, this is important.

2.2 create your own Repo

If I want to create a WordPress topic, I need to create a repo for the files in the creation process so that I can "Go back to the past" whenever necessary ". The Directory of the created topic is/Foo/bar. I want to create a repo under/home/Michael, so I need to do this:
# Create a repository named theme
Svnadmin create/home/Michael/theme
# Import the content under/Foo/bar to theme and create a repo. The repo version number is 1.
SVN import-M "first import"/Foo/bar file: // home/Michael/theme

From then on, if you want to checkout the repo just created on the local computer, you only need to enter it in any path.
SVN checkout file: // home/Michael/theme Baz # create a working copy named Baz

A working copy is created. For Windows, you must change the path format to file: // X:/path/to/repo. X: The drive letter of the repo.

You can modify it at will in WC. If you are not satisfied, you can use the svn revert command to restore it. When appropriate, you feel that you need to submit your changes to the repo. You can use:
SVN commit-M "blah"

In this way, a new version is generated ." Blah blah "is an annotation for this new version.

2.3 SVN command

Note that when you perform file operations under WC, such as deleting or moving files, you cannot directly use rm or mV. In this way, SVN cannot track file changes, you must use SVN del or SVN move to delete or move the data. The following is an example of a few commands:


SVN add filename # Add a file
SVN move filename Foo/BAR/Baz # Move filename to foo/BAR/Baz
SVN rename filename1 filename2 # rename the file

It is no different from common DOS/Linux commands. For more specific commands, refer to svn book. If you think the command line is too troublesome, you can use a graphical front-end called tortoisesvn to replace the command line.

2.4 conclusion

With the above content, we can:


1. Create a repository
2. Import the project to the Repo
3. Create a working copy
4. Some simple SVN commands

The above is basically enough for personal small projects, but if you can use it easily, you can use the svn HELP command to view the usage of other commands. If you are not comfortable with the command line operation, we recommend that you use the tortoisesvn software mentioned above in Windows to use a completely graphical interface, which is very simple to use. If you need help, you can refer to the User Guide on lifehacker.

The following two articles describe the application of subversion on the server, including server creation and user verification.


3. Use svnserve to create a Subversion server


Let's try it out.


Part1 describes how to create a repo on the local machine for your own use, but if you want to put the repo online for other users to checkout, you also need to set up the svn server-this is also the purpose of this Article.

The SVN server can be set up in two ways. One is relatively simple. The other is to use the svnserve utility provided by SVN, and the other is to directly use Apache for setup. Additional modules need to be loaded. Svnserve is simple and enough. I plan to explain in this article how to use it to set up SVN servers.

Svnserve is included in the Subversion package. After you install the Subversion on your computer, the small SVN server svnserve is automatically available. This server is simple and lightweight compared with Apache, which uses its own protocol. It is different from http: // prefix in access and uses SVN: // prefix.

3.1 Use svnserve to build the svn Server

We want to run svnserve. I will introduce the specific usage in the example.

Let's assume that I run svnserve on the local machine and the IP address is 192.168.0.1. This SVN server provides SVN services for computers in the local area network. I plan to set the svn server access address to http: // 192.168.0.1/svnprojects/projectx, where X is different from multiple projects. The entire process is as follows (taking windows as an example ):
First, determine the storage location of the repo on the local machine. For example, if I want to put the repo under D:/svnprojetcs/, run svnserve-d-r d on the command line: /svnprojects. The-D parameter enables svnserve to run in the background, and the-R parameter limits the addresses that repo can access on the network. In this way, if other computers on the network want to checkout this server, you only need to enter
SVN checkout SVN: // 192.168.0.1/project1

The actual position of the repo on the local machine is D:/svnprojects/project1. Similarly, if you want to checkout project2, you can change project1 to project2.

At this point, a simple SVN server is basically set up. However, for normal use, we also need to set user authentication and corresponding permissions.

Now we first create a repo named project1 and then go to project1:
Svnadmin create d:/svnprojects/project1
Cd d:/svnprojects/project1

There are a bunch of directories under the project1 directory, enter conf and open svnserve. in the conf file, find the following lines and remove the '#' annotation symbol. Do not leave any space before each line:
Anon-access = read
Auth-access = write
Password-DB = passwd

Here, anon-access and Auth-access are respectively anonymous and permission granted to authorized users. By default, anonymous users are given read-only permissions, which is good and we do not need to change them. However, if you want to reject access from anonymous users, you only need to change read to none. Passwd after password-DB is the file path that defines the user name and password. This file is in the same directory as snvserve. conf by default. Let's see how to configure the content in passwd:

[User]
# Harry = harryssecret
# Sally = sallyssecret

Harry and Sally define the username and password of the user who can write the repo respectively. We can add our username and password below, for example
Testsvn = Tester

This grants the user testsvn the permission to write data to the repo. After the storage disk exits, the svn server can be run! Put all the projects to be managed in the Directory D:/svnprojects. Use the svnadmin CREATE command as usual to create a repo. If you want to checkout Repo, enter:
SVN checkout SVN: // 192.168.0.1/project1

If you want to use commit, enter the user name and password you just set:
SVN commit-M "We are commiting changes! "-- Username testsvn -- password Tester

3.2 suggestions for Windows users


If you want to run svnserve on a Windows system, simply entering svnserve-D-r d:/svnprojects on the command line is not a good method. First, it is too troublesome to do so every time, second, to keep the server running after it is started, you must keep the Command Prompt window hanging on the desktop, affecting the appearance. It is best to use svnserve as a process of the system to automatically run at each startup:
D:/> SC create SVN
Binpath = "D:/SVN/bin/svnserve.exe -- service-r d:/svnprojects"
Displayname = "Subversion server"
Depend = TCPIP
Start = auto

Replace the path in with your SVN installation directory.



4. Create a Subversion server under Apache

Deploying subversion in Apache is not much more difficult than using svnserve. The difficulty is that most people do not have the permission to modify Apache configuration. If you have the permission to modify the configuration, building a SVN server is not difficult. Let's take a look at how to configure it.

4.1 preparations

First, make sure that Apache is correctly installed. The mod_dav and mov_dav_svn modules are also enabled. you can install them On Debian Linux:
Sudo apt-Get install apache2 subversion libapache2-svn

On the Windows platform, you can download an XAMPP, Apache MySQL, and PHP file.

Make sure that mod_dav and mod_dav_svn are enabled:
A2enmod Dav dav_svn

4.2 Basic settings

After the above preparations are completed, we will officially start using the network environment of the Part2 machine, the same example.

I want to change the network access address of the repo to http: // 192.168.0.1/svnprojects/projectx,

Modify httpd. conf under/etc/apache2/conf and add the following code:

<Location/svnprojects>
Dav SVN
Svnparentpath/path/to/svnprojects
</Location>

For more information about the <location> command usage, see the Apache manual. The svnparentpath command maps the network access address to the actual repo address.

In this case, the settings are complete. If you have set up the repo, you can now checkout it. Enter:
SVN checkout http: // 192.168.0.1/svnprojects/project1

4.3 set user permissions and Verification

However, this is definitely not enough, because no corresponding user permissions have been set. Now, no matter who is allowed to repo stuff in the past, in order to better control, we also need to set access permissions, for example, you can allow the specified user to commit, while others can only checkout.

Because we are on Apache, the access permission control can be directly borrowed from Apache. First, set the user name and password for your user:
Htpasswd-CMB/path/to/passwdfile/passwords user1 test1

In this way, the user name and password are stored in passwords, and the encryption method is MD5. To add a new user,
Htpasswd-MB/path/to/passwdfile/passwords user2 Test2
And so on.

Return to the code we added in httpd. conf and modify it:
<Location>
Dav SVN
Svnparentpath/path/to/svnprojects
Authtype basic
Authname "test repository"
Authuserfile/path/to/passwdfile/passwords
<Limit10000t get PROPFIND option report>
Require valid-user
</Limit10000t>
</Location>

Under the control of this Code, anyone can checkout the repo, but only user1 and user2 can commit. <limit#t> is used to control HTTP requests, if an HTTP request is one of the get PROPFIND option report statements, you do not need to verify the user.

Finally, you need to change the ownership of the Directory and file where the repo is located to the user who operates Apache in the system so that it will be recognized by Apache during commit. In ubuntu, this user is called www-data:
Sudo chown-r www-data/path/to/Repo

If you use another system or windows, you can find the USER command in the Apache configuration file to know who should give the directory ownership.

The above is the initial construction of A Subversion server. This article considers that there may not be many people actually using it, and the users who need it are sure to configure it by themselves. Therefore, I did not write it carefully enough, for example, the SSL-based setting step is not mentioned. If you really need to know about it, contact me and we will discuss it together.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.