PHP Files Download Instead of Running in XAMPP
PHP file downloading instead of executing in XAMPP? Learn how to configure Apache and fix MIME types on Windows, macOS, and Linux/Ubuntu systems.
🧩 Introduction
Ever clicked on a .php
file in your browser only for it to download instead of executing? This is a very common issue in XAMPP and typically happens because Apache isn’t configured to handle PHP properly.
In this blog, we’ll fix the issue step-by-step for Windows, macOS, and Ubuntu/Linux users.
❗ Why This Happens
- PHP module isn’t loaded by Apache
- MIME type for
.php
not handled - Wrong
httpd.conf
orphp.ini
configuration - PHP isn’t installed or linked correctly (on Linux/macOS)
🖥️ Fix on Windows
✅ Step-by-Step:
- Open
httpd.conf
:- XAMPP Control Panel > Apache > Config >
httpd.conf
- XAMPP Control Panel > Apache > Config >
- Enable PHP Module:
- Find:
#LoadModule php_module "c:/xampp/php/php8apache2_4.dll"
- Remove the
#
:LoadModule php_module "c:/xampp/php/php8apache2_4.dll"
- Find:
- Add PHP Handler:
- At the bottom of the file, add:
AddHandler application/x-httpd-php .php PHPIniDir "C:/xampp/php"
- At the bottom of the file, add:
- Save and restart Apache.
- Verify:
- Create a
test.php
file inhtdocs
:<?php phpinfo(); ?>
- Visit:
http://localhost/test.php
- Create a
🍏 Fix on macOS
✅ Step-by-Step:
- Edit Apache config:
sudo nano /Applications/XAMPP/xamppfiles/etc/httpd.conf
- Enable PHP Module:
Find and uncomment:LoadModule php_module modules/libphp.so
- Add PHP Handler:
Add this if missing:AddHandler application/x-httpd-php .php
- Set PHP config path:
Add:PHPIniDir "/Applications/XAMPP/xamppfiles/etc/"
- Restart Apache:
sudo /Applications/XAMPP/xamppfiles/xampp restartapache
- Test it:
- Add
test.php
in/Applications/XAMPP/htdocs/
- Visit:
http://localhost/test.php
- Add
🐧 Fix on Linux/Ubuntu
✅ Step-by-Step:
- Edit Apache config:
sudo nano /opt/lampp/etc/httpd.conf
- Uncomment PHP Module:
Find and ensure:LoadModule php_module modules/libphp.so
- Add Handler if missing:
AddHandler application/x-httpd-php .php PHPIniDir "/opt/lampp/etc"
- Restart Apache:
sudo /opt/lampp/lampp restartapache
- Verify:
- Add
test.php
in/opt/lampp/htdocs/
:<?php phpinfo(); ?>
- Open:
http://localhost/test.php
- Add
✅ Bonus Check (All Platforms)
If you’re using .htaccess
, ensure it doesn’t override PHP handling with:
RemoveHandler .php
AddType application/x-httpd-php .php
Also verify your browser isn’t caching an old MIME type. Try opening the file in incognito/private window.
📌 Conclusion
The issue where PHP files download instead of run is always tied to a missing or misconfigured PHP handler in Apache. Whether you’re using Windows, macOS, or Ubuntu, follow the steps above to get your server running properly.
💬 Need Help?
Post your httpd.conf
snippet or system info in the comments—I’ll guide you further!