If you manage more than one WordPress site on the same server, a single compromised site can quickly become a compromised server, and then every other site is at risk. This guide shows you how to isolate each WordPress installation so that a hack on one site does not spread to the others. You will learn to separate files, databases, and user permissions, and how to contain a breach if it happens. These steps assume you have basic command-line access to your server (SSH) and can create databases.
What You’ll Need
- SSH access to your server (root or a user with sudo privileges).
- Ability to create and manage MySQL or MariaDB databases (often via cPanel, Plesk, or command line).
- Basic familiarity with the command line (cd, cp, chown, chmod).
- For the advanced option: ability to edit Apache or Nginx configuration files.
Step-by-Step
- Separate user accounts per site (the most important step). Do not run all your WordPress sites under the same system user. Create a dedicated system user for each site. For example, if you have
site1.comandsite2.com, create userssite1userandsite2user. Use a command likeadduser site1user(on Debian/Ubuntu) oruseradd -m site1user(on CentOS/RHEL). - Place each site in its own directory. Instead of putting all sites in
/var/www/html, use a structure like/home/site1user/public_htmland/home/site2user/public_html. This ensures that file permissions are naturally scoped to the user. - Set correct ownership and permissions. After uploading your WordPress files, run:
chown -R site1user:site1user /home/site1user/public_htmlfind /home/site1user/public_html -type d -exec chmod 755 {} \;find /home/site1user/public_html -type f -exec chmod 644 {} \;
This prevents other users from reading or writing to the files. The web server (e.g.,www-data) should not own the files; it only needs read access. - Give the web server only minimal access. If your PHP runs as the site user (using PHP-FPM with a pool per user), the web server process runs as that user, so it can read and write files. If you use Apache with mod_php, the web server runs as
www-data, so you will need to givewww-dataread access to the files, but not write access to everything. A common approach is to make the site user the owner and the web server group read-only. For example:chown -R site1user:www-data /home/site1user/public_htmland set directories to 755 and files to 644. For writable directories (likewp-content/uploads), set them to 775 with groupwww-data. - Use separate databases and database users. Create a unique database and a unique database user for each site. For example, for site1:
CREATE DATABASE site1db;andCREATE USER 'site1dbuser'@'localhost' IDENTIFIED BY 'strongpassword';thenGRANT ALL PRIVILEGES ON site1db.* TO 'site1dbuser'@'localhost';Never reuse a database user across sites. Updatewp-config.phpwith the unique credentials. - Limit database user privileges. For an extra layer, do not grant
ALL PRIVILEGES. Instead, grant onlySELECT, INSERT, UPDATE, DELETEon the site’s database. This means that even if the database credentials are stolen, the attacker cannot drop tables or alter the database structure. You can do this with:GRANT SELECT, INSERT, UPDATE, DELETE ON site1db.* TO 'site1dbuser'@'localhost'; - Disable PHP execution in uploads directories. Add the following to your
.htaccessfile inwp-content/uploads/(if using Apache):<FilesMatch "\.(php|php5|phtml)$">Require all denied</FilesMatch>
For Nginx, add a location block to deny PHP in that directory. - Use a web application firewall (WAF) per site. A WAF like Wordfence or Sucuri can block malicious requests before they reach your server. Install a security plugin on each site and configure it to block common attack patterns. This does not isolate sites, but it reduces the chance of a hack in the first place.
- Keep each site’s core, themes, and plugins updated. Outdated software is the most common entry point. Enable automatic updates for minor core releases, and update plugins and themes as soon as updates are available. Many security plugins can automate this.
- If you are on a shared hosting plan, consider upgrading to a VPS or dedicated server. Shared hosting often runs all sites under the same user, making isolation impossible. On a VPS, you have full control over users and permissions.
- Implement a backup strategy that is also isolated. Store backups offsite (e.g., Amazon S3, Google Drive) and do not keep them in the web root. Test restoring a backup at least once.
- Monitor for unusual activity. Review access logs regularly for suspicious requests (e.g.,
wp-login.phpbrute force attempts). Use a security plugin that sends email alerts for file changes, new admin users, or failed login attempts.
Common Mistakes
- Using the same system user for all sites. This defeats the purpose of isolation. If one site is hacked, the attacker can read and modify files of all other sites.
- Sharing database users. If the attacker gets the database credentials from one site, they can access all databases that user has privileges on.
- Giving the web server full write access to all files. This is often necessary for shared hosting, but it means a compromised PHP script can write to any file. Use the principle of least privilege.
- Ignoring file permissions. If files are world-writable (777), any user on the server can modify them. Always use 644 for files and 755 for directories, and only give write access where needed.
- Not isolating the database server. Even if you have separate databases, if the MySQL user has global privileges (e.g.,
GRANT ALL ON *.*), they can access everything. Always restrict to specific databases.
Tips
- Use PHP-FPM with per-site pools. This is the best way to run PHP as the site user. Configure each pool to run as the respective site user. This ensures that PHP scripts can only write to that site’s files.
- Consider using a container or VM per site. For maximum isolation, run each site in a separate Docker container or a lightweight VM. This is more resource-intensive but completely isolates the filesystem, processes, and network.
- Use a security plugin that includes file integrity monitoring. This can alert you to changes in core files, which often indicates a hack.
- Disable file editing in wp-config.php. Add
define('DISALLOW_FILE_EDIT', true);to prevent admins from editing theme and plugin files from the dashboard. This reduces the attack surface. - Use strong, unique passwords for each database user and admin account. A password manager can help.
Troubleshooting
- Site becomes inaccessible after changing permissions. If you set files to 644 and directories to 755, but the site still shows a 500 error, the web server may not have read access. Check the ownership: the web server (e.g.,
www-data) must have read permission on all files. If you usedchown site1user:site1user, the web server cannot read them. Change the group towww-dataand set files to 640 and directories to 750, or add read permission for ‘others’ (but that is less secure). - Uploads fail. If you cannot upload images, the
wp-content/uploadsdirectory needs write permission for the web server. Set ownership tosite1user:www-dataand permissions to 775. Also, ensure the directory exists and is owned correctly. - Database connection errors. If you changed database users, make sure the new user has privileges on the correct database. Test with:
mysql -u site1dbuser -p site1db. If you get ‘Access denied’, re-run the GRANT command. - PHP-FPM pool not working. If you configure a pool per user, ensure the pool file has the correct user and group, and that the socket file is writable by the web server. Check the PHP-FPM error log for details.
- Site loads but images are broken. This often happens if file permissions are too restrictive. Check that the web server can read the image files. Use
ls -lto see permissions.
Frequently Asked Questions
Can I isolate WordPress sites on shared hosting?
Usually not. Shared hosting often runs all sites under the same system user, so file isolation is impossible. You can still use separate databases, but a hack on one site can still read other sites’ files. Consider a VPS or a managed WordPress plan that offers isolation.
Do I need to isolate if I only have one WordPress site?
If you have only one site, isolation is less critical, but you should still use separate database users and limit privileges. The main risk is if you later add more sites, so it is good practice to set up isolation from the start.
What is the most important step?
Using a separate system user for each site is the most impactful step. It prevents an attacker from reading or modifying other sites’ files if they compromise one site.
Should I use a security plugin even with isolation?
Yes. Isolation limits the blast radius, but a security plugin can prevent the hack in the first place. Use one that offers a firewall, malware scanning, and login protection.
How often should I check for breaches?
At least weekly, but daily is better. Many security plugins can automate scans and email you on suspicious activity. Also, review your server logs regularly.
Can I isolate using a WordPress multisite network?
Multisite actually shares the same codebase and database, so it does not isolate sites. If one site is hacked, the attacker can often access the entire network. It is not a recommended isolation method.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Tongue Escape Codes: What They Are0.20 movements/s
- Claude Code Workflow Habits Worth Trying
- HDMI 2.1 Explained: Why It Matters for Gaming
- Veeam Plugin for VMware Cloud Director: How It Works
- Oppo First Foldable: 120Hz Display & Snapdragon 888
- Samsung One UI: What It Is & How It Works