If you missed my post about migrating the WordPress site between hosts here is another one very similar about migrating OpenCart store from one location to another or from a subfolder to the root directory on the same server to be more precise. The common mistake occurs somewhere along the way and I’ll let you know what it is so you can skip the errors and perform your OpenCart migration like a boss.
There are two common scenarios that lead to migration of OpenCart store and those are: A) you are redesigning the website and you have installed OpenCart in a subfolder during development (for example like this: www.somewebsite.com/newsite);
B) you are working on your own hosting server (or localhost) and have many projects going on there which must be transferred to their desired location once you’re finished. Either way the process of transferring OpenCart project is basically the same. I will describe step by step how to transfer OpenCart store from subfolder to the root directory on the same server and mention the small differences at the end of the post regarding the transfer between different domains/host servers.
I said earlier that I will point out the common mistake that throws an error screen after the transfer is complete, so here it is. This is something that is not mentioned in tutorials about transferring websites between servers, maybe because that is something that you are supposed to know prior to executing this kind of operation. However, for those who are less familiar with databases (MySQL in this case) the thing that will give you an error after you complete your transfer from the subfolder to root directory of the server is the database username. So keep this in mind and I’ll explain more along the way. The steps to transfer OpenCart store are as follows:
1. Backup the original content from the root directory to your local computer
This is no brainer and you’ve done this many times before. Use your FTP client and copy all the content from public_html (or www) folder to your computer. This may take a while depending on the number of the files involved or, if it is a parked website, won’t take much time at all. Once this operation is done make a .zip or .rar archive of this data for safekeeping.
2. Transfer OpenCart store from the subfolder on the server to your local computer
After you made a backup copy of the original website it’s time to download the OpenCart project you’ve been working on. Once more, use FTP client and download all the OC data to a folder on your computer.
3. Export the MySQL database
The easiest way to do this is to use phpMyAdmin (tool in your hosting cPanel). Identify the database associated with the OpenCart project you want to transfer in the left panel and click Export tab. Leave the default “Quick” option selected and click Go to download the database to your computer. It should be a .sql file (e.g. your_opencart_database.sql ).
4. Upload the OpenCart files from local computer to Root directory
Delete the old website files from the root directory on the server and upload your OpenCart project files (those that you downloaded in step 2).
5. Create new MySQL Database
I already described this process in the post How to create MySQL Database? I would point out that the common error I mentioned at the beginning of the post is occurring right here. That is database username. After creating new MySQL database you have to assign a user to it. You create a new user in the MySQL® Databases section of cPanel and make sure that it has the same name and password as those you used in your project (the one you downloaded from subfolder in step 2). If you create a new user with a new database password chances are that you’ll get an error “Access denied for user…” at the end of the process.
P.S. Some hosting providers and web servers are configured so that this error may or may not occur. There are many various scenarios, and a good example can be found on this tech blog.
6. Import the old database into new one
Use the same tool as for exporting the database, I use phpMyAdmin. Select the database you created in step 5, make sure that it has no tables (empty database) and select the Import tab. Click on Browse, locate your old database that you downloaded in step 3 and upload it.
Practise patience meanwhile because this can take a while depending on the data you have in your database as well as your internet connection.
7. Edit the config files config.php and admin/config.php
The physical part of the migration process is done. Now you have to edit the 2 config.php files. First is located in the root directory of the server and second is in “admin” folder. Open the first config.php file in text editor and modify the following lines of code:
define(‘DIR_APPLICATION’, ‘/home/system username/public_html/newsite/catalog/’); define(‘DIR_SYSTEM’, ‘/home/system username/public_html/newsite/system/’); define(‘DIR_DATABASE’, ‘/home/system username/public_html/newsite/system/database/’); define(‘DIR_LANGUAGE’, ‘/home/system username/public_html/newsite/catalog/language/’); define(‘DIR_TEMPLATE’, ‘/home/system username/public_html/newsite/catalog/view/theme/’); define(‘DIR_CONFIG’, ‘/home/system username/public_html/newsite/system/config/’); define(‘DIR_IMAGE’, ‘/home/system usernamepublic_html/newsite/image/’); define(‘DIR_CACHE’, ‘/home/system username/public_html/newsite/system/cache/’); define(‘DIR_DOWNLOAD’, ‘/home/system username/public_html/newsite/download/’); define(‘DIR_LOGS’, ‘/home/system username/newsite/system/logs/’);
– the ‘newsite’ is the subfolder where your project was before you decided to move it to the root directory, so you have to delete it from the URLs.
– ‘system username’ should be your cPanel username.
In the same file edit the following lines of code:
define(‘DB_USERNAME’, ‘your_db_username’); define(‘DB_PASSWORD’, ‘your_db_password’); define(‘DB_DATABASE’, ‘your_opencart_database’);
NOTICE: your_db_username and your_db_password should be the same you used in your OpenCart project in the development process while your_opencart_database is the name of the new database created in step 5.
Same thing is to be done in the admin/config.php file. Similar lines of code similar changes. Off you go.
8. Set the file permissions of both config.php files to 444
Once you are done with modifying the config.php files set the file permissions of both files to 444 (read-only).
Now open your browser and visit the address of the website you redesigned and successfully transferred just now… I hope you don’t have any errors or white screen of death 🙂
The only differences in transferring OpenCart project between servers and with other domain names are that you have to purchase new domain and set up hosting plan before starting the step 2 (skip the step 1 since you are moving to another server and/or domain) and for the last step you should update your name servers to point to your new domain/host or eventually leave the redirection on old website towards your new website.
DISCLAIMER: I used the domain name somewebsite.com only for the sake of this tutorial and ease of understanding the process described here. I do not own this domain and mentioning it in this post is for identification purposes only. Use of this domain name does not imply endorsement.