0

Okay so, I'm using ubuntu 18.04 (downloaded from windows store). I set up LAMP stack using the basic installation commands. I was able to set up few websites that run on localhost using wordpress. Now my question is, is there a way I can migrate wordpress site from localhost to another localhost site using old database?

I also use phpmyadmin through Ubuntu terminal. Below is the source I used to get started on this migration but I ran into many problems. It would be great if someone can help me get started with basic steps. I just want to use my site (say, site1.com, which runs on localhost) and use its database for the new site i've created (say, site2.com, which also runs on localhost).

Any help would be appreciated.

https://websiteforstudents.com/migrate-wordpress-on-ubuntu-17-04-17-10-to-a-new-host-with-apache2-mariadb-and-php/

  • Hi, do you want to migrate only the database? Or the whole wordpress (theme+plugins+database) ? – Fabrizio Mele Feb 27 at 20:19
  • Hey, so well I have the basic theme (i was just testing it on ubuntu) but I would love to know if i can do all of that – Devon Karyo Feb 27 at 20:22
  • It's not a subject for an answer, but take a loot at this plugin. It creates a package with the whole website and a php file to install it, you just upload wherever you want to transfer the website, prepare a database like a standard wordpress install, navigate to the installer and... magic! – Fabrizio Mele Feb 27 at 20:27
  • No I know about the plugin, I want to know if I can do all that through ubuntu terminal or no? – Devon Karyo Feb 27 at 20:36
0

Migrating Wordpress is not that a big deal. The only tricky part is if the website changes domain, e.g. from https://domain.com to https.//newdomain.com. As general instructions:

Pack up the Wordpress directory using tar

You have to create a package to transfer over to the new location. To do this navigate inside the main wp directory and use a command like this: tar -cvfz my_wp_packed.tar .. This means "pack everything here (the .) inside my_wp_packed.tar and compress it". This should result in a .tar.gz file. Copy it somewhere and keep it aside for now.

Dump the database using mysqldump

Find the database credentials (cat wp-config.php inside the wp main directory will show the configuration, among which you will find the credentials) and move to your home directory, then use this command to dump the whole database to a .sql file: mysqldump -u my_db_user -pmy_db_password my_wp_database > my_wp_db.sql. Substitute username, pass and database with your data. look out: the password must be attached to the -p flag, like in the example, no spaces!. Take the resulting .sql file aside and move to the next step.

Move everything to the new location and unpack the site

The new location could be another directory on the same server, or another server. In the first case, you have just to create the new root (for example with mkdir /var/www/vhosts/my_new_webroot) and cd into it. Copy here the .tar.gz file created in step 1. Then, unzip the website with tar -xvf my_wp_packed.tar.gz. If the other location is on another server use scp to copy it over.

Migrate and import the database

Once you've set up the new database for the website, you are ready to import the sql. First you have to replace inside the file, which is editable as a text file with nano, the values of the siteurl and home options, found inside the wp_options table. Just place your new website url in place of the old one. The location inside the file looks something like this:

(36, 'advanced_edit', '0', 'yes'),
(37, 'comment_max_links', '2', 'yes'),
(38, 'gmt_offset', '0', 'yes'),
(39, 'default_email_category', '1', 'yes'),
(40, 'siteurl', 'https://myoldwebsite.com', 'no'),
(41, 'template', 'mystile', 'yes'),
(42, 'stylesheet', 'mystile', 'yes'),
(43, 'home', 'https://myoldwebsite.com', 'yes'),

Once you did this you are ready to import: mysql -u my_new_db_user -pmy_new_db_password my_new_database < my_wp_db.sql

And you're done! Do not forget to remove the tar and sql files from the wordpress directory, to avoid anyone from downloading them.

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.