How to move wp-content (or uploads) outside of the WordPress directory

I am trying to move the wp-content directory outside of the wordpress directory and hitting all kinds of weird problems. Even though http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder says you can do this, it seems that the directory structure is deeply wired into the WP code. For example, I get error messages like:

PHP message: PHP Warning:  file_exists(): open_basedir restriction in effect.
File(/srv/wp.content/themes) is not within the allowed path(s): (/srv/wordpress/:/tmp) 
in /srv/wordpress/wp-includes/theme.php on line 369

All I need to do is to move the uploads directory outside of the main hierarchy. I tried to symlink it as well but then I am getting permission errors.

Did anybody manage to successfully have the wp-content directory, or at least, uploads directory outside of the root directory?

2 s
2

You have to define WP_CONTENT_DIR and WP_CONTENT_URL:

const WP_CONTENT_DIR = '/path/to/new/directory';
const WP_CONTENT_URL = 'http://content.wp';

The new path must be accessible for read and write operation from the WordPress core directory. You might need a helper function to add the new directory path to the open_basedir list:

/**
 * Add a new directory to the 'open_basedir' list.
 *
 * @link   http://www.php.net/manual/en/ini.core.php#ini.open-basedir
 * @param  string $new_dir
 * @return void
 */
function extend_base_dir( $new_dir )
{
    $separator=":"; // all systems, except Win

    // http://stackoverflow.com/a/5879078/299509
    if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) )
        $separator=";";

    $dirs = explode( $separator, ini_get( 'open_basedir' ) );

    $found = array_search( $new_dir, $dirs );

    // Already accessible
    if ( FALSE !== $found )
        return;

    $dirs[] = $new_dir;

    ini_set( 'open_basedir', join( $separator, $dirs ) );
}

Now call it like this:

extend_base_dir( WP_CONTENT_DIR );

Leave a Comment