How can I safely port my wordpress blog to localhost? - php

I'm trying to make local development copies for my wordpress blog. I tried first to install wordpress locally (on XAMPP for Windows), install the plugins then import the live data (from a DB backup). The problem is whenever I import the live data I start getting all sorts of errors, even after I change the blog's URL through the database.
Also, the redirection rules I have on my server don't seem to work locally (whether set by wordpress or some of its plugins).
So is there a safe way to just grab the whole thing and make it work locally exactly like the server?
Your help is much appreciated :)

get a full backup of all the files in your online wordpress installation
get a complete backup of the database in use
with any text editing software, process the SQL file of the database backup and change every occurrence of http://old.site with http://localhost
extract the files to your document root
edit wp-config.php to tweak database host/user/pass
import the modified SQL backup
login into admin panel, go to Options->Permalink and save to update permalinks
No need to install anything, just grab what you have online. On windows you might have to rename .htaccess

Maybe somebody will come up with a tool, tutorial or a full HOWTO on this, but in the meantime a few general things on migration:
The redirection rules probably don't work because Windows has trouble with the .htaccess file name due to the starting .. What I usually do is, add (or change) the AccessFileName directive in my Apache config to htaccess.txt that makes the file better usable on Windows. If that doesn't help, put the contents of .htaccess up here.
From my (albeit limited) Experience with Wordpress, it is better to make a raw copy of the Wordpress file and data structure, rather than installing a fresh version and adding all the plugins. There is so much change in the Wordpress code base (automatic update of plugins etc.) that problems are legion. You would then have to change the paths locally in the configuration files, or set up a local path structure that exactly imitates that on the server.
Can you post some of the errors you get when using the live data?

Perhaps a much simpler way would just be to add a host reference from the address of blog to local host e.g. http://en.wikipedia.org/wiki/Hosts_file. This would allow you to test your blog as if it were actually running on the domain without any of the potential pitfalls.

