To restore your website after a hack, take the site offline, work out roughly when the attack started, and restore both the files and the database from a backup made before that date. Then change every password (hosting, FTP, database, CMS admin and email), update the software and remove whatever let the attacker in. Restoring without closing the hole usually means being hacked again within days.
Here is the full process, in order, with the checks that make the difference between a clean recovery and a repeat infection.
Step 1: contain the damage
- Put the site in maintenance mode or take it offline. Many hosts let you suspend a site or block public access. At minimum, stop visitors being sent to malware or phishing pages.
- Tell your host. They may have already seen the problem, can check other accounts on the server, and can tell you what their logs show.
- Do not delete anything yet. The hacked files and logs help you find how the attacker got in.
Make a copy of the hacked site before you change it: download the files and export the database, label it clearly as infected, and keep it apart from your clean backups. It is evidence, and occasionally the only copy of recent content you will want to recover by hand.
Step 2: find out when the hack happened
The single most important decision is which backup to restore. Restoring from a date after the attacker got in brings the backdoor straight back. Look for the earliest sign:
- Server access logs. Unusual requests to
wp-login.php, upload folders, or unknown PHP files. - File modification dates. In cPanel File Manager or your FTP client, sort by date and look for PHP files changed when you made no changes.
- New admin users in your CMS, or new FTP or database users in the hosting panel.
- Warnings from search engines, browsers, your host or security plugins, and the date they started.
- Spam pages, redirects or injected links, and when visitors first reported them.
Then pick a backup from comfortably before that date. This is why keeping many dated versions matters: if you only have last night's copy, it is probably infected too. Our guide to how many backup versions to keep suggests at least 30 days for websites.
Step 3: clean out the account
Restoring on top of hacked files can leave extra malicious files in place, because a restore usually only overwrites files that exist in the backup. Instead:
- Move or delete the contents of the site folder (such as
public_html), keeping your infected copy from step 1 offline. - Check for files outside the site folder too: cron jobs you did not create, files in the home directory, and other sites in the same account, which are often infected together.
- Remove unknown FTP accounts, SSH keys and database users.
Step 4: restore files and database together
Files and database need to come from the same backup date, or you can end up with a site that loads but has missing images, broken plugins or settings that no longer match.
- Upload the backed-up files to the site folder by FTP, SFTP or your host's file manager.
- In phpMyAdmin, drop the existing tables (or create a new, empty database) and import the backup's .sql file.
- Check the configuration file, such as
wp-config.php, points to the right database, and that you will change its password in the next step. - Scan the restored files with your host's malware scanner or a security plugin before making the site public.
If you keep your own backups on your PC, this step is fast. Rocket Backups backs up website files over FTP or SFTP and MySQL databases on a schedule, keeping each night's files and database dump together as dated versions on your own drive. You pick the date from before the attack and upload a matching set, without waiting on your host's support queue.
Step 5: change every password and key
Assume the attacker saw every password stored on the server. Change all of them:
| Credential | Where to change it |
|---|---|
| Hosting control panel | Your host's account area |
| FTP and SFTP accounts | cPanel → FTP Accounts, or your host's panel |
| Database user | cPanel → MySQL Databases, then update the site's config file |
| CMS admin accounts | Your CMS user settings. Remove any admins you do not recognize. |
| Security keys and salts | For WordPress, replace the keys in wp-config.php, which signs everyone out |
| Email accounts on the domain | Your hosting panel's email section |
| API keys and payment credentials | The relevant service's dashboard |
Also scan the PC you use to manage the site. Stolen FTP credentials from an infected computer are a common way in.
Step 6: close the hole
- Update everything: CMS core, plugins, themes and PHP version. An old backup has old, vulnerable versions, so update before going live.
- Remove unused plugins and themes, including deactivated ones; their files can still be attacked.
- Turn on two-factor sign-in for admin accounts and the hosting panel.
- Check file permissions: typically 644 for files and 755 for folders, and keep configuration files readable only by the account.
- Use SFTP instead of plain FTP if your host supports it, so passwords are not sent unencrypted.
Step 7: go live and check again
- Bring the site back online and browse it as a visitor, including on a phone.
- If search engines flagged the site, request a review in their webmaster tools once it is clean.
- Re-add any content created after the backup date by hand, using your infected copy only as a reference for text, never by copying files back.
- Watch logs and file changes closely for the next few weeks.
What if you have no clean backup?
If every backup is infected, or there are none, you have to clean the site manually: replace the CMS core, plugins and themes with fresh downloads, keep only your uploads folder (after checking it for PHP files, which should not be there), and search the database for injected scripts and unknown admin users. A security professional or your host's cleanup service may be worth the cost.
Once the site is clean, set up the backups that would have made this easier. A nightly, versioned copy on your own storage, independent of the host, turns the next incident into a short restore. See how to back up a website to your computer and how to automate cPanel backups. Rocket Backups can encrypt each copy and email you if a nightly job fails, so you know you have something to restore from.
Frequently asked questions
How do I know my backup is from before the hack?
Check server logs, file modification dates and when symptoms began. Pick a backup from before the earliest sign of the attack, and scan it before going live.
Should I change passwords after restoring a hacked site?
Yes. Change hosting, FTP, database, CMS admin and email passwords, and remove unknown admin users, or attackers may walk straight back in.
Will my host restore my hacked site for me?
Some hosts will restore from their own backups, but retention varies and those backups may also contain the infection. Your own dated copies give you more choice.
