How to use svn on a live apache server?
I'm new to SVN and theres something im stuck on. For the longest time Ive been developing websites locally (MAMP setup) and then ftping the whole site live when it is ready. Any small additional changes I make directly on the live site and every so often I will redownload all of the files on the live server to my localhost (since I can never remember all of the files i have changed). Obviously this is not the best way of doing things. I 开发者_C百科was curious how I could setup SVN on a live web server, so every change I make locally it will get pushed onto the website when I tell it to. Where do i create the svn repo? /domain.com/www/svn ? Can i create the www directory as the actual repo, and if so is this bad practice?
Don't create the repository in the web server directory! That's the first part of your issue.
Your repository can live anywhere, just don't put it in the webserver's directory.
When you setup Apache httpd (if that's what you're using), set it up to ignore .svn folders like this:
<DirectoryMatch \.svn>
Order allow,deny
Deny from all
</DirectoryMatch>
Now, somewhere else, other than your webserver, create a Subversion repository. Checkout from that repository in a working directory somewhere else that's not in your webserver's directory. You can now import all the files that will be in your repository here and commit them to your Subversion repository.
Once you've done that, you can go your webserver's directory where you want these files to appear, and do a checkout.
You should have three things:
- A Subversion repository that's not in your webserver's directory.
- A working directory that contains all of your files in your website that's not in your webserver's directory.
- A working directory that is in your webserver's directory.
The plan is this: You make the changes in the working directory that's not in your web server's directory. You can do your testing here, and commit your changes here. You also do all of your testing here too.
Once you're satisfied with everything, you can then do a svn update
in the Subversion working directory that is in your webserver's directory. So, you do your work outside of the webserver, test, and then do a svn update
in the webserver directory.
If you want to get really fancy, you can create a web branch which would represent the code in your webserver's directory. Then, you can check your code in and out all you want. When you are ready to implement it in your website, you can merge it to the web branch. When you update the working directory in your webserver's directory, it will only pull the code on the web branch.
In fact, you could automate that process with some sort of cronjob. You bring your website down, update the subversion working directory in your web server's directory, and then restart your website. This makes sure that files that a web user is looking at aren't changed from under them.
I would setup a structure in your svn checkout (on your local box) which matches the files you need to store (and don't necessarily match the server's structure), for example:
my-project
my-project/docs/README.txt (any documentation you want to write)
my-project/www/index.html (etc)
and so on. Then,
(1) If you have access to running commands on the server, I would log in and do e.g.:
cd /domain.com
rm -rf www
svn co https://svn.myserver.com/my-project/www www
(2) Otherwise, I would check out the files on your local machine and ftp them across to the server.
Option (1) is better but even with option (2) you have advantages over your current setup. If you change files on the server, you can ftp the whole directory back to your local box to a new directory, then "commit" the files to the subversion server. Subversion (with the .svn
directories, which you need to copy to/from the server) will know which files you've changed.
精彩评论