Article
How to tell if your PHP site has been hacked (checks you can run today)
Published 2026-11-26
How to tell if your PHP site has been hacked (checks you can run today)
Most hacked PHP sites are not defaced. The attacker's interest is in your server staying useful: sending spam, hosting phishing pages, storing content, acting as a relay. A defacement announces the intrusion to everyone including you, so it is the exception. The rule is a site that looks completely normal to its owner for weeks.
That is why discovery usually arrives sideways. Google Search Console emails you about "deceptive pages detected". A customer mentions the site redirects on their phone but not on a desktop. Your host suspends the account over outbound traffic nobody can explain. Each of those means the intrusion is old by the time you hear about it.
This article is about finding out whether it happened: the outside signs, the file checks, the log patterns, and just as importantly the things that look like evidence but are not. The commands assume a typical Linux host with shell access and a PHP application under /var/www. On shared hosting without SSH the same checks work through the file manager; they just take longer.
What a compromise on a PHP site usually looks like
Two shapes account for most of what you will find.
The first is a planted file. A PHP script dropped somewhere the web server executes it, callable over HTTP like any other page. CISA describes a web shell plainly: a script uploaded to a web server that gives an attacker remote administration of the machine. In PHP that means a file you never wrote, reachable at a URL, running whatever parameters arrive in the request. Small ones fit in a single line. Big ones (FilesMan and its relatives) have interfaces, and turn up on pastebin-style collections with filenames like mysql.php or alfa.php.
The second is injected code. A line or two appended to a file that already exists: index.php, a template, a commonly included config. The line might pull the actual payload from a remote host, so the injected file looks almost untouched. Or it might do its work inline and keep a low profile, checking the visitor's user agent or referer and serving spam only to search-engine crawlers, which is called cloaking. The site looks fine to you because it is fine for you; the crawler sees a pharmacy.
Both shapes depend on one thing: executable code in a place the web server will run it. Every check below is some version of looking for that.
The outside signs
Start with the things you can see without a terminal:
- Search Console security issues: "deceptive pages", "harmful content". Google is often the first to know. The Security Issues report names the URLs and the category. If Search Console flags pages you never created, you have cloaked spam, and the intrusion predates the flag by a while.
- Browser or Safe Browsing warnings that appear for your domain. Google's Safe Browsing status page shows what is currently listed.
- Redirects that happen for some visitors and not others (mobile only, or traffic from search only, or specific countries). Random-seeming redirect behavior is a strong tell because legitimate plugins redirect everyone or no one.
- New administrator accounts in the CMS. On any PHP application with a users table, check the newest accounts and their creation dates against reality.
- A search for
site:yourdomain "viagra"orsite:yourdomain "online casino"revealing pages you never wrote. Large sites find years of junk this way. - The host's abuse notice. Read it as a fact about traffic leaving your server, not as a diagnosis.
None of these alone is a verdict. Each narrows the search before you touch the filesystem.
File checks: what to look for and the commands that find it
PHP files in upload folders
Upload folders hold media. They should contain no executable code, ever, because nothing legitimate writes PHP there. A single .php file in an uploads directory is a planted shell until proven otherwise, and extensions are not just .php: .phtml, .phar, and .php5 all execute on default setups.
find /var/www -path '*/uploads/*' -type f \( -name '*.php' -o -name '*.phtml' -o -name '*.phar' \)
find /var/www -path '*/files/*' -type f \( -name '*.php' -o -name '*.phtml' -o -name '*.phar' \)
Run both with your real document root. An empty result here is genuinely good news, unlike most checks.
Recently modified or newly created files
The fastest triage is time. Sort by modification time and read the newest files:
find /var/www -type f -name '*.php' -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r | head -40
Timestamps lie, though: touch -r copies a file's times onto another file, and attackers use it. So use this to find candidates, not to rule anything out. What you want is to know which files changed around the date the outside signs started.
The usual shell signatures
Shells obfuscate, but the building blocks repeat. Grep for them:
grep -RIlE "eval\s*\(\s*(base64_decode|gzinflate|str_rot13|gzuncompress)" /var/www --include='*.php'
grep -RIlE "FilesMan|WSO\s*[0-9]|c99shell|r57shell" /var/www --include='*.php'
grep -RIl "auto_prepend_file" /var/www --include='.htaccess'
The eval(base64_decode(...)) family is the classic: a blob nobody can read that decodes into whatever the attacker wanted. Georgia Tech's guidance for compromised sites suggests a similar search for eval(gzinflate, preg_replace with the /e modifier (which executes the replacement as PHP, and was removed in PHP 7), and FilesMan. Expect obfuscation the greps will miss: long hex strings passed to pack() or hex2bin(), $ variables built from pieces at runtime, calls to assert(), create_function() (removed in PHP 8), or call_user_func with a variable function name. That is why the next check exists.
Compare against a clean copy
The only grep that cannot be obfuscated away is a diff. If your application has a known-good source (a release archive, a fresh composer install, a current version of the CMS, a yesterday copy from your deployment pipeline), compare:
diff -r /var/www/html clean-copy/ --exclude=uploads --exclude=node_modules
New files and changed files come out in the open. For WordPress, core checksums can be verified directly: wp core verify-checksums compares every core file against the release from wordpress.org and prints each mismatch, which catches modified core files that greps miss. Plugins can be checked the same way with wp plugin verify-checksums for plugins hosted on wordpress.org.
Images that are not images
Upload folders also hide code wearing an image extension, either as polyglots or with a second extension like shell.php.jpg. A quick pass:
find /var/www -path '*/uploads/*' -type f \( -iname '*.jpg' -o -iname '*.png' \) -exec grep -Il "<?php" {} +
.htaccess and config files
.htaccess is attractive to attackers because the web server honors it without any PHP involvement. Two patterns to search for:
find /var/www -name '.htaccess' -exec grep -HiE "auto_prepend_file|auto_append_file|php_value" {} +
auto_prepend_file tells PHP to load and execute a script before every request. An attacker who sets it in one .htaccess has effectively compromised every page under that directory, including ones you clean afterward. This is the classic reason people clean a site, watch it get reinfected within a day, and conclude the hack was "persistent" when it was a one-line config directive they never read.
User-level php.ini and .user.ini files deserve the same look. On CGI/FastCGI setups, .user.ini in a directory gets loaded per-directory just like .htaccess, and it accepts the same auto_prepend_file.
Logs: what the request trail tells you
Access log
You are looking for the requests that brought the shell in and the requests that used it:
grep "POST" /var/log/nginx/access.log | awk '{print $7}' | sort | uniq -c | sort -rn | head -20
grep -E " (5[0-9]{2}) " /var/log/nginx/access.log | tail -50
The interesting lines are POSTs to paths that have no business accepting POSTs, or to files that should not exist at all. When you find the first hit on a planted file, look at what the same IP requested just before it; that sequence often shows the upload or the exploit that created the file, which tells you the entry point. Then the entry point tells you what to patch after you clean, which is the part everyone skips and then gets hacked again through the same hole.
PHP and server error logs
The 2026 PHP supply-chain incident tagged PHP2Shell (CVE-2026-1096) made a specific set of error-log patterns worth knowing, because advisory after advisory repeated them: PHP memory exhaustion errors during request startup, often reported in Unknown on line 0; worker crashes and segmentation faults, including Apache AH00052 child-process exits; repeated 5xx responses following unusual POSTs; PHP_SESSION_UPLOAD_PROGRESS appearing in request bodies where it has no business being. Those are attempts, not proof. But a new or changed PHP file appearing in the hours after that pattern is proof, and the two together are how most of these incidents were actually found.
The PHP advisory said something worth keeping in mind for every check in this article: the absence of errors in the logs is not proof of safety. A successful exploit that stays inside a worker and returns HTTP 200 leaves nothing in an error log by design.
Outbound
ss -tnp | grep -E 'php|nginx|apache'
crontab -l; ls /etc/cron* -la
A web server process that keeps a connection open to an unfamiliar host is a strong signal. Unexpected cron jobs are the persistence mechanism of choice: a one-line entry that re-downloads the shell every hour survives every file cleanup, which is why "we deleted the file and it came back" is a common story. Read every cron entry before assuming any of them is yours.
The database
Content spam often lives in the database rather than in files: pages or posts that exist only for crawlers, injected script tags in text fields, stored user records with administrator rights.
SELECT user_login, user_registered FROM wp_users ORDER BY user_registered DESC; -- WordPress
grep -R "%eval(%<\|%base64_%" dump.sql -- generic strings
A database dump grepped for base64_decode and eval( catches payload-in-database cases where the file system is clean and you would otherwise conclude the site is fine.
What is not evidence
A clean log is not proof of safety, as above. A single 500 response is not a hack; applications produce 5xx on their own all day. A weird filename is not a hack; plenty of legitimate libraries have ugly names, and deleting files because the name looks strange is how people break their own sites. Google flagging one URL is a reason to check, not a verdict. The honest position is that all of these checks are individual signals, and the confidence comes from the combination: a POST pattern in the log, a file in uploads with a matching timestamp, and an outbound connection all pointing at the same afternoon.
If you find something
Contain first, understand second. Preserve a copy of the planted files and the logs around them before deleting anything, because the entry-point analysis depends on that evidence. Take the site offline or restrict access if it is actively serving malware. Patch whatever the entry point turned out to be. Then choose between cleaning and restoring: for a site with a known-good copy or backup from before the compromise, restoring is usually the better bet, after you verify the backup is clean and the entry point is closed. And rotate every credential the PHP process could read: database passwords, salts, API keys in config files. A cleaned site with unchanged credentials is a door with the same key.
Questions people ask
What is a web shell?
A script uploaded to a web server that gives an attacker remote administration of the machine, as CISA defines it; on a PHP site this is usually a PHP file in an uploads folder or code appended to a legitimate file.
Can a hacked site look completely normal?
Yes, and that is the common case. Shells are designed to be quiet, and cloaked spam is served only to search-engine crawlers, so the owner browsing their own site sees nothing wrong.
Does a clean access log mean the site is safe?
No. A successful exploit can return HTTP 200 and stay inside the PHP worker, and the PHP advisory on the 2026 supply-chain incident states plainly that the absence of errors in logs is not proof of safety.
Should I delete a suspicious file immediately?
Make a copy first. The file and the requests around it are the evidence for finding the entry point, and deleting them before you understand the sequence is how sites get reinfected through the same hole.
CheckWebSecurity's scan covers the outside signs a compromise leaves on the perimeter: readable config and backup files, exposed directories, and header and TLS problems that often accompany a neglected server. Run a scan after you have cleaned, not instead of cleaning; a green scan says nothing about a shell inside a web root.
Related: 13 signs your WordPress site is hacked · Backup files: the .bak next to your config that hands over the keys · An exposed .git directory: why it gives away your whole repository · Why an exposed phpinfo() page is a real problem