Move WHMCS writable directories outside the public web root to prevent direct web access, then update both the template cache path and storage settings. Moving files without changing those references can break attachments, downloads or page rendering.
IN THIS ARTICLE
01 Move the directories
- Back up the installation and record the current storage configuration.
- Choose private directories owned and writable by the WHMCS account, outside the public website directory.
- Move the existing
attachments,downloadsandtemplates_ccontents to their intended locations. - Update
$templates_compiledirinconfiguration.phpto the absolute path of the new template cache directory. - Open System Settings > Storage Settings and add the new local storage configurations.
- Assign the correct configurations in the storage settings and complete the appropriate switch or migration.
02 Example: map private storage to the correct WHMCS setting
This example uses a fictional hosting account named example. Replace every path with your own absolute path and confirm that none is inside a website's public document root.
| Directory | Illustrative private path | Where to configure it |
|---|---|---|
| Template cache | /home/example/whmcs-private/templates_c/ |
$templates_compiledir in configuration.php. |
| Attachments | /home/example/whmcs-private/attachments/ |
A local configuration in Storage Settings, assigned to the corresponding file storage. |
| Downloads | /home/example/whmcs-private/downloads/ |
A separate local configuration in Storage Settings, assigned to downloads. |
After moving the template cache, replace its existing assignment in configuration.php with the correct path. Preserve the rest of that file:
$templates_compiledir = '/home/example/whmcs-private/templates_c/';
The cache assignment does not move attachments or downloads. Configure those locations through Storage Settings, then choose Switch only when the existing files are already at their destination; otherwise follow the Migrate workflow.
What is the difference between Switch and Migrate?
Use Switch when the existing files have already been moved to the configured destination. Use the supported Migrate workflow when WHMCS needs to copy files from the old location. Inspect the actual source and destination before choosing, since an empty new directory is not equivalent to a completed move.
03 Verify access and rendering
Open the client and administrator areas to check template rendering. Upload and retrieve a harmless test attachment, then test an authorised download. Confirm the private directories cannot be fetched through a public URL.
If rendering fails, check the exact cache path and PHP process permissions. If downloads disappear, review the storage assignment and whether the files were moved or merely a new location was created. Keep the old backup until these checks pass.
04 Include the cron separately
The cron directory has its own supported move procedure, including crons/config.php, the installation's cron path and scheduled commands. Do not assume moving attachments also protects cron scripts.
Update backup jobs to include every private location. During later manual updates, confirm any moved cron files and renamed administrator files receive the matching release updates. An installation with private paths needs those paths recorded in its recovery and migration notes.