Moving a PHP website together with its database is usually straightforward if you plan the order of operations carefully. The main goal is to keep the application files, database contents, and connection settings aligned so the site continues to work after the move. In a hosting environment, especially when using a control panel such as Plesk, the safest approach is to export the database, copy the website files, import the database on the new hosting account, and then reconnect the application to the new database credentials.
This guide explains how to move a PHP website and database together with minimal downtime, what to check before the switch, and how to troubleshoot the most common errors after migration. The steps are suitable for typical PHP applications such as WordPress, Laravel, Joomla, Drupal, custom PHP sites, and other database-driven websites.
What needs to move together
A PHP website normally depends on two parts:
- Website files – PHP scripts, templates, images, uploads, themes, plugins, and configuration files.
- Database – MySQL or MariaDB data that stores content, user accounts, settings, orders, and other dynamic data.
If only one part is moved, the site may partially load but fail when it needs content from the database, or it may show connection errors because the credentials no longer match. For that reason, a complete migration means moving both parts and updating the database connection details in the application.
Before you start the migration
Before copying anything, collect the basic information about the current website and the destination hosting account. This reduces mistakes and helps you restore service faster if something goes wrong.
Check the application type
Identify whether the site uses plain PHP, a CMS, or a framework. The migration method is similar in all cases, but the configuration file location may differ.
- WordPress – database settings are usually in
wp-config.php - Joomla – settings are typically in
configuration.php - Drupal – database details are often in
settings.php - Custom PHP – credentials are often in
config.php,.env, or a similar file
Make a full backup first
Always create a complete backup before migration. Keep at least two copies if possible: one for immediate recovery and one stored separately. A proper backup should include:
- All website files from the document root
- The full database export
- Any additional media or storage folders used by the application
- Configuration files that contain database credentials or hostnames
Confirm access to the new hosting account
On the destination hosting platform, make sure you can access the control panel, file manager, FTP or SFTP, and the database tools. In a managed hosting or Plesk environment, you will usually need access to:
- File Manager or FTP/SFTP
- Database management tool such as phpMyAdmin
- Database creation screen
- PHP settings if the application requires a specific PHP version
Step 1: Export the database from the old hosting account
The database export is the first essential step because it captures the live content at the time of the move. Use a consistent export method so the table structure and data remain intact.
Using phpMyAdmin
In many hosting control panels, phpMyAdmin is the easiest tool for exporting MySQL or MariaDB databases.
- Open phpMyAdmin from the current hosting control panel.
- Select the correct database.
- Click Export.
- Choose the Quick method for smaller databases or Custom for larger or more sensitive migrations.
- Save the export as an
.sqlfile, or compressed file such as.sql.gz.
For larger databases, use compression if available. It reduces transfer time and makes upload easier on the destination hosting account.
Using command line tools
If you have shell access, a command line export is often more reliable for large databases.
mysqldump -u database_user -p database_name > database_name.sql
For a compressed export:
mysqldump -u database_user -p database_name | gzip > database_name.sql.gz
Command line exports are especially useful when the database is large or when phpMyAdmin has time limits.
Step 2: Copy the website files
After exporting the database, copy the PHP website files to the new hosting account. The goal is to preserve the same directory structure as much as possible, especially when the application uses absolute or relative paths.
Files you should include
- All PHP files
- Templates and theme files
- Uploaded media and image directories
- JavaScript, CSS, and asset folders
- Configuration files
.htaccessif the site uses Apache rewrite rules
Recommended transfer methods
- FTP/SFTP – suitable for small and medium websites
- File Manager archive upload – useful when the destination panel supports zip extraction
- rsync or SSH – best for larger sites if shell access is available
If the website uses an Apache-based setup, keep the .htaccess file in the correct directory. Missing rewrite rules can break clean URLs, login pages, or routing in frameworks.
Step 3: Create the new database on the destination server
Before importing the old data, create a matching database and user on the new hosting account. The database name, user name, password, and host value may differ from the old environment, even if the application stays the same.
What to set up
- A new empty database
- A database user with a strong password
- Full privileges for that user on the new database
- The correct database host, often
localhostin standard shared hosting setups
In Plesk or another control panel, this is usually done in the database section of the domain or subscription. Make sure the database engine matches the site requirements, typically MySQL or MariaDB.
Step 4: Import the database into the new hosting account
Once the new database is ready, import the data you exported earlier. This step recreates the content and application state on the new hosting environment.
Using phpMyAdmin
- Open phpMyAdmin on the destination hosting account.
- Select the newly created empty database.
- Click Import.
- Choose the exported
.sqlfile or compressed export if supported. - Start the import and wait for completion.
If the database is large, an import may fail because of time limits or upload limits. In that case, use command line import or split the database into smaller parts if your hosting environment supports it.
Using command line tools
With shell access, import the database using:
mysql -u database_user -p database_name < database_name.sql
For compressed dumps:
gunzip < database_name.sql.gz | mysql -u database_user -p database_name
After import, check for errors such as duplicate key warnings, missing tables, or incomplete file uploads.
Step 5: Update the database connection settings
After the import is complete, the application must point to the new database credentials. This is the most common place where migration issues appear.
Typical settings to update
- Database name
- Database username
- Database password
- Database host
- Database port if it is not the default
Common configuration file examples
Depending on the application, the settings may be stored in one of the following files:
wp-config.phpconfiguration.phpsettings.php.envconfig.php
After changing the credentials, save the file and test the site immediately. A small typo in the password or database host is enough to produce a connection error.
Step 6: Test the website before switching traffic
Do not point the live domain to the new hosting account until the site works correctly in the destination environment. Test it first using a temporary URL, hosts file override, or the preview method available in your control panel.
What to check during testing
- Homepage loads without database errors
- Internal pages display the correct content
- Forms submit properly
- Logins work
- Images and uploads load from the correct paths
- Admin area opens and can save changes
- Permalinks or clean URLs work if the site uses Apache rewrite rules
If the site uses PHP version-specific features, verify that the destination server runs a compatible PHP version. A mismatch can cause blank pages or fatal errors even if the database import was successful.
Step 7: Switch the domain to the new hosting platform
When the site is fully tested, you can move live traffic. In many cases, this means updating DNS records to point the domain to the new server. Because this guide is focused on database and app migration, remember that DNS changes may take time to propagate.
How to reduce downtime
- Lower DNS TTL in advance if possible
- Perform the migration during a low-traffic period
- Freeze content changes briefly before the final database export
- Repeat the export/import if new data was added during testing
If your website receives orders, form submissions, or new user registrations, it is important to do a final sync before switching traffic. This avoids losing recent changes made after the initial export.
Special notes for common PHP platforms
WordPress
After migration, WordPress may need updated site URLs if the domain or subdirectory changed. Check the siteurl and home values in the database if the site loads in the wrong location. Also confirm that uploaded media paths are correct and that permalinks regenerate properly.
Laravel and other frameworks
Framework-based applications often store database credentials in a .env file. You may also need to clear cached configuration after updating the settings. If the app uses storage links, ensure those paths are recreated on the new environment.
Joomla and Drupal
These CMS platforms often depend on exact database settings in their main configuration files. If the migration includes a change in table prefix, database host, or PHP version, verify those values carefully before testing.
Common migration problems and how to fix them
Database connection error
This usually means one of the following:
- Wrong database name, username, or password
- Incorrect database host
- User does not have permission on the database
- Database server is not running or not accessible from the application
Check the credentials in the configuration file and test them in the control panel if available.
Blank page or HTTP 500 error
This often points to a PHP compatibility issue, missing file, broken .htaccess rule, or a permission problem. Review the error log in the hosting control panel or Plesk to see the exact cause.
Missing images or broken uploads
If uploaded content is stored in a custom directory, that folder may not have been copied. Confirm that the full uploads directory is present and that file permissions allow the web server to read the files.
Database import stops halfway
Large imports may hit execution time or memory limits. In that case, use a command line import, increase limits temporarily if your hosting provider allows it, or import the database in smaller chunks.
Rewrite rules no longer work
If URLs return 404 errors after migration, check the Apache rewrite configuration. Make sure the site’s .htaccess file was copied and that the hosting platform allows overrides where needed.
Best practices for safer database and app migration
- Work from a fresh backup, not an old copy
- Keep file and database versions matched as closely as possible
- Document the old and new database credentials before editing files
- Test with the same PHP version if possible, then adjust later if needed
- Check logs immediately after migration
- Keep the old hosting account available until the new site is stable
In a managed hosting environment, these steps help reduce surprises and make rollback much easier if the migration is not successful on the first attempt.
FAQ
Can I move only the database and keep the same files?
Only if the site files stay in the same environment and the application configuration remains valid. In a normal hosting move, you should transfer both files and database together so the site remains functional.
Can I move a PHP website without downtime?
Full zero downtime is difficult, but you can reduce downtime significantly by preparing the new environment in advance, copying files first, importing the database, and doing a final sync before changing DNS.
What if the database is too large for phpMyAdmin?
Use command line export and import with mysqldump and mysql if shell access is available. This is usually more stable for large databases.
Do I need to change anything in the PHP code after migration?
Often yes, at least the database connection settings. In some cases you may also need to update base URLs, file paths, cache settings, or environment variables.
Why does the site work on the old host but not on the new one?
The most common reasons are different PHP versions, missing extensions, wrong database credentials, missing rewrite rules, or incomplete file transfer.
Should I keep the old database after moving?
Yes, at least until you have confirmed that the new site works correctly and no recent data is missing. The old database is your fallback if something needs to be restored.
Conclusion
Moving a PHP website and database together is mainly a matter of sequence: back up everything, export the database, copy the files, create a new database, import the data, update the connection details, and test thoroughly before switching live traffic. When done carefully, this process works well on most hosting platforms and control panels, including Plesk-based environments.
If you are migrating a database-driven site in Europe, it is especially important to plan for testing, DNS propagation, and final content sync so the move is smooth and the site stays consistent. With the right checklist, the migration can be completed with minimal downtime and without losing data.