最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

I am trying to move the wp-content directory outside of the wordpress directory and hitting all kinds of weird problems. Even though .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?

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/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?

Share Improve this question asked Feb 16, 2014 at 8:48 Sasha OSasha O 1851 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 5

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/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/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 );

Came here to find out how to move uploads outside the WordPress root. In the end I kept it as simple as creating a symlink and it works just fine.

$ pwd
/var/www/wordpress
$ cd ..
$ mkdir uploads
$ chmod 755 uploads
$ ln -sf /var/www/uploads /var/www/wordpress/wp-content/uploads

Source: Upload folder of Wordpress outside the project


For an existing project:

$ pwd
/var/www/wordpress
$ mv /var/www/wordpress/wp-content/uploads /var/www/uploads
$ chmod -R 755 /var/www/uploads
$ ln -sf /var/www/uploads /var/www/wordpress/wp-content/uploads
发布评论

评论列表(0)

  1. 暂无评论