Need to migrate your wordpress or website easily to another host or machine? Here is the step by step guide to do that within 15 minutes. It’s easy! let’s see how it do in ubuntu or linux server.
1.Install component on new host
You need to make sure every component which need to run server on new host. Which are,
- apache2 or lightpd
- phpmyadmin (not necessary)
If your server is run on ubuntu you can install these dependencies by running
#apt install <package-names>
To configure database you need to know root password which was the password you entered when you was installing the mysql. Then you have to create a database exactly as your current wordpress database name ( you can see it in
define('DB_NAME', 'dbname'); ). This is not mandatory. you can use any databasename. Later you can change it in wp-config.php file.
Then you have to move current host machine. You can backup mysql database name in to file using
mysqldump -u <username> -p <databasename> > <sql_file_name>
Then you are prompted for password, type and enter. If you have correctly defined database name and password you have a backup file in the directory.
You can use phpmyadmin alternatively to export database to a file if you have configured phpmyadmin.
Also you have to create separate user for wordpress and grant all privileges on database you created. You can easily do it with phpmyadmin. You can use exact username as in your current wordpress server is configured. You can see it in wp-config.php
Also update the password which is wordpress user’s.
3. Copy wordpress directory to new host
For minimal configuration copy wordpress directory exactly as current location. It’s better if your current username of linux is same if your wordpress directory is in home directory rather than default apache server directory. If you have different user name and your wordpress server directory is in home directory we have few configuration in apache2 server. I will explain it later.
4. Copy and configure apache2 server
If your new host is not using for hosting for any other site It’s easy to configure. Assuming you are hosting just only this wordpress site currently then just copy /etc/apache to new host’s /etc/ directory. Before you do that backup current directory by typing
#cp -R /etc/apache2 /etc/apache2.bak in case of something goes wrong. Then you may stop apache server running on new host. Then copy current host’s apache2 directory to new host and give correct permission.
#cp -Ru <current-host's-apache2-dir> /etc #chown -R root:root /etc/apache2 #service apache2 start [or restart]
If apache server successfully started you are done almost.
If you are currently running any other servers on apache2 you need to manually copy some file from current apache2 directory to new apache2 directory without copying whole folder. This is depend on how your current apache server is configured. You can learn how to configure apache server here.
4. Finish it.
Then try to run your server by localhost or your domain name. you may see Cannot connect database or Database Error or you will successfully launch it. If you see any error like above you have to configure wp-config.php. If your server cannot load it’s error in apache server. Read log for resolve error in /var/log/apache2 . When you editing wp-config.php you have to correctly configure database name,username,password,host in appropriate field. Then you have successfully migrated it.