How do I use SCM with a PHP app such as Wordpress?

Use SCM with PHP application like Wordpress

I run my blog using Wordpress and all too recently became a big believer in SCM. I really want to put my site into subversion (that's what I'm using right now, maybe git will come later) but I can't think of the correct way to do it yet. Basically, my repository is set up currently with an 'implementation' directory and a 'resources' directory, with implementation holding what will eventually be published to the live site. I want to be able to preview my site locally without having to upload to the server for obvious reasons. However, to do this I found that I needed to actually install Wordpress locally (not just copy the remote site down to my local box). This was told to me over at Wordpress.

This brings up the problem of being able to use SCM with the install because I need to upgrade my local site every now and then but this generates inconsistencies with subversion because it can’t track what’s going on because an external system is messing with it’s repository structure. That just won’t work.

My initial inclination is to try to just SCM my theme information as this is really the only stuff that I ‘own’ while as everything else is really just part of my platform (no different than Apache or PHP, really). However, that’s where my understanding breaks down. How can I selectively SCM only part of that directory structure, and how can I maintain the configuration of Wordpress that I’m on?

Use SCM with a PHP application like Wordpress

Anyway, I’m sure other people have tackled this and the solution is probably applicable to many apps similar to Wordpress (Drupal, phpBB, phpMyAdmin, etc.). So, how do you do it?

4 Answers

It's actually not that hard to do, but I'll break it down into a few suggestions here. What you're describing is more or less a "vendor drop" directory. This is basically where you maintain the code in SVN, but replace the contents with the newer stuff as it comes out.

What you should start with is an empty directory. Set up an SVN repository, and then do an SVN checkout into the empty directory (it will still be empty, except it will get a hidden .svn directory added). Next, install wordpress here normally, and then add its files to svn. You can probably just "svn add *" but be careful, and remove anything you don't want versioned (uploads/temp/cache directories, if applicable). You can also use the svn:ignore property to tell it to ignore certain directories or file types, if you'd like. Run "svn stat" to show you what is going to be checked in, etc, and once all is good, commit it (svn commit) and start working from there. Now you have a base installation of wordpress in SVN.

As you work and make changes, commit them.

When it comes time to upgrade, simply replace wordpress over top of what you have. Make sure when you replace directories, you replace the contents, and not the whole directory itself. You don't want to lose the hidden .svn folder in every folder because that is what will mess subversion up. Do an svn stat and/or svn diff to figure out what's changed, if anything, and mostly what's newly-added. At this point, you can commit again.

To deploy on your production site, you can do an svn export, or do a regular checkout into the web directory. If you do a checkout, be sure to only update when you are ready to deploy.

I'm not sure if this would allow me to do a full deploy from Subversion out to production, as the wordpress platform would not be included in the repo.

Sorry, I did mean that wordpress itself should be included in svn. I edited my post to reflect this.

Duh! And that makes sense too, as that's what the good people at Wordpress had told me. The reason you 'install' wordpress locally is to set up the DB. Then, everything can be CMed. Sorry I missed that somehow. :)

This is the method I'm testing. It takes some time to setup but you should then (in theory) have a future-proof install: Installing WordPress The Right Way. Also look at svn:externals for pulling in plugin updates: Use svn:externals to install WordPress plugins.

I think the upgrade part can even be a little easier than that; I do this with the most current version of both 2.5 and 2.6, as well as bleeding-edge trunk revision of WP.

Since Wordpress offers all of their stuff as subversion repositories, getting the current rev of a stable tag is as easy as making the blog directory and then

# svn co http _ svn _ automattic _ com /wordpress/tags/2.6.2/ (replace the current rev here for the first check out). 

When an upgrade is available, simply navigate to your blog directory and run

#svn sw http _ svn _ automattic _ com /wordpress/tags/2.6.3/ (or whatever wordpress rev you're updating to)

Then releasing to your production site is just an export, as gregmac mentions However, I don't think this answers your actual question, which I interpret as "How do I keep my custom stuff in SCM while being able to upgrade Wordpress". Your instainct about what directories to tack is pretty much on target (your own personal blog's stuff - themes, pplugins - will be in wp-content, so you should only need to put that into subversion) but I'm not proficient enough with subversion to tell you how to place the directory into your own repository while still being able to rely on Wordpress's repo for upgrades. My "SCM" for those files on my site is an off-server copy of the wp-content directory.

Maybe from that standpoint gregmac's answer works better for you.

My initial inclination is to try to just SCM my theme information as this is really the only stuff that I ‘own’ while as everything else is really just part of my platform (no different than Apache or PHP, really). However, that’s where my understanding breaks down. How can I selectively SCM only part of that directory structure, and how can I maintain the configuration of Wordpress that I’m on?

That's exactly how I version control my blog. I've found that it works great. Generally, if you're editing WordPress' files, you're doing it wrong and will be in for misery when it's time to upgrade.

To simplify this, I use TortoiseSVN. I navigated to my /wp-content/themes/ directory in Windows Explorer, right clicked on my custom theme's directory, and chose import from the context menu. After importing all of the existing files, I performed a checkout on that directory and everything was set.

Getting IIS6 to play nice with WordPress Pretty Permalinks

Getting IIS6 to play nice with WordPress nice links

I've got a WordPress powered blog that I'm trying to get setup on our IIS6 server and everything works besides the permalink structure which I'm having a big headache with. After googling around/wordpress codex I learned that it's because IIS6 doesn't have the equivalent of Apache's mod_rewrite which is required for this feature to work. So that's where I'm at now. I can't seem to find a functional solution to get the pretty permalinks to work without the "index.php/," anyone have any recommendations? What I can't do: Upgrade to IIS7, Switch to Apache, Quit my job. Those suggestions have been offered to me, which sadly, I can't do any of those. Just an, FYI. Much thanks for anyone who can lead me in the right direction. I just came across the following answer on another question: Pretty URLs for search pages. Hope that helps! IIRF does this, for IIS6…

Read more…

YouTube embeds not working in WordPress after importing from Blogger

YouTube embeds do not work in WordPress after importing them from Blogger

I imported a series of blogger posts (via xml) into WordPress, and the YouTube embed tags were removed. YouTube URLs in posts are not identified. Instead, just the text of the url is left. Possibly as opposed to full embed tags. I'm trying to restore the embed codes so it's seen. Another fact that is notable in the XML import is that [EMBLED CONTENT] appears instead of the url, that is, the video... by default, WordPress filters imported XML by removing possible troublesome tags…unfortunateely, including things like <embed> and <iframe> and other instances where you’ve included content in your posts. WordPress does so…

Read more…

How should a blog be structured to easily extract its data?

Structure a blog to easily extract its data

I'm currently using Wordpress to run my website. However, with each new release I become more concerned with software bloat and the convoluted table structures used to store my data. Maybe this is a fruitless pursuit. Features are always added to blogging software until it claims to be a CMS - and at that point your data is probably stuck. You do have the option of sticking with the 2.0 branch. This will be maintained with just bug fixes until 2010. I also sometimes worry about…

Read more…