Moving the “uploads” Folder outside of the WordPress Directory

If you’re using WordPress to run a website, you may want to move the “uploads” folder outside of the WordPress directory for various reasons. However, WordPress only allows you to change the location of the “uploads” folder within the main WordPress directory. In this tutorial, we will go over a workaround solution to move the “uploads” folder outside of the WordPress directory by using symbolic links or symlinks.

The Challenge

By default, WordPress stores all uploaded media files (such as images, videos, audio files, etc.) in the “uploads” folder, which is located in the “wp-content” directory within the WordPress installation. If you want to move this folder outside of the WordPress directory, you may encounter the following challenge:

  • WordPress only allows you to change the location of the “uploads” folder within the main WordPress directory. This means that you cannot move the “uploads” folder outside of the WordPress directory by simply changing a configuration setting.

The Solution

To move the “uploads” folder outside of the WordPress directory, we can use symbolic links or symlinks. A symlink is a special type of file that acts as a pointer to another file or directory. By creating a symlink, we can point WordPress to a folder outside of the WordPress directory while still keeping the “uploads” folder in its default location.

Here’s how to move the “uploads” folder outside of the WordPress directory using symlinks:

  1. Create a folder outside of the WordPress directory where you want to store your uploaded files. For example, you could create a folder called “uploads” in your website’s root directory (/public_html/app/uploads).
  2. Open a terminal window and navigate to the “wp-content” directory within your WordPress installation. You can do this using the “cd” command. For example, if your WordPress installation is located at “/public_html/wordpress/”, you would use the following command:
    $ cd /public_html/wordpress/wp-content
  3. Create a symlink that points to the folder you created in step 1. You can do this using the “ln” command. For example, if you created a folder called “uploads” in the root directory of your website, you would use the following command:
    $ ln -s ../../app/uploads app-uploads

    This command creates a symlink called “app-uploads” in the “wp-content” directory that points to the “uploads” folder outside of the WordPress directory.

  4. Set the correct permissions for the symlink using the “chmod” command. For example, you would use the following command to set the permissions of the “app-uploads” symlink to 755:
    $ chmod -h 755 ./app-uploads

    Note that the “-h” option tells “chmod” to modify the permissions of the symlink itself rather than the file or directory that the symlink points to.

  5. Open the “wp-config.php” file in your WordPress installation and add the following line:
    define('UPLOADS', 'wp-content/app-uploads');
    This line tells WordPress to use the “app-uploads” symlink as the location of the “uploads” folder.

And that’s it! WordPress will now use the “uploads” folder outside of the WordPress directory.

Conclusion

Moving the “uploads” folder outside of the WordPress directory may seem like a daunting task, but with symlinks, it’s actually quite simple. By creating a symlink that points to a folder outside of the WordPress directory and setting the correct permissions, you can trick WordPress into using the “uploads” folder in its default location while still storing your uploaded files

References

https://stackoverflow.com/questions/38129447/upload-folder-of-wordpress-outside-the-project/38151851#38151851