All my files disappear when I move from localhost to production - Drupal 7

Published December 18, 2010

Every Drupal site I build involves at minimum two environments: one is on my laptop, which I call the local server; another is what most people call the production server. Drupal has a very straightforward way of allowing you the developer to use a single code base to run both environments, even though they are on different machines, in different corners of the world, with different passwords, etc. This multisite capability can do much more, but this tutorial will teach you how to leverage Drupal 7's multisite functionality to run two copies of one site with a shared code base.

For information on settings.php files in Drupal 6, check out some of our other articles on DrupalEasy.com.

When you first install Drupal, you are instructed to copy the default.settings.php file in the sites/default directory and name the copy settings.php - Drupal's installer then adds your database configuration and the security 'salt' in this file. If you're running just one site on one server, you never need to worry about this file again.

During installation, a directory is also created to store files at sites/default/files, right next to the settings.php. Drupal's theme system will often stick files here, and any files users upload through the Drupal interface, like profile pictures, attachments to nodes, image field entries, and even the output of Backup and Migrate will be stored in the files directory.

Once you start moving your sites around to different servers, you may find it easier to make another directory underneath sites. In many cases, this will be called localhost, and that's what this tutorial will use. Now you will have a sites/default/settings.php, sites/default/files, and finally sites/localhost/settings.php. If you don't follow the instructions in this tutorial, Drupal will create a sites/localhost/files and now you will have two out-of sync files directories - you may also notice some missing or broken files as you try to keep your environments in sync. If you're trying to move all of your files around at once, this isn't the most useful configuration: you'll want to point both your localhost and default sites at the same files directory.

Drupal lets you set a whole bevvy of variables specific to one of these settings.php files, but right now I just want to talk about the file system settings, which you would normally access at Configuration > Media > File System.

Edit both the sites/default/settings.php and sites/localhost/settings.php - near the bottom of each file, you'll need a block like this:

{syntaxhighlighter brush: php;fontsize: 100; first-line: 1; }$conf['file_public_path'] = 'sites/default/files';
$conf['file_private_path'] = 'sites/default/files/private';
$conf['file_temporary_path'] = '/tmp';{/syntaxhighlighter}

Now both of your sites will look for files in the same directory.

As you set up your Drupal site on other environments, it may be necessary to make a directory next to default and localhost called dev.example.com and example.com - each one containing a settings.php file.

The main reason you will probably do this is to keep all of your environments' configuration in version control.

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name
CAPTCHA