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.
Comments
Why a branch instead of a tag?
No reason. You think tag would be better than branch?
In general, tags are actual releases and will not change; whereas, branches are in-progress and not always stable. I’d recommend using tags.
@JTJ – Noted and updated the post.
If all you’re going to do is delete the .svn folders afterwards, why are you bothing to checkout? Use export:
@Luke – I’m only deleting the
.svnfolders 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?@Trey oh, my bad – I missed the cd [theme] part.
Thanks Trey! The first steps are not totally clear (the difference between the two ways) but it definitely pointed me in the right direction.
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.
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?