How to get the address of the svn server for my subversion repository?

Recently, I had some code from a Subversion repository on my machine, but no longer had tortoise svn or any svn command lines tool set up. Luckily, I remembered that in Subversion there is a lot of fun data inside the .svn directory. For instance you can see the address of the server and repository by viewing the .svn/entries file at the root of the local subversion files.

Just look for the svn:// or svn+ssh://

That line should show you the svn server address, as well as the repo name and branch.

Continue reading

Development Environment layout using Linux, Apache, PHP, and Subversion

Some of the age old questions I face lately are:

  • What’s for dinner?
  • Should I accept that friend request on Facebook for the friend of a friend of a friend that I knew 15 years ago?
  • What’s the best development and test environment layouts for PHP using Apache as a web server with Subversion for version control for multiple developers?

Some of you may be asking yourselves the same questions. The choice of dinner is a personal one. I won’t go into that except to say that everyone loves a good burrito. Spicy! And you probably don’t care about my take on Facebook etiquette since your friends list probably dwarfs mine.

But I do have some definite thoughts on the layout of development environments. And I find that there’s a huge lack of information about this on the interweb, so here you go.

We use Linux, Apache, PHP, and subversion in our development environment and so these instructions will be biased towards these topics but I think you can apply this method using various other technologies.

I like to give each developer their own development web site and development database. I find it’s easier for everyone to have their own individual sandbox to play in. We give them each their own domain using their initials, something like rzdev.domain.com for me, Rich Zygler, and vbdev.domain.com for another developer, Vinny Bagadonuts. We set the Apache directories up on the Linux dev box in a similar fashion:

/var/www/rzdev.domain.com/
/var/www/vbdev.domain.com/

This has a few benefits. If I need to show Vinny something with my site development, I can just send him the link to http://rzdev.domain.com/broken-page. I can make changes to code, even major infrastructure code and not break anything for the other developers. We do the same thing with the databases, prefacing them with our initials.

Now, since our dev boxes use Linux, we set up Samba for sharing on these web directories. This means that all the devs can edit files and use source code management on the Linux server itself or on their Windows machines (we use either Eclipse or Zend Studio and create projects on the shares, that’s a whole different posting!).

This dev site layout is closely linked to the way we use Subversion for version control. When we start a new site or application, if we can split out the development evenly enough, we’ll just have everyone work from the trunk version of the code, with each developer working on their own little section. Each developer puts the trunk in their Apache dir and we edit the Apache configs to reflect this:

/var/www/rzdev.domain.com/trunk/
/var/www/vbdev.domain.com/trunk/

The root of the dev sites typically look like this:

/var/www/rzdev.domain.com/trunk/docs ( your Apache document root )
/var/www/rzdev.domain.com/trunk/lib ( non-public PHP library code )

When we commit code changes in Subversion, we have a hook that updates our main development site here:

/var/www/dev.domain.com/trunk

Again, that site can be seen on the web at http://dev.domain.com/ This way, we can do integration testing on our code to make sure our new code doesn’t break code from someone else within the dev site.

Now, the important thing here is that the Quality Assurance (QA) and Testing people ( if you’re lucky enough to have them ), don’t use any of these previously mentioned sites for their testing. Why not? Well, because if they’re doing a good job and are therefore sufficiently anal, they’re going to complain when code is changing on the site they’re looking at.

So we give them their own test site and database that’s viewed on the web at http://test.domain.com/ and setup in apache at:

/var/www/test.domain.com/trunk/docs
/var/www/test.domain.com/trunk/lib

The developers will meet and create the list of files and database changes that get moved over to the test site. How the actual moving is done doesn’t really matter. If you have the time and energy to set up some Ant or Phing tasks, that works great. But copying/rsyncing files and running some SQL on the test database works just as well. The most important part is that the developers meet to decide which part can go to test. Otherwise, you could have code going to test and eventually production that might not be fully vetted.

When QA finds bugs in test.domain.com, they can send them to the developers. The developers can instantly start working on fixing the bugs in their own dev space at rzdev.domain.com and not affect the other developers or the ongoing testing of the application. Pretty nice right?

Advantages of this approach

  • Uses source code management
  • Developers can unit test their own code
  • Developers can do integration testing between each other’s code
  • Developer A typically doesn’t destroy code or data that developer B is using
  • Developers don’t destroy code or data that QA/testing is looking at
  • Developers can both edit files and use source code management in either Linux or Windows environment
  • Very scalable. Adding new developers into the mix is as simple as adding their respective sub domains and databases (of course, this can also be viewed as a disadvantage, see below)
  • Less bugs make it to production

Disadvantages

  • Lots of sysadmin overhead initially and with each subsequent domain added. You have to set up all those developer sites, rzdev, vbdev, etc. Same overhead when using branching within subversion. Plus, you have to setup all those databases and setup the config code to connect to the appropriate database for each developer domain.
  • Lots of file space for all the sites and databases.
  • Confusing for lone wolf and gunslinger developers who are used to overwriting production or each other’s development code (too bad for them!)

So what do you think? How do you setup YOUR PHP development environment?

Continue reading

Using Subversion externals property for WordPress upgrades

I find that upgrading apps like WordPress, Drupal, Symfony and open source PHP apps is simple for less complicated environments, but once you start adding in things like new directories, custom themes/modules, source code control as well as separate development, test, and production systems, the upgrades start to get pretty hairy.

