telephone: (920) 215-1842
facsimile: (866) 456-2115

Symlinking WordPress core files, “WordPress Skeleton”

After attending a Startup Weekend in Milwaukee, a community driven individual very knowledgeable in WordPress by the name of Brad Parbs, he planted an idea in my head. This idea was symlinking the core directories of WordPress for local development and server implementations.

 

I took a few days to think about the idea and vet the process. Security and ease of execution were some of my top concerns. After coming across only a few posts asking about this idea I thought I would be a good idea to focus a article directly on the implementation of this task.

 

A WordPress Core Developer by the name of Mark Jaquith had a very basic overview of the execution of symlinking WordPress core files in a presentation he gave. He wrote up a article including this idea along with many more complex components which I think could be focused on independently in other blog posts. Please review the presentation video on WordPress.tv to help with the symlinking idea. The beginning of his presentation highlights symlinking, as the presentation continues he talks about many development techniques which I will not go into with this post.

 

So lets get started.

Having a symlinked directory can really help to update WordPress installations when new versions are released.

 

1. Download the custom wp-config.php files for your site which will be placed in the root directory. You might have an existing www or public_html folder were your website files exist. Manually file placement might be needed. View repo.

$ git clone https://github.com/htmlgraphic/WordPress-Skeleton.git

 

2. Download the newest version of WordPress, I recommend using git because then you can switch branches and versions and this makes testing different WordPress versions really simple and slick!

Create a symlink “wp” to the actual location of the WordPress files you downloaded using Git. This new location should be accessible by other other sites you manage locally or on a remote production server.

$ git clone https://github.com/WordPress/WordPress.git

Create a symlink “wp” to the actual location of the WordPress files.

$ ln -s /home/user/WordPress wp

 

2. a. The following note is not required but might be a helpful item to complete: (Create the symlink as the user which will need to view any of the files. Match the owner and group which is set on other files in the directory.)

 

3. Update the wp-config.php file in the symlinked wp directory?

You might be receiving the following error: Why is the wp-config.php file not found?

The following important piece of code needs to be included is in the wp-config.php file. This file is located in the directory you symlink’d to. Open /wp/wp-config.php and add the following.

<?php
include_once("${_SERVER['DOCUMENT_ROOT']}/wp-config.php");
?>

This is all that should exist in this file.

 

4. Now we need to add the WordPress index.php in the root directory accessible from the browser. Overwrite the existing file if it exists or create a new one and input the following:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require('./wp/wp-blog-header.php');
?>

 

5. Redirection issue when accessing the wp-admin login page?

The WordPress Address (URL) should include a /wp/ at the end so you can proper login to the admin side. You will need to access the wp_options database table and modify a value within the option_value column.

Search for the siteurl option and add /wp to the end of the domain you have listed. After this you should be able to login to the admin side and manage the WordPress site just like you always have.

 

6. This is the fun part. Access the the wp directory you symlinked. Execute the following command.

$ git tag
$ git checkout 4.0

You are now on the previous version of WordPress. Switching this around is so simple and your wp-config.php in the symlinked /wp folder will not be overwritten. Cool!

 

 

ISSUES: Why do I have a blank page? There is a blank page because the wp-content directory has not been loaded correctly.

Does this directory exist?

Database credentials?

Turn on the rewrite engine and enable the `FollowSymLinks` option (this is necessary in order for the following directives to work). With the .htaccess look for FollowSymLinks, this will be an important piece. The ‘+’ should be removed for the symlink to work properly.

 

If you are still having problems please leave your situation in a comments below. I would be happy to provide guidance or ideas to solve your problem.

2 Responses

  1. Cool. Thanks for writing this up Jason!

    I messed with Jaquith’s skeleton setup a while ago and while I really liked it it confused to many people I work with so I went back to normal.

    Personally I really wish core would adopt this file structure, but I have a feeling we’ll see WP version 10 before that happens.

    I’d actually thought about symlinking all the root core files plus wp-admin and wp-includes, but that seemed too much a hassle to try, this might incentivize me to try skeleton again with your symlink setup though.

  2. Jon Brown on Nov. 27th, 2013 at 4:35 pm
    • Thanks for your feedback I have added the option to disallow the admin update option for WordPress. This way files will not be overwritten and updates can be managed for others.

      // This will disallow WordPress core updates from /wp-admin
      define( ‘DISALLOW_FILE_MODS’, true );

      I think you should review this idea again. If there is anything needed to make this better I would be happy to include it in my tutorial.

    • Jason Gegere on Nov. 28th, 2013 at 1:10 pm