Move an Megento site to new url

So I hade to move en megent site from topunder.se to test.topunder.se this is so that you can test and try new stuff on a site that is not you primary site.
Moving magneto was some hazzel it not as easy as other site is take som sql to make it work.

 

 

 

  1. First setup you webbserver  (This is only the basic)

 

<VirtualHost *:80>
 ServerAdmin webmaster@test.topunder.se
 ServerName test.topunder.se
 ServerAlias test.topunder.se# Indexes + Directory Root.
 DirectoryIndex index.html
 DocumentRoot /var/www/test.topunder.se/# Logfiles
 ErrorLog /var/log/apache2/error.log
 CustomLog /var/log/apache2/access.log combined
</VirtualHost>

 

 

 

2. Setup you sql

CREATE database test_topunder_se;
REATE USER 'top_test'@'localhost' IDENTIFIED BY 'top_test_pass';
GRANT ALL PRIVILEGES ON test_topunder_se.* TO 'top_test'@'localhost';
flush privileges;

 

3. Setup the copy of megento

cp -r topunder.se/ test.topunder.se

 

Change the database setting in the new copy of the site

vi test.topunder.se/app/etc/local.xml

 <connection>
 <host><![CDATA[localhost]]></host>
 <username><![CDATA[test_top]]></username>
 <password><![CDATA[test_top_pass]]></password>
 <dbname><![CDATA[test_topunder_se]]></dbname>
 <initStatements><![CDATA[SET NAMES utf8]]>
 <model><![CDATA[mysql4]]>
 <type><![CDATA[pdo_mysql]]></type>
 <pdoType><![CDATA[]]></pdoType>
 <active>1</active>
 </connection>

 

Now lets fill the database with some stuff. First we will dumpt the old and and make some change then reloadet inte the new database.

mysqldump -u root -p topunder > /topunder.sql    <--- dump the live database
sed -i 's/topunder\.se/test\.topunder\.se/g' /topunder.sql   <-- replace topunder.se with test.topunder.se ELSE SITE WILL NOT WORK
mysql -u root -p test_topunder_se < /topunder.sql    <--- insert the new data in the new database

 

Done Done !!