Take WordPress for example. A typical upgrade of WordPress involves copying the new WordPress files over your existing files. Then you have to copy back safe versions of things like wp-config.php, .htaccess (if you’re using it), as well as any custom themes/modules from the wp-content/ directory. Not to mention any of your own directories that should exist alongside your wp-includes/ and wp-content/ directories. After that you can run the upgrade.php file.

These upgrade steps aren’t terrible. They’re quite a bit better then most open source apps out there but they still suffer from a few problems:

  1. If you have your code, including your WordPress install, in Subversion or another source code control system, you have to commit all the files that change with each WordPress version. There may be files added, deleted, etc. You’ll have to keep combing thru “svn status” messages to figure out everything you need to do to get all the WordPress files into your repository. This can be painful. And take a long time.
  2. WordPress is specifically written so that you don’t ever have to muck with the guts of it. You create themes and plugins for added functionality. So, since you’re not maintaining the code that powers WordPress, do you really need all those deltas in your Subversion repository? I think not.
  3. What do you do with your own code in directories that sits alongside wp-includes/? What if it’s in a Subversion repo?

The WordPress site also has instructions for using Subversion with your site. Here, they advocate the use of “svn switch” to update your site. This is much more manageable and solves a few of the above problems. Most svn users can probably can get away with this method. But unfortunately not me.

I have additional directories on some of my sites that I need to add into my WordPress install. So I have to copy/move them into the WordPress dirs which gets tough. And then my “svn status” will get all wonky because my WordPress dir is under one repo and my code is under another. This was endlessly confusing for me.

So I found myself looking for a way to completely wall off my WordPress install from the rest of my files. I was reminded recently of the use of the Subversion externals property and my mind started buzzing with possibilities. With “externals,” I can say:

Pull the stable WordPress code from WordPress.org and put it into this directory named /docs/wp/

Then my other directories, which are under my own local subversion repo can exist at /docs/dir1, /docs/dir2, etc. Of course, some Apache Alias magic is needed to make all this work.

Here’s the way I set it up for my some of my projects. So far so good. This is a bit hairy to set up but subsequent upgrades are a breeze. I use this across development, testing, and production systems (how to get those environments to work with WordPress will be another entry)

First off, the previous Apache document root for domain1 was at /www/domain1/docs, so the WordPress files wound up like this:

/www/domain1/docs/wp-content/
/www/domain1/docs/wp-includes/

But I also have a lot of dirs that sit alongside of wordpress like this:

/www/domain1/docs/dir1

/www/domain1/docs/dir2

We’re going to wind up changing that.

Create an subversion external property in /www/domain1/docs for WordPress

vi starts up and you can add the following line:

Save and exit

This downloads the WordPress code from the above address into your wp/ directory. Now we are cooking.

  • Now, /www/domain1/docs/wp is where all your WordPress code lives.
  • Copy wp-config.php to /www/domain1/docs/wp/
  • Copy .htaccess to /www/domain1/docs/wp/
  • Create a link from the stock wp-content/ dir to your personal wp-content dir like this

  • In Apache config, set document root for this domain to /www/domain1/docs/wp
  • Put wp-content/ dir and any other non-WordPress dirs/files into /www/domain1/docs
  • Create an alias for wp-content/ and any other non-WordPress dirs/files in Apache config

This looks like a lot of work, but it’s really only a lot the first time around. Next time WordPress has an upgrade:

Everything after the propedit in this group can and should be scripted which will basically give you a 2 step process for upgrading WordPress, while keeping you wp-content/ dir under local source code control, as well as leaving room for any other directories or files your site might require.

This technique will probably also work with Symfony although I haven’t tried it yet.

Continue reading

Yes you, Mr. ASP.NET developer can use a hosted open source Subversion source control for your projects also

For some reason, most .NET devs that I run into insist on using closed source applications for everything they do. I have no idea why. I guess it’s a culture thing. That’s why I love it when a mostly ASP.NET fellow starts using something open source, like Subversion source code control. All the tools are in place to do what you need, the TortoiseSVN windows explorer plug-inthe Ankh Visual Studio plug-in. It’s all there.
Plus, I’ve really fallen in love with the concept of a hosted subversion solution. For me, I host my own at my provider. But for my side projects, its great to be able to access them from multiple computers. If I can get to the internet, I can get to my project code.

Continue reading

How to for SSH, Subversion (SVN), Putty, Tortoise, and Zend Studio 5.x using svn+ssh

Attempting to connect my new Windows machine with Zend Studio 5.1 using svn+ssh to an svn repository on Linux, I am obliged to once again stand on the shoulders of giants that have come before me. Here’s some “how tos” that got me through it.

  • Logemann Blog – Subversion / TortoiseSVN SSH HowTo – Soup to nuts on how to set up both the server end as well as the client end of this ordeal. Includes ssh, ssh-keygen for generating keys, installing keys on client via Putty and Pageant, and using the ssh tunnel built to grab the repo via TortoiseSVN.
  • Zend.com Forums: Zend Studio => HOW-TO: Using SVN+SSH in ZS 5.5 – More ssh, ssh-keygen, installing keys on client via Putty and Pageant, and using the ssh tunnel with Zend Studio. (This seems to be missing one step for Zend to work though which is included next)
  • SVN – SSH connection produces errors – This post from the Zend knowledgebase adds the mysterious SVN_SSH environment variable that magically makes this work for Zend. NOTE – while they show this using the path to TortoisePlink.exe, you may also use Putty’s Plink.
Continue reading