Magento-moving sourcecode around with different base_url

Magento-moving sourcecode around with different base_url

Posted: 10 years ago in  PHP | Magento |


Magento is very popular to build an e-commerce website at a glance. It is a consistent system with many many useful configuration.


Magento is very popular to build an e-commerce website at a glance. It is a consistent system with many many useful configuration.

I am also a newbie with magento. Recently, I did a very irregular step that is building everything on server, then move it back to localhost for a faster data input and modification. It took me couple hours dealing with the base_url configuration. For anyone have same problem, take a look at my step to save a bit your time :-D

Scenario: I backup database and sourcecode then restore on localhost with same configurations, when typing in the url, it redirect me to live server :-?

  1. Dump current database on server to sql file:
    mysqldump -u username -p databasename > databasename.sql
  2. Copy sourcecode to localhost
  3. Extract sourcecode, restore database. Called localhost address is local.magento.com (create virtualhost in apache, check it if you like the pretty url in localhost). Make sure every configuration are same as on server
  4. If you use different databasename, do not forget to update dbname in app/etc/local/xml
  5. Go to mysql and find core_config_datatable. Here is what you get:
    use databasename;
    select * from core_config_data; #this show all the entries in a particular table

    This is what you get

    +-----------+---------+----------+--------------------------+--------------------------------+
    | config_id | scope   | scope_id | path                     | value                          |
    +-----------+---------+----------+--------------------------+--------------------------------+
    |         1 | default |        0 | catalog/category/root_id | 2                              |
    |         2 | default |        0 | web/seo/use_rewrites     | 1                              |
    |         3 | default |        0 | web/unsecure/base_url    | http://mywebsite.com/          |
    |         4 | default |        0 | web/secure/base_url      | http://mywebsite.com/          |
    |         5 | default |        0 | general/locale/code      | en_US                          |
    |         6 | default |        0 | general/locale/timezone  | America/New_York               |
    |         7 | default |        0 | currency/options/base    | USD                            |
    |         8 | default |        0 | currency/options/default | USD                            |
    |         9 | default |        0 | currency/options/allow   | USD                            |
    +-----------+---------+----------+--------------------------+--------------------------------+
    1. Update value of web/unsecure/base_url and web/secure/base_urlto local.magento.com or new domain:
      update core_config_data set value='http://local.magento.com/' where config_id = '3';
      update core_config_data set value='http://mywebsite.com/magento/' where config_id = '4';

      Note: Take a look at new url:
      http://local.magento.com/
      Even we work in localhost, we need http:// and the slash at the end. Without it, you get error of request or the css/js/images file are not found.

  6. If you have previously configured Merge CSS and JS, you would change its value to 0. They are also found in this table named "dev/js/merge_files" and "dev/css/merge_css_files" It is able to change them back in System > Configuration in admin of magento
    UPDATE 'core_config_data' SET 'value' = 0 WHERE 'path' = "dev/js/merge_files" OR 'path' = "dev/css/merge_css_files";
  7. Go to sourcecode and clear everything in var/cache and var/session
  8. You have a identical copy of what you did on server :)

Enjoy !!!