How to clone wordpress site for the develope purpose? - php

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" ;)

Related

WORDPRESS - Clone Website on a New Installation to Update It

We need to recreate our site from scratch. When I mean from scratch I mean we want to keep the same content (pages, articles, URLs and tons of media) and move it to a new WordPress installation with a different theme.
A brief background to try to understand what the underlying problem is. The current site (the one to be copied and transferred) is HUGE. It has more than 1500 pages and 3000 articles. It is currently running on an old version of WordPress and an outdated theme. We are deliberately not updating WordPress, theme and PHP so as not to risk crashing and being left without a site (this has already happened in the past with another installation).
What we have done is to create (on the same hosting) a new, updated installation of WordPress (on another directory). This will be the new and definitive one. Then – when all is said and done – we should use the name of the first installation (but this will be another issue to deal with at the end). We decided to operate in this way because we want everything to be done as safely as possible.
Some details:
Objective: SITE 1 -> SITE 2
SITE 1: Installation: domain.org/directory1 WordPress 5.2 PHP 7.1.33
Theme: Awaken
SITE 2: Installation: domain.org/directory2 WordPress 5.7.1 PHP
7.1.33 Theme: Divi Builder
At the moment, we have already installed the new theme in directory2 and created the home page that will host all the pages and articles from the old site. We are not interested in keeping the plugins. Our aim is for the new installation to be as “clean” as possible, without the risk of dragging around old problems.
What do you think is the correct way to proceed? Again, the most important thing is that the links are not changed (so that the URLs will still work once the change has been made; I mean: domain.org/directory1/perma/link/article-written-in-the past = domain.org/directory2/perma/link/article-written-in-the past
Could the export/import tool do this job? How should I proceed to make sure that I don’t affect the performance of the new site? Is it possible to carry out a test with a few pages to see if this can be done?
Thank you all!
The first step is to create a backup of the existing site. You can do this manually, you need all of the site files plus the database.
However, Duplicator is a great plugin that will create a backup package that includes everything for you. One thing to be aware of is the size of your site may cause issues for the plugin do to server load, but its the easiest method. There are other plugins as well to help with migration.
Once you have everything you can copy it to a new domaon like dev.website.com. The installer from Duplicator will help with the url updates, but its pretty easy to adjust in the config file and database options table. If you use relative urls most things wont be an issue, but a simple find and replace in the database will easy update any absolute urls.
Once you have made all your changes in dev you just reverse the process by writing over the live site and your set. This is safe beacuse you have a backup of the live site from step one in case you need to revert to the current state.

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

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.

Using multiple php frameworks on one website

Our main website uses symfony 1, and by the time I started working on the code it seems impossible to upgrade (too much custom code from previous developer). Now we are adding a large addition to what the company offers. Instead of using a really old framework I wanted to use CodeIgniter, also since I'm very familiar with it. My real question:
What is a proper way of setting up a website to use multiple frameworks. The new features will be separate from the original website, but it will still need a few tables of the database.
I was going to have apache handle where the root directory was depending on the url and just do everything normally. The main website is example.com and the new feature will be abc.example.com
I'm really looking for people who have done this and some tips and warning they had.
PHP will run the framework based on which directory is loaded on the server. For instance, on most apache servers the root directory for example.com would be /www. Which means all of the code for Symphony would be in /www/*.
When you setup the path of your subdomain, just put it outside of the /www folder. Then, when you go to abc.example.com apache won't try to load the original site along with the Symphony framework.
I think it will be fine for both frameworks to share the same database tables. I'm not entirely sure how you plan for these two applications to work, but as long as you don't change the column names and types you should be okay.
If you don't want the applications to share the data in the original table, then look into using mysqldump or something of the like to copy the data over to a new table.

How can I safely port my wordpress blog to localhost?

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.

Categories