Home WordPress WordPress: Migrating WordPress site from one server to another

WordPress: Migrating WordPress site from one server to another

by Kliment Andreev

First, make sure that you have Apache, PHP and MySQL (MariaDB) installed and properly configured. In order to avoid any problems down the road, make sure that you have the same version of the software. There are some Wordpress plugins that allow you to backup/restore the database and the content, but we’ll do this manually.

Let’s say that I want to migrate www.iandreev.com from one server to another. First, change the DNS so the hostname points to the new IP. Create a test HTML file and see that you can actually browse to the new web site. Once completed, stop the Apache web server and MySQL database on the old server. Go to the root folder where your Wordpress installation is and open the wp-config.php file. These are the values that you will need.

/** The name of the database for WordPress */ 
define('DB_NAME', 'wwwiandreevcom'); 
/** MySQL database username */ 
define('DB_USER', 'username); 
/** MySQL database password */ 
define('DB_PASSWORD', 'password'); 
/** MySQL hostname */ 
define('DB_HOST', 'localhost'); 

Backup this database with:

mysqldump -u <username>  -p <password> databasename > /somewhere/dbname.sql 

Note: Don’t leave a space between “-p” and the password.

Once you have the database backed up, transfer it to the new server using scp or whatever you use to transfer files between servers. In my case I typed this command on the old server.

scp wwwiandreevcom.sql [email protected]: 

Where wwwiandreevcom.sql is the backup file, myusername is the username that I use on both servers and www.iandreev.com is the new server hostname.

Create the database on the new server and grant necessary rights.

create database wwwiandreevcom; 
grant all privileges on wwwiandreevcom.* to "username"@"localhost" identified by "password"; 
flush privileges; 

Make sure that the database name, username, password and host are the same as on the old server.
Now, restore the database.

mysql -u username -p wwwiandreevcom < wwwiandreevcom.sql 

Where wwwiandreevcom is the database being restored and wwwiandreevcom.sql is the dump file of the database that we transferred from the old server.

There is no need to install Wordpress from scratch on the new server, so go back to the old server and compress the Wordpress installation folder.

tar czvf zipfile.tgz www.iandreev.com 

Where www.iandreev.com is my Wordpress installation directory. Transfer the tarball to the new server.

scp zipfile.tgz [email protected]: 

Move the file where your new installation will be and unpack it.

tar xvf zipfile.tgz 

Make sure to change the owner to the user that runs Apache if needed. In my case I had to do:

chown -R www:www www.iandreev.com 

That’s it. Go to www.whatever.com and you’ll see your website/blog back in action.
Note: If you receive the following error:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Then install the following Apache modules and restart Apache.

pkg install php5-pdo_mysql
apachectl graceful

Related Articles

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More