Overview
After migrating cPanel accounts from one server to another, especially when using LiteSpeed Web Server, you may notice that some websites start downloading the index.php file instead of loading it normally in the browser.
This issue is usually caused by wrong PHP handler directives left inside .htaccess files during migration โ typically referencing EasyApache PHP handlers (ea-php) instead of LiteSpeed (lsphp).
โ ๏ธ Why This Happens
When cPanel generates .htaccess rules, it often adds PHP handlers like:
AddHandler application/x-httpd-ea-php74___lsphp .php .php7 .phtml
These handlers work on Apache with EasyApache, but on LiteSpeed servers using LSPHP, they are invalid. As a result, LiteSpeed doesn't process PHP โ it treats .php files as plain text and sends them as downloads.
๐ Step 1: Detect Affected Accounts
To find which accounts (under /home2) still contain this incorrect handler, use this detection script:
Script: check_php_handler_issue.sh
#!/bin/bash
# This script checks all users in /home2 for .htaccess files
# that contain the old EasyApache PHP handler lines
echo "๐ Scanning for .htaccess files with EA-PHP handlers in /home2..."
for user_home in /home2/*; do
[ -d "$user_home" ] || continue
user=$(basename "$user_home")
if grep -Rqs "AddHandler application/x-httpd-ea-php" "$user_home"; then
echo "โ ๏ธ $user"
fi
done
echo "โ
Scan completed."
Usage:
chmod +x check_php_handler_issue.sh
sh check_php_handler_issue.sh
This will output the usernames that have the old handler issue.
๐งน Step 2: Automatically Fix All Affected Accounts
Once you've confirmed the issue is widespread, run the following script to clean all .htaccess files safely:
Script: fix_all_php_handlers.sh
#!/bin/bash
# This script fixes the "ea-php handler" issue in .htaccess for all users in /home2
echo "๐ง Fixing .htaccess PHP handler issues for all users in /home2..."
for user_home in /home2/*; do
[ -d "$user_home" ] || continue
user=$(basename "$user_home")
echo "๐งฉ Checking user: $user"
find "$user_home" -type f -name ".htaccess" | while read -r file; do
if grep -q "AddHandler application/x-httpd-ea-php" "$file"; then
echo " ๐งน Fixing: $file"
cp -f "$file" "$file.bak_$(date +%F_%T)"
sed -i '/AddHandler application\/x-httpd-ea-php/d' "$file"
sed -i '//d' "$file"
sed -i '/<\/IfModule>/d' "$file"
fi
done
done
echo "โ
All users processed. EA-PHP handlers removed safely."
echo "๐๏ธ Backups created with .bak_ suffix."
Usage:
chmod +x fix_all_php_handlers.sh
sh fix_all_php_handlers.sh
This script:
- Scans all
/home2users - Removes broken EasyApache PHP handler lines
- Keeps LiteSpeed Cache and WordPress rewrite rules intact
- Backs up each
.htaccessbefore editing
๐งพ Step 3: Verify PHP Functionality
After running the fix script, visit any affected domain.
If the site loads normally, the issue is resolved.
You can also test PHP execution manually:
1. Create a file info.php in public_html:
<?php phpinfo(); ?>
2. Visit https://domain.com/info.php
If it displays PHP info, the PHP handler is working correctly.
โ Final Notes
- Always back up your
/home2directory before running batch scripts. - These scripts only modify
.htaccessfiles โ no other website data is affected. - For best results, after fixing, go to WHM โ MultiPHP Manager and ensure each domain uses a valid PHP version (e.g.,
PHP 8.2) with LiteSpeed LSAPI. - If you're using CloudLinux, make sure alt-php or lsphp packages for the required versions are installed.
In Summary
| Issue | Cause | Solution |
|---|---|---|
| PHP files downloading instead of executing | .htaccess using EasyApache handler | Remove AddHandler application/x-httpd-ea-php lines |
| public_html empty or missing | Incomplete migration | Detect using check_empty_public_html.sh |
| LSCache or rewrite errors | Old handler blocks | Clean .htaccess using fix_all_php_handlers.sh |