0

I have been developing a WordPress website for a client, working from my own machine utilizing WAMP to create a local environment on which to work.

Now, the problem is that the website needs to go live. I understand how to use an FTP client, and that's not a problem. I have the details for the domain etc. There is an existing website already there, and I would like to know if it's possible to upload the new website while keeping the old one running, but that is not the main issue.

I have been having trouble transferring the website from one machine to another, and I believe that this has to do with properly exporting/importing the database. This is the area that I am struggling with. To make things even more difficult, I wish to upload the new website to the server but use the database that is already in place with the existing website, for the client's benefit. Is this possible? How would I achieve this? If it is not, what are my alternatives?

Apologies for the short essay, but I thought it best to paint as clear a picture of my situation as possible. Thanks in advance for time taken to read/respond to this.

  • By reusing database do you mean using existing WP data/tables, or do you mean adding the data of your new site in same database old one uses? – Rarst Jun 12 '15 at 15:34
1

Moving your sites

My recommendation would be to use the the duplicator plugin. Far and away the easiest method I've used to back-up, move, and restore sites from local to production or from one host to another.

If the old site is WordPress - sounds like it is, you may want to consider creating a sub-domain and then using duplicator on the old site to back-up and then restore the old site to the new sub-domain.

mysite.com -> old.mysite.com

Then use duplicator to back-up your local dev site and then restore it to the location of the original site.

Connecting to the old DB

Once you have both sites on your host mysite.com and old.mysite.com you could change the settings in the wp-config.php of the new site (now mysite.com) to point to the db of the old site (old.mysite.com) like so:

// wp-config.php

define ( 'DB_NAME', 'olddbname' );
define ( 'DB_USER', 'olddbusername' );
define ( 'DB_PASSWORD', 'olddbpassword' );
define ( 'DB_HOST', 'old.mysite.com' ); 

In fact you could probably just copy the DB definitions from the wp-config of old.mysite.com into the wp-config of the mysite.com.

  • I'd comment out the db definitions present for mysite.com.

Can you clarify what you want to accomplish by doing this? The problem with pointing the new site to the old db is that it will also use the old site theme etc. A sum zero really. If your just trying to get the posts and pages from the old site to the new, I'd use the export/import tools that come packaged with WordPress. There are also syndicate plugins (FeedPress is my preferred one) that seem to be more robust than the WordPress import/export tools.

0

If your client's existing site is a wordpress site and you just want to use your new theme then you can just upload the theme from your local PC to the remote server and change the theme out in the remote backend.

Either way, how you run both sites simultaneously will differ depending on your exact setup.

As far as transferring your database goes, I assume you're exporting it as a .sql file? After you export it from your local database, open the file in a text editor (Notepad++ works well), do a search/replace on the file to replace http://localhost to http://yourdomain.com. Then upload the modified sql file to the remote database. You'll also have to open the config.php file in the root of your wordpress directory and change out the database credentials to be those of the remote database.

0

You can easy plugin transfer to other host https://wordpress.org/plugins/wp-clone-by-wp-academy/

localhost 1: first install plugin your localhost wordpress. 2: goto wp clone create local backup. 3: copy backup .zip upload any host/server.

host/server 1: first install plugin your host/server wordpress. 2: goto wp clone select restore backup. 3: localhost backup link paste.

enjoy

0

When transferring a db from any origin to another in WordPress, you need to update some key tables to be replaced with the host's pathname and the domain.

Here's a handy SQL snippet I use regularly when doing this manually.

-- Avoid updating serialized strings with "NOT LIKE '%{%'"
UPDATE wp_options SET option_value = REPLACE(option_value, '//olddomain.com', '//newdomain.com') WHERE option_value NOT LIKE '%{%';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '//olddomain.com', '//newdomain.com') WHERE meta_value NOT LIKE '%{%';
UPDATE wp_posts SET post_content = REPLACE(post_content, '//olddomain.com', '//newdomain.com') WHERE post_content NOT LIKE '%{%';
UPDATE wp_posts SET guid = REPLACE(guid, '//olddomain.com', '//newdomain.com') WHERE post_type = 'attachment';

-- File paths
UPDATE wp_options SET option_value = REPLACE(option_value, '/home/old/path', '/home/new/path') WHERE option_value NOT LIKE '%{%';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '/home/old/path', '/home/new/path') WHERE meta_value NOT LIKE '%{%';

However, in most cases I use wp-sync-db to handle this for me. It can be found here: https://github.com/wp-sync-db/wp-sync-db

I would highly recommend using the plugin above if you are unfamiliar with SQL querie, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.