Set Path for a Folder Outside the Root in Craft CMS

Published on

82058495 1f88bc80 96c5 11ea 8ce2 bf46203d7214

How to Correctly Set Path for a Folder Outside the Root in Craft CMS – A Step-by-Step Guide

 

When working with Craft CMS, there may be times you want to store files outside the web root directory—either for security reasons or to better organize your assets. Craft CMS gives you the flexibility to define custom paths for storage, but it's important to do it the right way to ensure smooth functioning and secure access.

 

 

Why Store Files Outside the Web Root?

 

  • To prevent direct access to sensitive files via URL
  • To organize uploads or backups in a separate server directory
  • To comply with security best practices for enterprise environments



Step 1: Locate Your Folder Outside the Root

 

Let’s assume your Craft installation is in:
/var/www/html/craftcms

And you want to store files in:
/var/www/uploads

Make sure this folder (/uploads) is created and the correct permissions are set for read/write access by your web server.

 

 

Step 2: Define a Custom Volume in Craft CMS

 

Go to your Craft CMS admin panel.

Navigate to Settings → Assets → New Volume.

Set a Name (e.g., “External Uploads”).

For the File System, click New File System.

 

 

Step 3: Configure the File System Path

 

In the File System settings:

Root Path: Use the absolute path to your folder
Example: /var/www/uploads

Base URL: Leave this empty if the folder is not web accessible
Or use a custom CDN/subdomain if files will be served via proxy

Click Save, then link your new volume to asset fields as needed.

 

 

Step 4: Access and Manage Files

 

  • Files stored in this location can now be managed from the control panel, but they won't be publicly accessible unless:
  • You set up a symlink, or
  • You use a CDN or reverse proxy to serve them securely

 

Conclusion

 

Setting a folder path outside the web root in Craft CMS is both possible and practical. It’s great for keeping your system secure, especially when handling private files or heavy media. By configuring volumes and root paths correctly, you can enjoy both flexibility and security in your Craft projects.

Need help configuring Craft CMS volumes or working on a Craft project?

🔗 https://www.craftcmsdeveloper.in/