Here is my 2cents tip:
If you are using plugins, and one of them has an api-key (for an example, Google's analytical toolkit, requires a key), the key may be bound to the IP address where your wordpress blog is located and may fail under the localhost (127.0.0.1). So double check to see if you can obtain a global key which can work on any IP address. This is dependent on the service and plugin. Google Maps is one, Recaptcha is another that comes to mind.
Hope this helps,
Best regards,
Tom.

kemp's answer is just about perfect. I only wanted to add that you could download something like VirtualBox or VMware and install Linux to it and get a webserver up and running on the virtual machine. This would let you get past any WAMP-LAMP inconsistencies.

Kemp's answer is good - but you don't need to edit your SQL dump, or change the database.
Instead, add 2 lines to your wp-config.php file (I normally add them just above the comment line in the file:
define('WP_HOME','http://localhost');
define('WP_SITEURL','http://localhost');
/* That's all, stop editing! Happy blogging. */ <-- this line already present in the file.

Related

SFTP as a alternative method to auto-update wordpress-themes and plugins?

many wordpress-uses are not able to auto-update/upgrade their WordPress and plugins to a newer version without providing their FTP connection information. This is a difficult issue - since WordPress can’t write to the /wp-content folder directly.
i am on a root server and the server admin enables me to use sftp-client (like filezilla and WinSCP [no SSH itself ) to do all kinds of upload to the server.
question: untill now i have difficulties to get a auto-update option for themes and plugins – since here we need to have the ftp-credentials (and method): i am looking for a method to keep my WordPress install up-to-date and installing plugins in a hassle-free manner:
since it is not so easy if i server uses SFTP. i need a tool or a method to do this.
are there methods, ways and workaround for doing so – e.g. using phopseclib to remedy these deficiency!?
Well: how to go round this issue? I have tried to read through the documents: Is it correct that
a. one method is to define the FTP details in the wp-config.php file so WordPress will remember it.
b. write-access to /wp-content folder: another way and method is to provide WordPress with write access to the /wp-content folder by accessing the FTP root file and changing the folder file permission (CHMOD)
to 775 rather than the default 755 and 644.
But wait: there is a interesting workaround for doing so: we can do this by defining constant, FS_METHOD in the wp-config.php file. this way bypasses WordPress’s recurring prompts - and doing so we allow the wordpress auto-updates of the files to work.
a. Open /wp-config.php - located at wordpress/wp-config.php
b. Insert FS_METHOD: write the following line of code to the wp-config.php file, just below every other line of code.
define('FS_METHOD','direct');
FS Method
question: untill now i have difficulties to get a auto-update option for themes and plugins – since here we need to have the ftp-credentials (and method): i am looking for a method to keep my WordPress install up-to-date and installing plugins in a hassle-free manner: note: i am on a root server and the server admin enables me to use sftp-client (like filezilla and WinSCP [no SSH itself]!!) to do all kinds of upload to the server.
is this above described method okay to get a alternavive method to auto-update my wordpress-themes and plugins?
update: see the important thread:
What security concerns should I have when setting FS_METHOD to "direct" in wp-config?
https://wordpress.stackexchange.com/questions/189554/what-security-concerns-should-i-have-when-setting-fs-method-to-direct-in-wp-co
What I would like to know is what real concerns should I have around setting FS_METHOD to direct? Are there any other alternatives to installing the plugin? This is what the official documentation has to say:
FS_METHOD forces the filesystem method. It should only be "direct",
"ssh2", "ftpext", or "ftpsockets". Generally, you should only change
this if you are experiencing update problems. If you change it and it
doesn't help, change it back/remove it. Under most circumstances,
setting it to 'ftpsockets' will work if the automatically chosen
method does not.
(Primary Preference) "direct" forces it to use Direct File I/O
requests from within PHP, this is fraught with opening up security
issues on poorly configured hosts, This is chosen automatically when
appropriate.
head over to the answers to this: https://wordpress.stackexchange.com/questions/189554/what-security-concerns-should-i-have-when-setting-fs-method-to-direct-in-wp-co

Pulling from Git to Wordpress and Desktop Server

I'm having problems keeping consistent versions of a repository on different local machines, and pushing and pulling effectively.
When I worked with Rails, I could push and pull easily and all the files required to start a Rails server were included.
With Wordpress, I have to include files like wp-config.php in .gitignore so when I pull the repository to a new computer, I cannot start a local server (through Desktop Server). I did try manually transferring wp-config because that wasn't too inconvenient, but then a database error followed and I need a more complete solution.
How do you transfer entire WP repositories between developers through version control? I want to be able to push and pull, not drag and drop.
(One solution I thought of: Duplicate the WP base, connect the remote repository to the base, then pull and merge the updated site into the base server.)
(Another possible solution: moving the db config and salts lines from wp-config.php into dbsalts.php, then including that file in wp-config.php. I would then add dbsalts.php to .gitignore and remove wp-config, so the big important stuff would be ignored but the reduced wp-config would be pushed. Not sure if this would work, and we'd still have to drag and drop dbsalts.php.)
dbsalts.php
define( 'DB_NAME', ..... (redacted code for security)
...........................
define('AUTH_KEY'......
..........................
wp-config.php
include(dbsalts.php);
Currently using wpengine and desktop server, but I'm just now implementing this and open to suggestions.
*Private BitBucket Git Repository – While most of the time the only truly sensitive information in a WordPress install is in the wp-config file, which is preferable not to include in Git repository, keep whole sites in private repos, which are free from Bitbucket. Open-sourcing your entire site might make sense, but it’s something to think through thoroughly before doing so, and erring on the side of caution is a good policy, especially when doing client work.
*WP Migrate DB Pro – While Git can keep all of the site’s files in sync between environments, a different tool is required for keeping the MySQL databses in sync. WP Migrate DB Pro is an excellent plugin that automates this process.
Even if you get this to work you are going to have further problems with the database. 2 developers working on 2 different local WordPress sites can create a number of issues with data in the database.
Here's an example suppose both of you pull the site that has the following posts in the database: A, B, C.
Now you make a new post: 'D1' and the other developer make a different post: 'D2'. This will associate D1 and D2 with the same post ID (since D1 isn't at the second developer's WordPress database, the same is true for D2).
What you could do (in theory), is set up both machines to connect to the same remote database (you'll have to white-list both of your IP address, if they are different, for that particular install with WPEngine's support). You'll need to modify the local wp-config.php, which I believe will make it different from the one on the server, but that's okay, since you can include it in gitignore.
Now you might can both pull and push to the server without an issue. But I'd use BitBucket or GitHub and have only one of you pushing to the server. I'd also look at DeployBot.com at some point. It can push the code from BitBucket/GitHub to WPEngine's server through ftp automatically.
I use local configs based on the url by adding the following to wp-config.php:
$site_options_filename = dirname(__FILE__) . '/options-' . $_SERVER['SERVER_NAME'] . '.php';
if (!file_exists($site_options_filename)) {
die('missing config: ' . $site_options_filename);
}
This will look for a specific config file based on the domain you are viewing. I use a dev. prefix or similar for my local builds.
I also use a quick bash script to dump the db to a .sql file which I include in the commit whenever there are database changes that have to be propagated:
mysqldump -uyour_db_username -pyour_db_password --add-drop-table --create-options your_database_name > dump.sql
It's a simple task to run dump.sql against the database every time you pull and dump.sql has changed.

I want to duplicate my WordPress website, but how do i deal with the database?

I wish to duplicate my current website so I can play around and try new ideas, before putting them on my live site. The reason I want to duplicate is so I have all of the content etc, so I can see how it really looks. I understand I can just copy my entire WordPress install into another directory, but what do I do with my database?
Currently my WordPress is installed into the root directory, I will simple create a new directory called Dev. Then simple just add /Dev to my URL and voila, I can view my duplicated website.
But how do I deal with my database? I am using a MySQL database, hosted with GoDaddy.
(I want to change my hosting from GoDaddy to someone else once the renewal is up, mainly because of their support for SOPA. anyway that's for another time...)
If you have phpMyAdmin installed, you may export your wordpress database, then create a new database and import the .sql file you just exported. Next, configure the copied wordpress to use your new database. The configuration is in wp-config.php. Good luck :)
Like the other answers here i suggest you export your DB via phpmyadmin if can. You will however notice that all image URLS point to the old domain. To fix this run a find and replace script. I usually use this one: http://interconnectit.com/products/search-and-replace-for-wordpress-databases/
Good luck!
The simple way with GoDaddy is to log into your account, go to your hosting management and click the databases tab at the top and then look for phpMyAdmin.
Once in phpMyAdmin, go to the wordpress database and select the operations tab at the top and then use the "Copy database to:" feature.
If your version of phpMyAdmin doesn't show the copy database feature, you can export all tables of the database and import them into your duplicate database.
Hope this helps!
If you don't want to mess around with a new utility like phpmyadmin, you can install a wordpress plugin to back up your database. Then you can copy your files anywhere and use the same plugin to restore the database. I personally use UpdraftPlus - Backup/Restore.
It should be noted that moving your site to a new folder or domain will break a lot of the database data. A simple search and replace is not enough to fix it.
For more information, you can go here: Wordpress Codex

How to clone wordpress site for the develope purpose?

I have a wordpress site and I have to do modifications very often so i would like to create clone of that website for testing because i would like to test my modification first for a few days before i put them on my site.
There are links to the "real" site everywhere so i'm not sure how to do that.
UPDATE (improved explanation):
Problems:
links are absolute
this need to be online so other developers can test site
Copy/paste your entire files from your domain to everywhere you want as first step.
Go to the phpMyAdmin or use a tool that permit to you to export your database as .sql.
Open the .sql file and run a find and replace and replace all your absolute path (just the one before wordpress: ie.: of this http://www.yoursite.com/wp-content/etc. Replace only http://www.yoursite.com)
Check for the permission of the DB, maybe you should change also the Server name, DB Name, Username and Password.
Create a new database and import the file you exported and modified the minute before.
Now you got a clone of the previous website ready for your experiments on both side, files and DB.
2nd result in Google for me...
http://wpmu.org/quickly-clone-and-migrate-wordpress-sites-with-the-duplicator-plugin/
If you're going to use a different hostname or path for the copy of the web site, it's not as simple as copying your files and exporting / importing your MySQL database. There are, in fact, embedded absolute URLs in various columns of the database.
There's a step by step procedure here.
http://codex.wordpress.org/Moving_WordPress
If you were working on WP MultiSite you could avoid having to duplicate your database and then doing a sql find and replace as mentioned by using one of the WP cloning plugins.
The NS Cloner - http://wpmu.org/clone-sites-within-a-wordpress-multisite-network/handles everything for you automatically including the DNS, DB, and Hosting. Based on your mutlisite setup you can then deploy it to a new subfolder or subdomain. For advanced features after your new site is live you can use the Pro Version and do advanced things like search and replace on the live site.
Again this is for MultiSite only, however I would highly recommend moving to that architecture anyway to allow you to take advantage of all of WP multisite has to offer.
WP Staging allows you to clone an entire site including database and files into a subdirectory of your main site for testing purposes with just two clicks:
https://wordpress.org/plugins/wp-staging/
What's your problem exactly?
You just need to download all worpress files from your server.
Then create a local copy of the database so that you have all the data.
All the links are relative in wordpress, so you won't have any troubles with links to the "real site" ;)

Wordpress Development VS Production Environments

I am about to use WordPress as CMS with a lot of customization, but my question is, how should I sync development to production?
Assuming WordPress is not used, a typical development cycle is to develop the pages locally, and create the DB scripts. Then when everything is ready, it is posted to the site. And then again, more db and code changes, then only the changes are updated/applied, and so on.
Now, with WordPress, you get all the great features (one example is blogging, comments, almost ready CMS ...etc). However deployment is a pain! Ideally, I would rather keep my typical development cycle described above. Therefore I am going to be implementing WordPress locally (from wordpress.org) and then pushing the changes to my production server.
So, assuming that I create a new page in WordPress locally (I will never create pages on the server, all locally, I will find a way to disable wp-admin for the server), a number of files are created. This is not a problem so far. HOWEVER, if I want to add content to that newly created page, that content is saved to my local database. Even though that content is a database change, it is considered (from my point of view) a new change that should be pushed to server rather than add that content via the live server (because that content is considered static, it is not a blog post or a comment, it is a static page).
Now, that new page content is saved to the DB, and therefore, the DB will have changes done on my local machine that I should push to the server along with the files that I will FTP to the server.
My questions are:
Is this approach correct? If not, what do you suggest
What is the best way to find database diffs? What is a tool to use? Does MySQL Workbench provide something like that? I intend to use that tool to find diffs and then generate an update script for the DB. The reason for this question is I normally make the changes myself, and I know how to track them, but now, those DB changes are generated by WordPress and I need to reverse engineer them to find out which changes are made.
Assuming I got step 2 to work, is there anything in that script that should be modified? Such as server names? Does WordPress hard-code server names for example?
So to summarize and give you more information about my development environment, I use XAMPP for development on Windows 7, with PHP and MySQL setup. I also use Mercurial for source control. As mentioned above, I will use WordPress as part of the solution and I intend to use it to help me create a CMS solution. I will use it locally for page generation, and disable that feature for online (keeping online for blog posts and similar entries only). I am doing that so as to keep things in-sync. If I create a page locally, some data is saved to the DB. Now, how do I sync/upload?
Thanks.
OK, after further investigation, here is what I concluded.
All theme development should be version-controlled
All plugin development should be version-controlled
Content of pages and posts are not part of the development porcess, this is contect and should only be backed up.
This way, you do not need to worry about DB changes ...etc.
Hope this helps everyone.
You might use a Version Control System? What OS is the development on, e.g. Win or Linux? And what is the production OS? I use http://serverpress.com for my testing environment though there are others, WAMP, LAMP, etc.

Categories