Categorized: Subversion, WordPress

Installing WordPress The Right Way (revised)

Keep WordPress core files entirely separate from your content (themes, plugins, uploads).

There are a couple of ways to keep your WordPress install up-to-date. The easiest way is to install it as an svn:external. In the root of your (Subversioned) site:

svn propedit svn:externals .

Then paste in:

wordpress http://svn.automattic.com/wordpress/tags/[current_tag_number]

Replacing [current_tag_number] with the current tag number (check wordpress.org/download/ to see the latest). Alternately, you can just download WordPress and put it in a wordpress folder (or wp or whatever you prefer) in the root of your site.

Now copy the default wp-content folder from the fresh copy of WordPress to the root of your site:

cp -R wordpress/wp-content .

Delete the existing .svn folders from your fresh new wp-content.

cd wp-content
rm -rf `find . -type d -name .svn`

Now create your wp-config.php

cd ..
cp wordpress/wp-config-sample.php wp-config.php

Edit the file and add your database info. While you’re in there, add these settings to the top of the file:

// Custom wp-content folder: 
define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content' );
define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/wp-content');

define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME'] . '');
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/wordpress');

Those settings do a number of cool things. First, you’re allowing WordPress to use your fresh copy of wp-content in the root of your site instead of the one that lives inside of the wordpress folder. Second, you’re specifically setting some WordPress variables that are normally defined in its database in PHP, so that you won’t have to readjust your settings between development (on your local machine) and where it lives in the wild. Third, you’re telling WordPress where to find it’s core files since you’ve put them in a subfolder (/wordpress).

Now copy index.php from WordPress to the root of your site:

cp wordpress/index.php .

Edit the file and change the line that says:

require('./wp-blog-header.php');

To this:

require('./wordpress/wp-blog-header.php');

If you want fancy URLs (you do), create an .htaccess file:

touch .htaccess
chmod 666 .htaccess

Duplicate the default theme:

cp -R wp-content/themes/default wp-content/themes/[your_new_theme]

Replacing [your_new_theme] with what you want your new theme to be called.

Bonus: keep Akismet as an svn:external for automatic updates from Automattic.

cd wp-content/plugins/
rm -rf akismet

Or, if you’re already committed your code:

svn rm akismet
svn ci -m "Moving Akismet to external."

Then setup the external link:

svn propedit svn:externals .

Paste in:

akismet http://plugins.svn.wordpress.org/akismet/trunk/

That’s it.

Now commit your code and get to it. If you get lost, check out wp-template for an example.

Updating WordPress

svn propedit svn:externals .

Change the tag number, then svn update and you’re good to go.

If you’re not using svn:externals, just dump a new copy of WordPress over the one that’s already in /wordpress. There’s no way you can hurt your existing content, because that’s all in the /wp-content folder in the root of your site.

Sources

Comments

JTJ → May 28th, 2008 at 3:19 pm

Why a branch instead of a tag?

Trey → May 28th, 2008 at 3:46 pm

No reason. You think tag would be better than branch?

JTJ → May 29th, 2008 at 8:17 am

In general, tags are actual releases and will not change; whereas, branches are in-progress and not always stable. I’d recommend using tags.

Trey → May 29th, 2008 at 8:54 am

@JTJ – Noted and updated the post.

Luke → January 14th, 2009 at 5:36 pm

If all you’re going to do is delete the .svn folders afterwards, why are you bothing to checkout? Use export:

svn export http://svn.automattic.com/wordpress/tags/tag [site]
Trey → January 14th, 2009 at 7:50 pm

@Luke – I’m only deleting the .svn folders from the new theme I’ve created by duplicating the default theme, not WordPress itself. And I’m only doing that because I’ll be creating a new repository for my new theme. Dig it?

Luke → January 15th, 2009 at 10:04 am

@Trey oh, my bad – I missed the cd [theme] part.

joshua → February 16th, 2009 at 12:09 pm

William → February 17th, 2009 at 11:03 am

Thanks Trey! The first steps are not totally clear (the difference between the two ways) but it definitely pointed me in the right direction.

David Lima Cohen → May 31st, 2009 at 9:50 am

Thanks Trey! Awesome work, this is exactly what I was looking for. I could only find information to do checkouts or exports from Automattic’s SVN, but nothing about using the svn:external property. Really appreciated.

Nick Yeoman → June 18th, 2009 at 3:12 pm

Great article, I use Apache so I’m able to use sym links, which means I don’t have to all that extra work you do.

When a new update appears just propedit and run an update then run a config script which sym links all your directories (plugins, themes, images).

example: rm -f public-disabled/wp-config.php ln -s ../resources/wp-config.php public-disabled/wp-config.php

Just a different approach of doing the same thing.

What do you think about that?

Elsewhere in the empire: Home, Blog, APOD