Home > Magento > Howto change the Base URL in Magento via command line

Howto change the Base URL in Magento via command line

August 7th, 2009

A quick howto that complements chandansweb’s article on how to change the Base URL using phpMyAdmin. On production servers I do not install phpMyAdmin and therefore I need to use command line. Here is how in 3 steps:

Step 1: Login to mysql (command line) and update two records:
Note that the values in square brackets need to be filled with your specific values.

update [prefix]core_config_data set value="http://[domain]/[rootfolder/]" where path='web/unsecure/base_url';
update [prefix]core_config_data set value="http://[domain]/[rootfolder/]" where path='web/secure/base_url';

Step 2: Clear cache by removing entries in the /var/cache/* folder:
Careful with this one, make sure you are pointing to the right folder.

rm -rf /var/www/[path to html folder]/var/cache/*

Step 3: Force Magento to clear its database cache by running this php file:
Note that I recommend that you copy and paste this code in a file at your Magento root folder. Then point your browser to this file, it will trigger the clearing of various cache objects in Magento.

<?php
ob_implicit_flush(true); //Saves having to flush manually
set_time_limit(0); //Set time limit to unlimited, though we shouldnt need to
ignore_user_abort();

require_once("app/Mage.php");
umask(0);

// clean overall cache
Mage::app()->cleanCache();

// clear 'refresh_catalog_rewrites':
Mage::getSingleton('catalog/url')->refreshRewrites();
echo 'Catalog Rewrites was refreshed succesfuly<br>';

//  clear 'clear_images_cache':
Mage::getModel('catalog/product_image')->clearCache();
echo 'Image cache was cleared succesfuly<br>';

//  clear 'refresh_layered_navigation':
Mage::getSingleton('catalogindex/indexer')->plainReindex();
echo 'Layered Navigation Indices was refreshed succesfuly<br>';
?>

That should do it, you should now be able to point to your production store and it will pull the right URLs. It worked for me after various attempts of other howto’s. The above steps are the ones that worked for me.

Magento , ,

  1. graham cooke
    | #1

    this is an amazing tip – thanks so much!

    Graham

Comments are closed.