Moving site from test to production

sbsoft - February 20, 2009 - 11:42

Hi All,

after moving my drupal site from test to production all the images in the pages are not visible.

I check and found that all path images are saved into database with absolute path ( /TEST_DRUPAL/sites/default/files/image/bioexpress.jpg ) , in my case the site name is TEST_DRUPAL, but the production site name is LIVE_DRUPAL .

Why drupal save image with absolute path and not with relative path ?

I figure out I have something wrong configured. What ?

Thansk

It sounds like you need to go

bwv - February 20, 2009 - 12:34

It sounds like you need to go into site configuration >>> file system, and resubmit the default settings. That may solve the problem. If not, please write back.
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207

----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207

Because, if you are using

cog.rusty - February 20, 2009 - 13:37

Because, if you are using clean URLs and
- you are browsing, for example, node/15, and
- it contains a relative link with img src="images/image.jpg"
Then the browser will resolve it to node/15/images/image.jpg, which is wrong.
You need an absolute img src="/drupaldir/images/image.jpg"

This is a consequence of using clean URLs. Without Clean URLs, the browser won't consider ?q=node/15 as a path, and relative image links will work fine.

You will need to search and replace those paths (in phpadmin or in a database dump using a good text editor), or check to see if the http://drupal.org/project/pathologic module is smart enough.

Generally, I avoid using subdirectory URLs in any devel sites which I may need to move, and I use subdomain URLs instead. This way, when I use clean URLs, a front slash is all I need in the image links. Note that what matters is the URL path, not the filesystem path.

More details, please?

techywoman - February 20, 2009 - 18:07

This seems like a very important topic for those of us working on local development sites, particularly if we are concerned about time-wasters!

You wrote: "Generally, I avoid using subdirectory URLs in any devel sites which I may need to move, and I use subdomain URLs instead. This way, when I use clean URLs, a front slash is all I need in the image links. Note that what matters is the URL path, not the filesystem path."

I understand, Cog.Rusty, your "why" explanation. Makes perfect sense. But I don't understand how to implement your solution. Initially, I thought I'd simply go in and turn off "clean urls" on my development site.

Can you provide me more details on how to avoid the "mess" that might develop on a production site from using clean urls on a dev site.

Sure glad someone brought this up...

If I create a subdomain: -

cog.rusty - February 20, 2009 - 19:02

If I create a subdomain:

- URL: dev.example.com (or localhost, or anything that does not contain a path)
- disk directory: public_html/dev (Drupal installed here)
- uploads directory: public_html/dev/files (for example)

then, with clean URLs enabled, I can use image links in the content like "/files/images/image.jpg" (just a front slash and my Drupal files path). The front slash will make the browser resolve this as http://dev.example.com/files/images/image.jpg no matter whether I am in a node.

If I move to a live site:
- URL: www.example.com
- disk directory: public_html (Drupal installed here)
- uploads directory: public_html/files (different, but same relative to Drupal)

then the exact same link "/files/images/image.jpg" in the content will work, because it will be resolved as http://www.example.com/files/images/image.jpg

So, by not using a path in Drupal's URL, I can always use clean URLs with just a front slash in front of the image paths.

Unfortunately these solutions

jlmeredith - March 31, 2009 - 15:05

Unfortunately these solutions do not fix situations where say a person is using imagecache in a multisite. When the file is uploaded (in this case via the file field module) the image is placed in

sites/example.com/files/images/imagecache.jpg

And this full path is stored in the database.

The only way that I have found to fix this is to setup your local environment (via hosts file) to resolve your domain locally when doing development work, and then when you push to your production environment, change the hosts file to resolve away from your local system. This allows you to build and browse your local development environment as though it were the live site (using the full domain of http://example.com) and then when you are ready to push it to production, you simply change your hosts file.

This is a messy solution either way. There surely should be a way to no have module store absolute paths?

--
Jamie Meredith
Lead Developer
South Central Media

The simplest solution for

cog.rusty - March 31, 2009 - 15:32

The simplest solution for multisites is:
(a) In admin/settings/file-system, *don't* set your files directory to sites/example.com/files. Use files/site-nickname instead. That is perfectly movable.
(b) Don't set up your development sites with subdirectory URL paths, just use subdomains.

Upcoming Drupal 7 will have a solution for these movability problems created by the sites/example.com/files directories (http://drupal.org/node/231298). However, I still believe that the files/site-nickname solution is simpler and more reliable, even for Drupal 7.

SQL solution to problem

houen - June 24, 2009 - 09:55

If you already have the image problem, this one-liner SQL statement can set you straight:

UPDATE `DATABASE_PREFIX_files` SET filepath = replace(filepath,"OLD_SITE_NAME","NEW_SITE_NAME");

(Replace DATABASE_PREFIX, OLD_SITE_NAME and NEW_SITE_NAME with your respective values)

This small query just saved my ass at 1:30 AM in ... [drumroll] 0.0012 sec

Thanks, saved mine too

TomiMikola - September 25, 2009 - 09:43

In addition, if you have inserted images into node bodies, replace the image paths with this update query:

UPDATE node_revisions SET teaser = replace( teaser, "sites/OLD_SITE_NAME", "sites/NEW_SITE_NAME" ) ,
body = replace( body, "sites/OLD_SITE_NAME", "sites/NEW_SITE_NAME" )

 
 

Drupal is a registered trademark of Dries Buytaert.