Set up my DEV environment for my PHP site using SVN

I am creating my first website which I am hosting shortly. It's a great app that I hope will fit somewhere in the end, but I'll work on it while it's actually online. I want to do it right and set everything up efficiently. It is very difficult to gain knowledge of how to do this from a book or even the Internet.

Firstly, I have done a lot of research on SVN, and although I am currently the only one on the site, I would like to add more people to the project. I know that you need to create a repository for SVN that will actually house your project, and that there are some places that offer it for free, like Codesion. I understand well how it works.

I need a virgin. a subdomain for the current website so that I can test and work on anything I develop on and that SVN commits to. How does your SVN repository link and upload files to this subdomain? Is this even how you do it? How can I manage all the different databases for each domain?

When I've finished updating a few changes to my new deployment, will I just manually upload all the files to the site in real time? I am very busy with the process for all of this and it is difficult to find information on this. What's the best practice for rolling out new updates? Are there any other mechanisms or applications that I will need to be aware of in order to sustain my website as it grows?

Please, any help in the right direction would be greatly appreciated.


source to share

3 answers

It depends on how much control you have over your web server.

Most (IMO) people push their files to the server via something like FTP / SFTP. Many SVN hosting services offer this as a "deployment" service. You should absolutely use this option unless you have shell access or anything similar.

Personally, I prefer to have finer levels of control and let the web server do the pull. Using a system with full SSH access, you can simply test the server for code:

 svn co http://server/project/trunk --username foo --password bar


If you want ease of use (mixed with potential control layers), you can also create a PHP administration class for that.

echo `svn co http://server/project/trunk --username foo --password bar --non-interactive`;


And quite often I create a bridged solution. You can create post-commit bindings and configure things like this so that the SVN server reaches the specified URL with a comment. The client server then checks the comment and takes action based on the comment (it can ignore anything without the AUTODEPLOY " tag ).

There is also GIT (which you should be able to do similar things with), but I haven't blown up my current processes (and hundreds of SVN repositories) to go there yet.



There are many concepts to cover all in one question. Firstly - I host my repo directly on my webserver, but I can highlight what happens if it is also on the remote server.

When setting up your SVN repo, you must have a post-commit (.tmpl) file - renaming it for post-commit is something that will be done with every commit.

Inside this:


    #   [1] REPOS-PATH   (the path to this repository)
    #   [2] REV          (the number of the revision just committed)


    if ( svnlook log -r $REV $REPO | grep "*DEPLOY-DEV*" )
        rm -rf ~/tmp/path/to/repo
        svn export -r $REV "file://$REPO" ~/tmp/path/to/repo
        rsync -az ~/tmp/path/to/repo/trunk/ ~/path/to/webroot

    if ( svnlook log -r $REV $REPO | grep "*DEPLOY-LIVE*" )
        rm -rf ~/tmp/path/to/repo
        svn export -r $REV "file://$REPO" ~/tmp/path/to/repo
        rsync -avz -e "ssh -i /path/to/.ssh/rsync" ~/tmp/path/to/repo/trunk/
        ssh -i /path/to/.ssh/rsync chown -R apache:apache /path/to/webroot/


Now to see the important parts - include * DEPLOY-DEV * or * DEPLOY-LIVE * in your commit to deploy your site to the path you specified.

The DEPLOY-DEV part in the example works well when it's on the same server - you just need to apply the correct paths.

If the server lives somewhere else, this may require some ssh keys and other tricks that are a little deeper than I'll go into - but that should give you direction to tweak if you need to.



If you have ssh access to your webserver, check the two working copies on the server (in dev and in the document root). This way you can easily deploy any changes.

You can use a stable branch where you merge your changes for production.

A database connection that you define in an ini config file (or something similar) that is not under version control. So you can have different values ​​for dev and prod.

If you don't have ssh access and want to "efficiently" find another server with ssh access.



All Articles