One vulnerable upload can give an attacker a quiet way into your website. A single disguised script may expose passwords, alter pages, or create a backdoor that keeps returning after cleanup.
The safest way to block PHP uploads WordPress sites receive is to stop uploaded scripts from executing. We also need strong file rules, updated plugins, sensible permissions, and hosting that watches for trouble. Let’s start with the risk inside the uploads folder.
Why the WordPress uploads folder needs protection
WordPress normally stores images, PDFs, videos, and other media in wp-content/uploads. Those files need to be publicly available so visitors can view them. That public access creates a target.
An attacker doesn’t need to upload a file named malware.php. They may use a double extension, a less common PHP extension, or a vulnerable plugin that handles uploads poorly. If the server treats that file as executable code, the attacker may run commands through its URL.
The result can be serious:
- Malicious code may create administrator accounts.
- Attackers may inject spam links into posts and pages.
- Website files may be changed or deleted.
- Database credentials may be exposed.
- A backdoor may remain after the original file disappears.
A media upload folder should store content, not run code. That distinction gives us a practical security rule: PHP execution has no place inside a normal WordPress uploads directory.

WordPress itself checks many common upload types, but those checks aren’t a complete security boundary. A plugin can introduce a file-handling flaw. A compromised administrator account can also bypass normal expectations.
That’s why server-level protection matters. Even if a harmful script reaches wp-content/uploads, the web server should refuse to execute it.
Block PHP uploads WordPress sites cannot safely execute
The exact fix depends on your hosting stack. Apache servers usually use .htaccess. Nginx servers ignore .htaccess, so the rule belongs in the server configuration.
Before changing anything, create a backup of the current file and confirm whether your website uses Apache, LiteSpeed, or Nginx. If you’re unsure, ask your hosting provider. A wrong server rule can produce errors or fail without giving you any warning.
Apache and LiteSpeed: add an uploads rule
On Apache or LiteSpeed, create a file named .htaccess inside:
wp-content/uploads/
Do not place this rule in the website’s root .htaccess unless your hosting support team tells you to. The uploads folder is the narrowest location, so the protection affects media files without interfering with WordPress core.
For Apache 2.4 and newer, use:
<FilesMatch "\.(php|phtml|php[0-9]?|phar)$">
Require all denied
</FilesMatch>
This blocks common PHP variations, including .php, .phtml, .php5, and .phar files. The server returns a forbidden response instead of handing the file to PHP.
Some older Apache setups use this syntax instead:
<FilesMatch "\.(php|phtml|php[0-9]?|phar)$">
Order Allow,Deny
Deny from all
</FilesMatch>
Use one version, not both. If your host uses cPanel, you can create the file through File Manager. For a step-by-step file-manager example, see one.com’s guide to disabling file execution.
The same approach is commonly recommended in the WordPress.org support discussion about disabling PHP execution. The rule is small, but its location matters. It must sit directly inside the uploads directory.

Nginx: add a server-level location rule
Nginx doesn’t read .htaccess. Adding that file to wp-content/uploads won’t protect the directory on an Nginx server.
Your host needs to add a rule to the Nginx server block:
location ~* ^/wp-content/uploads/.*\.(php|phtml|php[0-9]?|phar)$ {
deny all;
return 403;
}
The rule matches PHP-related extensions below wp-content/uploads and returns HTTP status 403. That means the file can exist, but the web server won’t allow it to run.
Nginx rules can interact with other location blocks, especially a general PHP handler. The order and pattern need to match your server’s existing configuration. This is one reason we don’t recommend editing production Nginx settings without a backup and a way to restore the previous version.
If your website uses managed hosting, send the rule to support rather than guessing. A hosting technician can check the active web server, place the rule correctly, and reload the configuration safely.
Test the protection before trusting it
A rule that looks correct isn’t enough. Test the result.
Upload a harmless file named test.php containing plain text, or ask your host to test the path without placing a real script there. Then request its URL, such as:
https://example.com/wp-content/uploads/test.php
A working block should return 403 Forbidden or another non-executable response. You should not see PHP output, a blank page generated by PHP, or a download that exposes source code.
Delete the test file after checking it. If the request returns a normal page or executes code, contact your host immediately. The protection isn’t active yet.
Strong upload security needs more than one rule
Blocking execution closes one dangerous door. It doesn’t replace the rest of your WordPress security work.
Start with the upload process itself. Only allow the file types your website needs. A photography site may need JPEG, PNG, WebP, and PDF files. It probably doesn’t need PHP, JavaScript, shell scripts, or server-side templates.
Use trusted plugins that receive regular updates. Pay attention to plugins that accept profile pictures, contact form attachments, ZIP files, or document submissions. Upload features deserve extra scrutiny because they move files from a visitor’s browser onto your server.
Keep WordPress core, themes, and plugins updated. Security fixes only help when they reach your site. Remove plugins and themes you no longer use instead of leaving inactive software in place.
File permissions matter too. WordPress needs enough access to manage media, but every account and process shouldn’t have unrestricted control over every file. Your hosting provider can recommend the right ownership and permission setup for its server.
A practical baseline includes:
- Blocking PHP execution in
wp-content/uploads. - Disabling unused plugins, themes, and server features.
- Using separate administrator accounts instead of sharing one login.
- Requiring strong passwords and two-factor authentication where available.
- Keeping off-site backups that you can restore.
- Reviewing security alerts, login activity, and unexpected file changes.
Don’t overlook older files. If an attacker already placed a backdoor in the uploads folder, adding .htaccess won’t remove it. Review recently modified files, scan the website, check administrator accounts, and restore from a clean backup when needed.
A security plugin can help with scanning and alerts, but it shouldn’t be your only control. Application tools, server rules, account security, and reliable backups work better together.
How hosting makes WordPress upload protection easier
Website owners often know they need protection but don’t want to edit server files every week. That’s reasonable. Your time belongs on customers, orders, and growth, not on hunting through configuration menus.
The right hosting plan reduces that burden. ZADiC provides WordPress hosting and cPanel hosting for site owners who want simple setup without giving up dependable infrastructure. With cPanel access, you can manage files, domains, SSL, backups, and email in one familiar place.
When you need more help, our managed Web Hosting Plus options add hands-on support and room to grow. We can help confirm whether your site runs Apache, LiteSpeed, or Nginx, then point you toward the correct protection for that environment.
Our VPS options fit websites that need more control over server settings. That flexibility is useful when you manage Nginx rules, custom applications, or several WordPress installations. It also means you need a clear maintenance plan, so managed support can be a better fit if you don’t want server administration on your plate.
Security monitoring and 24/7 human support give you another practical advantage. When a file behaves strangely or a website suddenly shows a forbidden error, you have someone to contact instead of relying on trial and error.
Free SSL on many plans protects data moving between your visitors and website. One-click WordPress setup gets the site online quickly. The goal is straightforward: secure hosting that lets you focus on the business using the website.
Check your WordPress uploads protection today
If you want to block PHP uploads WordPress sites should never execute, begin with the server rule in wp-content/uploads. Apache and LiteSpeed need a local .htaccess file. Nginx needs a server-block rule.
Then test the result with a harmless file request, remove the test file, and review the rest of your security setup. Update software, restrict upload types, protect administrator accounts, maintain clean backups, and monitor unexpected changes.
A malicious PHP file is dangerous because it can look like an ordinary upload until the server runs it. Stop that execution path first. With the right hosting setup and a few focused controls, your uploads folder can stay useful without becoming an open door.





