Restoring old WP install, renamed wp-content... restoring upload links? - php

Expertise level: medium-low; I'm not afraid to find a file and edit it, but I don't really understand the inner workings of PHP.
I'm trying to restore a WP blog from backup, but with a fresh 3.7.1 install and a lot more attention to security after a hacking incident. Among other things, I've used Better WP Security to rename the wp-content folder.
My steps were:
Install 3.7.1,
Import the database,
Activate Better WP Security, rename wp-content,
Pull the old theme into the themes folder.
The database restore went fine, and the site is about 90% there, but nothing that linked to the old uploads folder in wp-content is linking now.
I've searched and replaced all of the instances of wp-content on the site using an FTP program and Sublime Text, but I'm still not getting any re-linking. Images are still being sought with generated HTML that looks for things like http://foo.com/wp-content/uploads/2012/12/pants.jpg.
Where else do I need to look for and replace wp-content to the new content folder name? I've tried poking around in the database but I have no idea where to look or what to look for.

I've never used Better WP Security, but if you need to update references to wp-content in the database, the best way to update the database is the Search and Replace for WordPress Databases Script mentioned in the Codex. Don't just try updating the database manually - if the fields contain PHP serialized data (a lot of them do) you'll break things.
Sounds like you already have a database backup, so you should be safe just to give the script a try. The search and replace values will depend on how Better WP Security works, but if the directory is just renamed (to, say, newname), using /wp-content/ and /newname/ should do the trick.

Wordpress saves the attachments URL in the database so you have to replace the image paths in the sql dump (you can use sed ).
You don't have to touch the wordpress core and in the wordpress themes the attachments won't show in the htmls cause were called by wordpress functions.
You can make this
Unzip wordpress in a directory
Make the string replacement (with your new domain) in your old dump sql
import the sql dump
install wordpress with your mysql data and the same db prefix in the backup (it should say that there's already a wordpress installation)
That should work

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.

Is it OK to edit/update Wordpress theme files over FTP?

I'm working on developing my first Wordpress theme. As of now, I've just been coding the files, zipping my theme folder, and then uploading and activating the theme in my Wordpress Dashboard to test it.
However, this has become quite tedious, as I basically have to:
1) code a bit of my theme, zip into folder
2) deactivate/remove old version of theme in Wordpress dashboard
3) upload new version of theme, and activate
4) repeat...
I'd like to install Wordpress locally, but I don't quite understand how to do that yet, and I'm not familiar setting up a local webserver.
SO... rather than do it the tedious way that I have been, is it OK to just make sure my theme is activated, and then edit my files and overwrite/upload them to the wp themes folder over FTP using Filezilla?
I'm guessing it'd be considered bad practice, but for the time being would this work well enough until I learn a better way?
That's definitely okay.
You can modify the files locally and then upload the changes using FTP. Make sure you have backups so if you accidentally FTP the wrong changes you can easily revert them.
Yes you can absolutely download the uncompressed theme and modify and put it back using ftp.
Also, some themes support whats called a child theme. This allows you to override the theme with your changes, without changing the original source code. Which in turn gives you a better upgrade path from the original theme provider when they have updates.
I have actually had some weird formatting issues with WP after manually editing files, where they would no longer run, so I try to avoid it. But I have bad luck that time.

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

Switching themes in Drupal without the web interface

I'm in the process of learning php and creating themes.
Unfortunately, while I was editing a theme that i was currently using in drupal, I made a mistake in the theme such that nothing shows up anymore, even if i were to hit drupal/index.php. I want to change my broken drupal theme to a working one but i'm unable to do so because I can't even view the administration section.
The How To reset your theme via the database page on Drupal.org has instructions for changing your theme directly from the SQL prompt.
It's not immediately clear whether this will work in the most recent version of Drupal, so back up your database before attempting this.
The easiest way to change your frontend theme is to set it in your sites/default/settings.php:
$conf['theme_default'] = 'minelli';
In terms of sorting your current problem, here's a simple way to do it that should work... Let's say your current theme is called "custom_theme".
Go to your theme directory ("sites/default/themes" probably)
Backup your development theme (i.e. move it elsewhere, if you're using Linux command line do something like "mv custom_theme custom_theme.bak")
Copy the garland theme to here and name it the same as your broken theme (if using LInux command line, something like this should work "cp -a ../../../themes/garland ./custom_theme"
Try viewing your site now. It should now use garland instead of your broken theme.
As others have said before, it's also highly recommended that you use a different theme for admins as you do for normal users (in case you break stuff). Select a safe admin theme (like garland) and then you can nearly always get to the admin interface if you're playing with theming.
Or if you are using Drupal 6, removing/moving the broken theme folder will make Drupal change the theme to the default theme (Garland).
Maybe using two themes in parallel will help.
Set one for the "user frontend" - the one you are developing at /admin/build/themes, another one standard, like garland, which you are NOT going to change, as a "administration backend": /admin/settings/admin.
If you happen to break the theme you're developing, you just go to the admin area (/admin), it will switch back to garland.
you can also insert a new login form in your theme by including this code:
`<?php
if(!user_is_logged_in() ){
print drupal_render(drupal_get_form('user_login'));
}else{
print "You are already logged in!";
}?>`
anywhere in the page.tpl.php file of your broken theme, then register with your admin credentials ;)
Please also see the following stack over flow issue.
it is related to them
Changing Drupal's theme and keeping Garland as the admin theme?
Changing the Admin Theme in Drupal 6 Directly in Database
Now here is solution :
Remove the files of the bad theme and clear the cache. After clearing the cache you will be able to login again.
The main difficulty is that you have to clear the cache without being logged in.
Try one of the methods for clearing the cache described in
Clearing Drupal's cache
IF Not then Try this one :
If you have drush, the command to type would be
drush vset theme_default garland
Either on the commandline, or via an administration interface (eg PHPMyAdmin) enter the following query
UPDATE system SET status=1 WHERE name = 'garland';
Then either:
UPDATE variable SET value='s:7:"garland"' WHERE name = 'theme_default';
TRUNCATE cache;
TRUNCATE cache_bootstrap;
TRUNCATE cache_block;
Note that 's:7' refers to the length of the following string. Modify as needed. This is database surgery, tricky stuff.
OR
If you are using per-user themes, and you've just messed it up for yourself as admin, try
UPDATE users SET theme='garland' WHERE uid = '1';
Be careful, as getting either of those lines wrong can mess things up just as badly.
Cheers!
Mudassar Ali
As far as I know, theme settings are stored in the database, as well for each individual user. The quickest way to get rid of a theme is probably removing it from the theme path.
Just move it onto your desktop and Drupal should be able to detect that your requested theme is missing and point you to the default instead.
Update: Tried this on my Drupal 5 installation, it turned out 'clean'. I suggest copying a working Drupal theme into your theme directory (make a copy first).
It's worth mentioning that if you're using the "Sections" module to apply different themes to different parts of the site, the instructions given on the Drupal site won't necessarily work — you may find that moving the problem theme directory out of the way is the only method of seeing the admin interface properly.

Categories