๐Ÿ”ฅ Sizzling Summer Deals! Up to 78% Off Hosting + Free Domain & Website Migration
โฐ Expires In: 23h 59m 38s
View Deals
HosterOcean.com
Knowledge Base

How to Fix PHP Files Downloading Instead of Executing?

After migrating cPanel accounts, especially with LiteSpeed Web Server, PHP files may download instead of executing properly.

by dotmedia โ€ข Knowledge Base

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 /home2 users
  • Removes broken EasyApache PHP handler lines
  • Keeps LiteSpeed Cache and WordPress rewrite rules intact
  • Backs up each .htaccess before 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 /home2 directory before running batch scripts.
  • These scripts only modify .htaccess files โ€” 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

Tags:

apache mime types bash script for cpanel cpanel migration problems cpanel php handler configuration cpanel to cpanel migration issue fix php file download issue how to fix php files downloading in wordpress htaccess php handler linux server fix litespeed php handler fix litespeed web server php configuration fix php downloading instead of running php execution issue php files downloading cpanel php files downloading in browser php files downloading instead of executing php handler issue cpanel php mime type error php not executing php not executing after migration server configuration error web hosting troubleshooting why are php files downloading instead of opening wordpress php issue

Related Articles

Business Guide

How to Choose the Best Web Hosting for Your Business 2026

Complete guide to selecting the perfect web hosting solution for your business needs, budget, and growth plans in 2026.

Read More โ†’
Technical Guide

How to Update PHP Settings for All Versions in cPanel & CloudLinux Using a Bash Script

Learn how to efficiently update PHP settings across multiple versions using automated bash scripts for better server management.

Read More โ†’

Take your website online with HosterOcean!

Still on the fence? Give it a shot for just $0.95/month for the first month!

Get Started