Migrating OpenCart requires special attention to two things: config files with paths and URLs, and database tables with orders and customers. An incorrect migration can break the store and lose orders.
OpenCart file structure
| Directory/file | What it stores | Migration importance |
|---|---|---|
| config.php | Paths and database credentials (root) | Critical |
| admin/config.php | Paths and database credentials (admin panel) | Critical |
| image/ | Product images | Large volume, don't forget it |
| system/storage/ | Logs, cache, sessions | Clear before migrating |
| .htaccess | SEO URLs, Apache rules | Important for Nginx |
Step 1: Preparation — clear out junk
># Clean up temporary files before creating the backup
rm -rf /var/www/opencart/system/storage/cache/*
rm -rf /var/www/opencart/system/storage/logs/*.log
rm -rf /var/www/opencart/system/storage/session/*
Step 2: Back up files and the database
# File archive
tar -czf opencart-files.tar.gz /var/www/opencart/
# Database dump (with all data: products, orders, customers)
mysqldump -u ocuser -p ocdb --single-transaction --routines --triggers > opencart-db.sql
Step 3: Transfer and restore
># Transfer to the new server
rsync -avz /var/www/opencart/ root@new-server:/var/www/opencart/
# Restore the database
mysql -u newocuser -p newocdb < opencart-db.sql
Step 4: Update config.php (both files!)
># /var/www/opencart/config.php
define('HTTP_SERVER', 'https://www.new-domain.com/');
define('HTTPS_SERVER', 'https://www.new-domain.com/');
define('DIR_OPENCART', '/var/www/opencart/');
define('DIR_APPLICATION', '/var/www/opencart/catalog/');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'newocuser');
define('DB_PASSWORD', 'NewPass123');
define('DB_DATABASE', 'newocdb');
# /var/www/opencart/admin/config.php
define('HTTP_SERVER', 'https://www.new-domain.com/admin/');
define('HTTPS_SERVER', 'https://www.new-domain.com/admin/');
define('HTTP_CATALOG', 'https://www.new-domain.com/');
define('DIR_OPENCART', '/var/www/opencart/');
define('DIR_CATALOG', '/var/www/opencart/catalog/');
Step 5: Update the URL in the database
># When changing the domain, update the store settings
mysql -u newocuser -p newocdb <<'SQL'
UPDATE oc_setting
SET value = 'https://www.new-domain.com/'
WHERE `key` = 'config_url';
UPDATE oc_setting
SET value = 'https://www.new-domain.com/'
WHERE `key` = 'config_ssl';
SQL
SEO URLs on Nginx: OpenCart uses
.htaccess for SEF URLs. On Nginx, add this to your config:
>location / {
try_files $uri $uri/ @opencart;
}
location @opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
Post-migration checklist
- The homepage and categories open correctly
- The product page displays with images
- Add a product to the cart and place a test order
- Log into /admin — make sure every section works
- Check the order history — everything should be there
- Check order email notifications
- Make sure payment modules are configured for the new domain
Payment systems: After changing the domain, be sure to update the callback URL in your payment providers' dashboards (YooKassa, LiqPay, Stripe, etc.). Otherwise payments won't be processed.