Moving Magento

So I was asked to help finish moving a magento (1.9) installation to a new server the other day. To sum it up, it was not fun

They had already moved the files and had everything installed and updated the database connection string, however it was still throwing an error. The plan was to set this site up on a subdomain, so we could test a few things, update some things and then go live on the new server

After a while of trying to find the logs ( looking in /var/log/apache and /var/www/magentoinstall/var/log) I was having no luck of trying to find out what was causing the error. Until I found /var/www/magentoinstall/var/report. This folder seemed to be what I was looking for. After the fact, looking up some magento docs, var/report seems to be where magento logs uncatched errors by default here is a nice run down. Every time the site failed to load, it spat out a file into this folder, which included an interestly useful error

root@myserver:/var/www/magentoinstall/var/report# cat 828704810349
a:4:{i:0;s:113:"SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'myoldDBserver' (4)";i:1;s:2753:"#0 /var/www/magentoinstall/lib/Zend/Db/Adapter/Pdo/Mysql.php(109): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 /var/www/magentoinstall/lib/Varien/Db/Adapter/Pdo/Mysql.php(320): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 /var/www/magentoinstall/lib/Zend/Db/Adapter/Abstract.php(460): Varien_Db_Adapter_Pdo_Mysql->_connect()
#3 /var/www/magentoinstall/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SET NAMES utf8', Array)
#4 /var/www/magentoinstall/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('SET NAMES utf8', Array)
#5 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Resource.php(169): Varien_Db_Adapter_Pdo_Mysql->query('SET NAMES utf8')
#6 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Resource.php(110): Mage_Core_Model_Resource->_newConnection('pdo_mysql', Object(Mage_Core_Model_Config_Element))
#7 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(320): Mage_Core_Model_Resource->getConnection('core_write')
#8 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(350): Mage_Core_Model_Resource_Db_Abstract->_getConnection('write')
#9 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(335): Mage_Core_Model_Resource_Db_Abstract->_getWriteAdapter()
#10 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(360): Mage_Core_Model_Resource_Db_Abstract->_getReadAdapter()
#11 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php(134): Mage_Core_Model_Resource_Db_Abstract->getReadConnection()
#12 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Config.php(1354): Mage_Core_Model_Resource_Db_Collection_Abstract->__construct(Object(Mage_Core_Model_Resource_Website))
#13 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Config.php(1386): Mage_Core_Model_Config->getModelInstance('core_resource/w...', Object(Mage_Core_Model_Resource_Website))
#14 /var/www/magentoinstall/app/Mage.php(491): Mage_Core_Model_Config->getResourceModelInstance('core/website_co...', Object(Mage_Core_Model_Resource_Website))
#15 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Abstract.php(208): Mage::getResourceModel('core/website_co...', Object(Mage_Core_Model_Resource_Website))
#16 /var/www/magentoinstall/app/code/core/Mage/Core/Model/Abstract.php(213): Mage_Core_Model_Abstract->getResourceCollection()
#17 /var/www/magentoinstall/app/code/core/Mage/Core/Model/App.php(608): Mage_Core_Model_Abstract->getCollection()
#18 /var/www/magentoinstall/app/code/core/Mage/Core/Model/App.php(466): Mage_Core_Model_App->_initStores()
#19 /var/www/magentoinstall/app/code/core/Mage/Core/Model/App.php(349): Mage_Core_Model_App->_initCurrentStore('', 'store')
#20 /var/www/magentoinstall/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#21 /var/www/magentoinstall/index.php(153): Mage::run('', 'store')

It was interesting as it was using the database server connections string, re-checking all the config files (everything under /var/www/magentoinstall/app/etc just to make sure) I finally resorted to doing a search for the old connection string (using ag ) in the magento instance

Magento seems to agressively cache everything. It found a few hits of the old connection string under /var/www/magentoinstall/var/cache in classPathCache.php and a few of the mage--xxx folders. After a quick search, it was deemed OK to wipe this folder clean. Sure enough, after deleting the cache folder we had progress. No more errors, but the site was redirecting to the main domain of the website (which was not good as we wanted to set it up on a subdomain first)

Without access to the admin interface to update the domain, modifying this via the database was the next best option. There were a few strings that we need to update to make sure nothing breaks, seems that magento tried to do an inbuild CDN style configuration so it pulls assets from varying domains/paths to speed things up

root@myserver:/var/www/magentoinstall# mysql -u root -p -h mynewDBserver
mysql> use database mymagentodb;
# Main domain

mysql> update core_config_data set value = '' where path = 'web/secure/base_url';
mysql> update core_config_data set value = '' where path = 'web/unsecure/base_url';

mysql> update core_config_data set value = '' where path = 'web/unsecure/base_media_url';
mysql> update core_config_data set value = '' where path = 'web/secure/base_media_url';

mysql> update core_config_data set value = '' where path = 'web/unsecure/base_js_url';
mysql> update core_config_data set value = '' where path = 'web/secure/base_js_url';

mysql> update core_config_data set value = '' where path = 'web/unsecure/base_css_url';
mysql> update core_config_data set value = '' where path = 'web/secure/base_css_url';

Okay great. More progress, the site is loading, but not over https. I was getting a 404 error when trying to load over https. Back to the drawing board This was just a config error within apache. I had to change the default SSL apache config, to point to the right folder as the document root, enable the site and restart apache


One other thing I can across in my research was that Magento 1.9 reads in all and any xml files that are located in app/etc. So if you have copied the local.xml file during development and made local-dev.xml it will still load that in and read any configuration settings that have been placed in here. This tripped alot of people up as it would load old or development database connection strings in and mess things up. So rename things to .old or .dev or something other then .xml