search
php star Featured

How to Solve PHP File Not Executing on Server Problems - Essential Fixes

Essential guide to solve 'PHP file not executing on server' problems. Essential fixes with minimal code examples.

person By Gautam Sharma
calendar_today January 8, 2026
schedule 3 min read
PHP Server Execution Configuration Debugging Code Fixes

The ‘PHP file not executing on server’ error occurs when PHP files are not processed by the server and are displayed as plain text or download instead of being executed.


Common Causes and Fixes

1. Wrong File Extension

<?php
// ❌ Error: Wrong file extension
// File saved as: script.txt instead of script.php
echo "Hello World";
?>
<?php
// ✅ Fixed: Correct file extension
// File saved as: script.php
echo "Hello World";
?>

2. Server Not Configured for PHP

<!-- ❌ Error: Server serves as plain text -->
<?php
echo "This should be executed";
?>
<?php
// ✅ Fixed: Server configured for PHP
echo "This will be executed";
?>

3. PHP Tags Missing

<!-- ❌ Error: No PHP tags -->
Hello World
<?php
// ✅ Fixed: PHP tags included
echo "Hello World";
?>

4. Short Tags Disabled

<?
// ❌ Error: Short tags disabled
echo "Hello World";
?>
<?php
// ✅ Fixed: Full PHP tags
echo "Hello World";
?>

5. File Permissions

# ❌ Error: Wrong permissions
-rw------- script.php  # Only owner can read
# ✅ Fixed: Correct permissions
-rwxr-xr-x script.php  # Owner: rwx, Group: rx, Others: rx
# OR
-rw-r--r-- script.php  # 644 permissions

6. Web Server Configuration

# ❌ Error: Apache not configured for PHP
<FilesMatch "\.php$">
    # PHP handler not configured
</FilesMatch>
# ✅ Fixed: Apache configured for PHP
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>

7. PHP Module Not Loaded

# ❌ Error: PHP module not loaded
apache2ctl -M | grep php  # No PHP modules
# ✅ Fixed: Load PHP module
# In Apache: LoadModule php_module modules/libphp.so
# In Nginx: fastcgi_pass 127.0.0.1:9000;

8. MIME Type Issues

# ❌ Error: Wrong MIME type
AddType text/plain .php
# ✅ Fixed: Correct MIME type
AddType application/x-httpd-php .php

9. Virtual Host Configuration

# ❌ Error: PHP not enabled in virtual host
<VirtualHost *:80>
    DocumentRoot /var/www/html
    # PHP not configured
</VirtualHost>
# ✅ Fixed: PHP enabled in virtual host
<VirtualHost *:80>
    DocumentRoot /var/www/html
    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

10. PHP Configuration

; ❌ Error: PHP execution disabled
engine = Off
; ✅ Fixed: PHP execution enabled
engine = On

Troubleshooting Steps

  1. Check file extension is .php
  2. Verify PHP is installed on server
  3. Test PHP info with <?php phpinfo(); ?>
  4. Check server error logs
  5. Verify file permissions
  6. Confirm web server configuration
  7. Test with simple PHP code

Prevention Tips

  • Always use .php extension
  • Verify server supports PHP
  • Check file permissions (644 for files)
  • Ensure PHP module is loaded
  • Configure web server for PHP
  • Test with simple PHP script first
  • Check server configuration files
  • Monitor server error logs

Remember: PHP files must be processed by the server, not served as plain text.

Gautam Sharma

About Gautam Sharma

Full-stack developer and tech blogger sharing coding tutorials and best practices

Related Articles

php

Fix: PHP file not executing on server error - Quick Solutions

Quick guide to fix 'PHP file not executing on server' errors. Essential fixes with minimal code examples.

January 8, 2026
php

Fix: Cannot modify header information error in PHP - Quick Solutions

Quick guide to fix 'Cannot modify header information' errors in PHP. Essential fixes with minimal code examples.

January 8, 2026
php

[SOLVED]: Headers already sent error in PHP Full Tutorial

Quick guide to fix 'Headers already sent' errors in PHP. Essential fixes with minimal code examples.

January 8, 2026