The storage directory in OpenCart is the only place where the engine writes data during operation: file cache, sessions, error logs, generated OCMOD copies of files, customer uploads, and downloadable product files. The rest of the code tree is normally read-only, so storage must be writable by the web server, and for security it is better to keep it outside the web root. Below, we look at what is in each subfolder in OpenCart 3.0 and 4.1, what can safely be cleared, and how to work with these directories from module code. Examples are for OpenCart 4.1; in 4.0.x, model triggers and event handling differ.
Where is storage and how does OpenCart find it?
After installation, storage is located in system/storage/. The general directory map is described in the article about the file structure of OpenCart 3.0 and 4.1, and here we focus only on storage. It is important to understand that no core component "knows" the path to storage directly: everything is tied to constants defined in config.php (the root) and admin/config.php.
The base constant is DIR_STORAGE. Derived constants are built from it: DIR_CACHE, DIR_DOWNLOAD, DIR_LOGS, DIR_MODIFICATION, DIR_SESSION, DIR_UPLOAD. So, to move the directory, it is enough to change DIR_STORAGE in both configs and physically move the files. For more details on where these constants come from and how they coexist with settings in the database, see the article on config.php, system/config and settings in the database.
OpenCart 3.0: storage also contains vendor/, the Composer libraries (Twig and others) that are loaded already at the startup stage. If you move storage and forget about vendor, the site will crash with a fatal autoloading error before routing.
OpenCart 4.1: the structure is similar, but new subfolders have appeared (for example, for database backups and uploaded extension packages), and the extensionsAdditional functionality: a module, a payment or shipping method, a feed, or a theme. They are managed in "Extensions → Extensions." More in the glossary → themselves live separately in the root extension/ and do not belong to storage.
What is in each storage subfolder?
The directory contents differ slightly between branches. The table below shows the typical picture for current 3.0.5.x and 4.1.0.x releases; on a specific server there may be additional folders from third-party modules.
| Subfolder | Contents | OpenCart 3.0 | OpenCart 4.1 | Can it be cleared? |
|---|---|---|---|---|
cache/ | File cache (cache.ключ.мітка_часу), template cache | yes | yes | yes, at any time |
session/ | Session files, if the file driver is selected | yes | yes | only old ones; fresh ones are logged-in customers |
logs/ | error.log, in 3.0 also ocmod.log | yes | yes | yes, after analysis |
modification/ | Generated OCMOD copies of PHP and Twig files | yes | yes | yes, but then click "Refresh" |
upload/ | Files that customers uploaded via the "File" option | yes | yes | no, they are tied to orders |
download/ | Digital product files (Catalog → Downloads) | yes | yes | no |
vendor/ | Composer libraries | yes | yes | under no circumstances |
backup/ | Database backups from the admin | no | yes | old ones: yes |
marketplace/ | Uploaded .ocmod.zip archives | no (temporary files go to upload) | yes | be careful: this is the source for installation |
The main rule: cache, logs and modification are derived data that the engine will recreate on its own. upload, download and vendor are originals, and losing them means losing customer data or a non-working site. Sessions are an intermediate case: deleting them breaks nothing, but it logs out all customers and empties guests' carts.
How do cache and sessions work in storage?
By default, OpenCart uses the file cache driver, and all entries go into DIR_CACHE. Each entry is a separate file whose name contains the key and the expiration time; the value is serialized as JSON. When reading, the engine looks up the file by the key mask and deletes expired ones. The standard lifetime is roughly one hour; it is set in the cache configuration and depends on the version and server settings.
From a module, the cache is used via the $this->cache object from the Registry:
Example
$key = 'mymodule.bestsellers.' . (int)$this->config->get('config_store_id') . '.' . (int)$this->config->get('config_language_id');
$data = $this->cache->get($key);
if (!$data) {
// дані беремо власною моделлю модуля (у 4.1 бестселери обробляє
// окреме розширення bestseller, а не модель catalog/product)
// OpenCart 3.0
$this->load->model('extension/module/mymodule');
$data = $this->model_extension_module_mymodule->getBestsellers(10);
// OpenCart 4.1
// $this->load->model('extension/mymodule/module/mymodule');
// $data = $this->model_extension_mymodule_module_mymodule->getBestsellers(10);
$this->cache->set($key, $data);
}
// при збереженні налаштувань модуля в адмінці
$this->cache->delete('mymodule');
Pay attention to two things. First, the key must include the store and language, and if needed the currency and customer groupA segment of buyers (retail, wholesale) with different prices and terms. More in the glossary →, otherwise one store in a multistore setup will show another store's cache. Second, the delete() method of the file driver deletes by prefix, so name your keys with a unique prefix and you can invalidate the entire module cache with one call.
Sessions end up in DIR_SESSION only when the file engine is selected in the configuration; with the db engine they are stored in the session table, and the folder may be empty. How to switch drivers and how they differ in 3.0 and 4.1 is covered separately in the article on session and cache drivers. For storage, one thing matters: with file sessions, the folder can grow to tens of thousands of files because of bots, so session cleanup must be handled either by PHP GC or by cron.
How does OCMOD use storage/modification?
The modification/ directory is the most treacherous one in storage. OCMOD does not change the original files: when you click "Refresh" on the "Extensions → Modifications" page, the engine applies all XML modifications and writes the result into a mirrored structure in storage/ (catalog/, admin/, system/). On every request, the file inclusion wrapper checks whether a modified copy exists, and if so, includes that copy. How to write the modifications themselves is described in detail in the blog article about OCMOD and code edits without changing system files.
flowchart TD
A["Request: controller file needed"] --> B{"Is there a copy in storage/modification?"}
B -- "yes" --> C["Include the modified copy"]
B -- "no" --> D["Include the original file"]
C --> E["Run the controller"]
D --> E
F["Extensions → Modifications → Refresh"] --> G["Clear modification/"]
G --> H["Apply all XML"]
H --> I["Write new copies"]
This leads to a typical trap: you edit catalog/, but nothing changes on the site. The reason is that an old modified copy sits in storage/, and that is what runs. An edit to the original will only take effect after "Refresh". The same applies to theme Twig templates.
OpenCart 3.0: the log of applied modifications is written to logs/ocmod.log and is available on the log tab of the modifications page. That is where you can see which search string was not found.
OpenCart 4.1: there is a modifications page (marketplace/), and the archives contain ocmod/*.ocmod.xml files. For new code, it is better to use events.

Where to look for logs and how to write to them from a module?
The main log is a file in DIR_LOGS, whose name is set in the settings on the "Server" tab, by default error.log. PHP warnings and errors go there if error logging to file is enabled. You can view and clear it in the admin: System → Maintenance → Error Logs.

For your own module, it is better to keep a separate log so as not to mix your entries with core noise. The Log class takes a file name and writes it to DIR_LOGS:
Example
// OpenCart 3.0
$log = new Log('mymodule.log');
$log->write('Відповідь API: ' . json_encode($response));
// OpenCart 4.1
$log = new \Opencart\System\Library\Log('mymodule.log');
$log->write('Відповідь API: ' . json_encode($response));
// Запис у загальний журнал через Registry (обидві гілки)
$this->log->write('mymodule: помилка синхронізації');
Practical tips on logs:
- Do not write full responses from payment providers containing customers' personal data and tokens to the log; everyone with admin or FTP access can read it.
- Add a "debug modeDisplaying errors for the developer. Turn it off on a live site. More in the glossary →" toggle to the module settings and write detailed entries only when it is enabled.
- Watch the size: on a store with thousands of orders per day, a "chatty" shipping module can fill gigabytes of log in a few weeks. If the file is too large, the log page in the admin will not open it fully.
- Log rotation is most reliably done with server tools (logrotate), not from PHP.
How are customer files and digital products stored?
The upload/ and download/ folders are often confused, although their purposes are opposite.
upload: files from buyers
If a product has an option of the "File" type, the buyer uploads a document (a print layout, a photo for engraving). The file is saved in DIR_UPLOAD under a name with a random suffix, and the original name, internal name and unique code are written to the upload table. The order stores only the code, not the path. Therefore, deleting files from disk "by hand" leaves broken references in orders. Manage them properly via System → Maintenance → Customer Uploads: there you can see the original name, date and code.

download: digital product files
DIR_DOWNLOAD contains the files you add in Catalog → Downloads and link to products. The name on disk is also masked with a suffix, and delivery happens through the account controllerCode that receives a request and prepares data. More in the glossary → only after payment for an order with a status that grants download access. That is exactly why download must not be directly accessible via the web server: if storage is in the web root and the server has no access restriction, a paid course file can be downloaded by its direct URL, by guessing or finding the name.
Both folders must always be included in the backup together with the database. During a store migration, they are often forgotten because "it's just cache and logs" — and after launch it turns out that old orders have no customer layouts.
How to move storage outside the web root and configure permissions?
In 3.0 and 4.1, after logging into the admin, a security notice appears on the dashboard suggesting moving storage outside the public directory. The reason is simple: logs, sessions and customer files must not be accessible from a browser, and a session file is effectively a key to someone else's account. The broader context of admin protection is described in the article on OpenCart admin security.

If the automatic move did not work (due to permissions or open_basedir), do it manually:
- Enable maintenance mode and make a backup of the files and the database.
- Copy
system/storage/one level above the web root, for example from/tohome/ user/ public_html/ system/ storage/ /home/user/storage/. Make surevendor/has been copied. - In
config.phpandadmin/config.php, changeDIR_STORAGEto the new absolute path with a trailing slash. - Check that derived constants (
DIR_CACHE,DIR_LOGS, etc.) are built fromDIR_STORAGEand not hardcoded. - Open the storefrontWhat the customer sees: the home page, categories, product page, and cart. More in the glossary → and the admin, place a test order, and click "Refresh" in modifications.
- Only after verification, delete the old directory.
# права: власник — користувач, від якого працює PHP
chown -R www-data:www-data /home/user/storage
find /home/user/storage -type d -exec chmod 755 {} \;
find /home/user/storage -type f -exec chmod 644 {} \;
Do not set 777 "just to be sure it works": on shared hosting, this gives write access to other accounts. If PHP runs as your user (typical for PHP-FPM on hosting), 755/644 is enough. During OpenCart installation, the installer checks write access to these folders, but after a move you will have to check it yourself.
Summary
- storage is the single directory where OpenCart writes during operation; its path is set by
DIR_STORAGEin bothconfig.php. cache/,logs/andmodification/are derived data and can be cleared; after clearing modification, be sure to click "Refresh".upload/,download/andvendor/are originals; they must be in every backup and never deleted "for cleanup".- In module code, use the
DIR_*and$this->cacheconstants, with a unique key prefix and a separate log file. - Keep storage outside the web root with 755/644 permissions — this closes access to sessions, logs and paid files.
Next, it is worth understanding how files from storage are included during request processing: start with the request path from index.php to the controller and the work of the Loader. Other materials on the engine's internal structure are collected in the Architecture and Files section.