Admin
Moderating
Donor Member
Master Member
Elite Member
Active Member
- Mai 31, 2020
- 2,980
- 1,693
Security hardening starts with proper file permissions, then web server rules to reduce attack surfaces.
1. File Permissions (base requirement)
Apply these permissions before webserver rules. Never use 777 globally.- Folders: 755
- PHP, twig, html, css, js files: 644
- Writeable directories (only these folders need write permission):image/, system/storage/cache/, system/storage/logs/, system/storage/download/, system/storage/upload/Set these writable folders to 755 (or 775 if your host requires group write).
- Critical folders must be read-only: catalog/, admin/, install/ (delete install folder completely after setup).
- Do NOT give PHP execution permission inside upload/image directories.
- Remove write permission from PHP files after installation.
- Delete unused files and old leftover modules/themes from server.
2. Apache (.htaccess rules, place at site root)
- Disable directory browsing
Options -Indexes
- Block access to sensitive folders
<FilesMatch "\.(php|twig)$">
<If "%{REQUEST_URI} =~ m#^/(system|catalog|admin)/#">
Require all denied
</If>
</FilesMatch>
- Block PHP execution inside image and upload folders
<Directory "/image">
<FilesMatch "\.(php|phtml|php5|twig)$">
Require all denied
</FilesMatch>
</Directory>
<Directory "/system/storage/upload">
<FilesMatch "\.(php|phtml|php5|twig)$">
Require all denied
</FilesMatch>
</Directory>
- Prevent access to config files
<Files "config.php">
Require all denied
</Files>
<Files "admin/config.php">
Require all denied
</Files>
- Disable unsafe PHP functions in htaccess (if host allows php_value)
php_value disable_functions eval,passthru,system,shell_exec,popen
3. Nginx server block rules
- Disable directory listing
autoindex off;
- Deny direct access to sensitive folders
location ~ ^/(system|catalog|admin)/ {
deny all;
}
- Block PHP execution in image and storage upload folders
location ~ ^/(image|system/storage/upload)/.*\.(php|twig)$ {
return 403;
}
- Block config.php
location ~ /config\.php$ {
return 403;
}
- Restrict PHP entry point, only allow index.php
location ~* ^(?!/index\.php).*\.php$ {
return 403;
}
- Limit request size to prevent large malicious uploads
client_max_body_size 32M;
Extra OpenCart security practices
- Rename your admin folder path, do not keep default /admin.
- Restrict admin panel access by IP in Apache / Nginx if you have static IP.
- Use strong admin passwords and enable 2FA if your OpenCart version supports it.
- Remove unused extensions and themes, delete leftover module files.
- Regularly clear cache and review logs under system/storage/logs/.
- Always backup database + files before installing new modules.
- Test all webserver rules on staging first, bad rules can break your store.