ThisCalculator

Everyday

How to Move a Drupal Site: Files & Database

Updated · Standard formula, shown below

How to Move a Drupal Site: Files & Database

Moving a Drupal site to a new server involves transferring two main parts: the files (code, themes, modules, and uploaded content) and the database (content, configuration, and user data). This guide walks you through the entire process, from preparing both servers to updating settings and verifying the move. You’ll need command-line access to both the old and new servers, and ideally a backup of your site before you start.

What You’ll Need

  • SSH access to both the old and new servers (or a hosting control panel with file and database export tools).
  • Database credentials for the old and new databases (username, password, database name).
  • A temporary location on the new server to store the transferred files and database dump.
  • Optional but recommended: a local copy of the site for testing before the final switch.

Step-by-Step

  1. Back up your Drupal site. Before touching anything, create a full backup of both files and database. This is your safety net. You can use a module like Backup and Migrate, or do it manually: compress the site’s root directory (e.g., tar -czf drupal_backup.tar.gz /path/to/drupal) and export the database (see step 3).
  2. Prepare the new server. Ensure the new server meets Drupal’s requirements (PHP version, database server, web server). Create a directory for the site, e.g., /var/www/html/mysite, and set appropriate file permissions (usually writable by the web server user).
  3. Export the database from the old server. Use mysqldump (or your database admin tool) to create a SQL dump. For example: mysqldump -u username -p database_name > drupal_db.sql. This file contains all your content, configuration, and user data.
  4. Transfer files to the new server. Use scp, rsync, or a file manager to copy the compressed site files to the new server. For example: scp drupal_backup.tar.gz user@newserver:/tmp/. Then extract the archive into the site directory: tar -xzf drupal_backup.tar.gz -C /var/www/html/mysite.
  5. Import the database on the new server. Create a new database and user on the new server (or use an existing one). Then import the SQL dump: mysql -u username -p database_name < drupal_db.sql.
  6. Update settings.php. Edit the file at sites/default/settings.php on the new server. Update the database connection details (host, database name, username, password) to match the new database. Also check the $base_url if you use it (though Drupal usually handles this automatically).
  7. Update the files directory and permissions. Ensure the sites/default/files directory exists and is writable by the web server. If you moved to a different path, you may need to update the file system path in settings.php (the $settings['file_public_path'] or similar).
  8. Clear caches. On the new server, clear Drupal's caches. You can do this via Drush (drush cr) or by visiting update.php if needed. If you don't have Drush, you can temporarily set $settings['cache'] = FALSE; in settings.php, or use the database to clear cache tables.
  9. Test the site. Visit the site on the new server. Check the homepage, a few content pages, user login, and any custom functionality. Look for broken images or missing files, which often indicate file path issues.
  10. Update DNS and go live. Once everything works, update the domain's DNS records to point to the new server. After propagation (which can take a few hours), the site will be served from the new server. Keep the old server running for a few days as a fallback.

Common Mistakes

  • Forgetting to update settings.php: The most common error is leaving the old database credentials in place, causing a connection failure.
  • Incorrect file permissions: Drupal needs write access to sites/default/files and sometimes the cache directories. If permissions are too restrictive, you'll see errors or blank pages.
  • Not clearing caches: Old cached data can cause the site to reference old paths or broken CSS/JS. Always clear caches after moving.
  • Mixing up database names: Ensure the database name in settings.php matches exactly the one you imported into.
  • Transferring files with wrong paths: If you extracted files to a different directory than the web root, the site won't load.

Tips

  • Use rsync instead of scp for large sites—it's faster and can resume interrupted transfers.
  • If you're using a version control system (like Git), you can clone the code repository directly on the new server, and only transfer the files directory and database separately.
  • Test the site on the new server using a temporary URL (e.g., an IP address or a test subdomain) before changing DNS. This avoids downtime.
  • Export the database with --single-transaction to avoid locking tables on a live site.
  • Keep a copy of the old server's files and database until you're confident the new site is stable.

Troubleshooting

  • Site shows a blank page or "Unable to connect to database": Double-check the database credentials in settings.php. Ensure the database server is running and the user has privileges.
  • Images or files are missing: This usually means the file path is wrong. Check the files directory location and the $settings['file_public_path'] in settings.php. Also ensure the files directory has the correct permissions.
  • CSS/JS not loading: Clear caches. If that doesn't help, check that the sites/default/files directory is writable, as Drupal may need to create aggregated CSS/JS files there.
  • White screen of death (WSOD): Enable error reporting by adding error_reporting(E_ALL); ini_set('display_errors', TRUE); to settings.php temporarily. This will show the underlying PHP error.
  • Database import fails with "Access denied": Make sure the database user has all necessary privileges on the new database, and that you're using the correct host (often 'localhost' vs a remote host).

Frequently Asked Questions

Do I need to move both files and database?

Yes. Drupal stores content, configuration, and users in the database, while themes, modules, and uploaded files are in the file system. Both are required for the site to function.

Can I move the site without SSH access?

Yes, you can use a hosting control panel like cPanel to export the database and download files via FTP. The process is similar, but you'll use the panel's tools instead of command-line commands.

What if my site uses a different database (e.g., PostgreSQL)?

The process is the same, but use the appropriate dump/import commands (e.g., pg_dump and psql). Also ensure the PHP database driver is installed on the new server.

Should I update the $base_url in settings.php?

In modern Drupal versions, $base_url is optional and usually auto-detected. Only set it if you have a specific reason, such as a reverse proxy setup.

How do I handle a large files directory (e.g., 10GB)?

Use rsync to transfer files in the background, or compress the directory before transferring. If the transfer is interrupted, rsync can resume.

What if the new server has a different PHP version?

Drupal may have compatibility issues with different PHP versions. Check the Drupal requirements for your version. You may need to update core or contributed modules to match the new PHP version.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.