Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Installing WordPress With Clean Subversion Repositories

Many people have used Subversion to install WordPress or have installed WordPress into its own directory. You can combine these techniques to create a "clean" Subversion installation in which the user's custom files (wp-config.php and wp-content/) are stored outside of the WordPress application directory, so that user files and files under version control never overlap. (Original credit to Sam Bauers for presenting these instructions at WordCampUK.)

In the example below we will use wordpress as the directory for the core WordPress files and wordpress-content for the new location of the wp-content directory; the home directory will be the Document Root (http://example.com). The finished installation will include files in these locations:

/.htaccess
/wordpress/
/wordpress/index.php
/wordpress-content/
/wp-config.php

There are a few basic steps (explained in detail below):

  1. Check out a branch or tag of the WordPress application into the wordpress directory (and complete a new installation)
  2. Change the Site address to the URL of the home directory
  3. In an .htaccess file in the home directory, edit WordPress's mod_rewrite rules to pass requests to the index.php file in the wordpress directory. Remove WordPress's write access to the .htaccess file.
  4. Move the new content directory and set WP_CONTENT_DIR and WP_CONTENT_URL to the new location
  5. Create symbolic links to the Akismet plugin and the default theme in the new content directory

Check out a working copy and install

Create the new location for the core WordPress files to be stored (we will use /wordpress in the examples).

Following the New Install using Subversion instructions, check out (Subversion command co) the stable version of WordPress you have chosen. Do not type the $ characters -- they are just indications of the command prompt. Here is the command (assuming the version you want is 6.7.1):

$ svn co http://core.svn.wordpress.org/tags/6.7.1 .

When the download is complete, edit the wp-config.php (see editing wp-config.php) ignoring the Advanced Options and save the file within the root directory (http://example.com/).

Access your blog URL (http://example.com/wordpress) to complete the installation, as in the standard WordPress installation instructions.

Change Site address

Change the Site address to the URL of the home directory. This can be done in the Settings panel or in wp-config.

In the settings panel

  1. Go to the Options panel.
  2. In the box for Site address (URL): change the address to the root directory's URL. Example: http://example.com
  3. Click Update Options. (Do not worry about any error message and do not try to see your blog at this point!)

In wp-config

(This method avoids the error message and is more easily reversible.)

Set the WP_HOME constant in wp-config like so:

 define( 'WP_HOME', 'http://example.com' );

Edit .htaccess

Instead of moving WordPress's index.php file into the home directory (as in Giving_WordPress_Its_Own_Directory), we leave it in the application directory and change the mod_rewrite rules to pass requests there.

Set up Permalinks on the Permalinks panel and update your Permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate file permissions. Don't worry if WordPress can't write to your .htaccess file; we will be overwriting the contents anyway.

If the file exists move the .htaccess file from the wordpress directory into the root directory of your site (Blog address).

Open your root directory's .htaccess file in a text editor (or create it if necessary).

Edit the contents of the file to match the following lines, using your directory name for the WordPress core files:

# BEGIN WordPress
<IfModule mod_rewrite.c>
	# Hey-ho let's go!
	RewriteEngine On
	# Base is the URL path of the home directory
	RewriteBase /
	# Base goes to WordPress
	RewriteRule ^$ /wordpress/index.php [L]
	# Skip real files and directories
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	# Otherwise send it to WordPress
	RewriteRule .* /wordpress/index.php [L]
</IfModule>
# END WordPress

Edit the .htaccess file permissions to ensure WordPress can't overwrite it.

Note: If working in your development environment on a Windows machine (e.g. using XAMPP), file permissions can be modified by: right-click => Properties => 'Security' tab.

You should now be able to view the site via the root URL (http://example.com).

Move the content directory

Create the new location for the wp-content directory (we will use /wordpress-content in our examples).

In that directory create two further directories called plugins and themes.

Edit the wp-config.php adding the following lines:

 define('WP_CONTENT_DIR', dirname(__FILE__) . '/wordpress-content');
 define('WP_CONTENT_URL', 'http://example.com/wordpress-content');

Create soft links of wp-content/plugins/akismet/ into wordpress-content/plugins/ and wp-content/themes/default/ into wordpress-content/themes/. This will ensure that WordPress uses any SVN updates to the default theme or Akismet plugin. Running XAMPP on a Windows machine, you can follow these instructions for creating symlinks: http://www.inkplant.com/code/how-to-create-a-symbolic-link-in-windows-vista.php