{"id":330,"date":"2025-06-16T08:36:21","date_gmt":"2025-06-16T03:06:21","guid":{"rendered":"https:\/\/griffso.com\/blogs\/?p=330"},"modified":"2025-06-16T08:36:45","modified_gmt":"2025-06-16T03:06:45","slug":"php-files-download-instead-of-running-in-xampp-fix-for-windows-macos-linux","status":"publish","type":"post","link":"https:\/\/griffso.com\/blogs\/php-files-download-instead-of-running-in-xampp-fix-for-windows-macos-linux\/","title":{"rendered":"PHP Files Download Instead of Running in XAMPP \u2013 Fix for Windows, macOS &amp; Linux"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>PHP Files Download Instead of Running in XAMPP<\/strong><\/h2>\n\n\n\n<p>PHP file downloading instead of executing in XAMPP? Learn how to configure Apache and fix MIME types on Windows, macOS, and Linux\/Ubuntu systems.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83e\udde9 <strong>Introduction<\/strong><\/h3>\n\n\n\n<p>Ever clicked on a <code>.php<\/code> file in your browser only for it to <strong>download<\/strong> instead of <strong>executing<\/strong>? This is a very common issue in XAMPP and typically happens because <strong>Apache isn\u2019t configured to handle PHP properly<\/strong>.<\/p>\n\n\n\n<p>In this blog, we\u2019ll fix the issue step-by-step for <strong>Windows<\/strong>, <strong>macOS<\/strong>, and <strong>Ubuntu\/Linux<\/strong> users.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2757 Why This Happens<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP module isn\u2019t loaded by Apache<\/li>\n\n\n\n<li>MIME type for <code>.php<\/code> not handled<\/li>\n\n\n\n<li>Wrong <code>httpd.conf<\/code> or <code>php.ini<\/code> configuration<\/li>\n\n\n\n<li>PHP isn\u2019t installed or linked correctly (on Linux\/macOS)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udda5\ufe0f <strong>Fix on Windows<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">\u2705 Step-by-Step:<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Open <code>httpd.conf<\/code>:<\/strong>\n<ul class=\"wp-block-list\">\n<li>XAMPP Control Panel > Apache > <strong>Config<\/strong> > <code>httpd.conf<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Enable PHP Module:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Find: <code>#LoadModule php_module \"c:\/xampp\/php\/php8apache2_4.dll\"<\/code><\/li>\n\n\n\n<li>Remove the <code>#<\/code>: <code>LoadModule php_module \"c:\/xampp\/php\/php8apache2_4.dll\"<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Add PHP Handler:<\/strong>\n<ul class=\"wp-block-list\">\n<li>At the bottom of the file, add: <code>AddHandler application\/x-httpd-php .php PHPIniDir \"C:\/xampp\/php\"<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Save<\/strong> and restart Apache.<\/li>\n\n\n\n<li><strong>Verify:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Create a <code>test.php<\/code> file in <code>htdocs<\/code>: <code>&lt;?php phpinfo(); ?><\/code><\/li>\n\n\n\n<li>Visit:<br><code>http:\/\/localhost\/test.php<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83c\udf4f <strong>Fix on macOS<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">\u2705 Step-by-Step:<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Edit Apache config:<\/strong> <code>sudo nano \/Applications\/XAMPP\/xamppfiles\/etc\/httpd.conf<\/code><\/li>\n\n\n\n<li><strong>Enable PHP Module:<\/strong><br>Find and uncomment: <code>LoadModule php_module modules\/libphp.so<\/code><\/li>\n\n\n\n<li><strong>Add PHP Handler:<\/strong><br>Add this if missing: <code>AddHandler application\/x-httpd-php .php<\/code><\/li>\n\n\n\n<li><strong>Set PHP config path:<\/strong><br>Add: <code>PHPIniDir \"\/Applications\/XAMPP\/xamppfiles\/etc\/\"<\/code><\/li>\n\n\n\n<li><strong>Restart Apache:<\/strong> <code>sudo \/Applications\/XAMPP\/xamppfiles\/xampp restartapache<\/code><\/li>\n\n\n\n<li><strong>Test it:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Add <code>test.php<\/code> in <code>\/Applications\/XAMPP\/htdocs\/<\/code><\/li>\n\n\n\n<li>Visit: <code>http:\/\/localhost\/test.php<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udc27 <strong>Fix on Linux\/Ubuntu<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">\u2705 Step-by-Step:<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Edit Apache config:<\/strong> <code>sudo nano \/opt\/lampp\/etc\/httpd.conf<\/code><\/li>\n\n\n\n<li><strong>Uncomment PHP Module:<\/strong><br>Find and ensure: <code>LoadModule php_module modules\/libphp.so<\/code><\/li>\n\n\n\n<li><strong>Add Handler if missing:<\/strong> <code>AddHandler application\/x-httpd-php .php PHPIniDir \"\/opt\/lampp\/etc\"<\/code><\/li>\n\n\n\n<li><strong>Restart Apache:<\/strong> <code>sudo \/opt\/lampp\/lampp restartapache<\/code><\/li>\n\n\n\n<li><strong>Verify:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Add <code>test.php<\/code> in <code>\/opt\/lampp\/htdocs\/<\/code>: <code>&lt;?php phpinfo(); ?><\/code><\/li>\n\n\n\n<li>Open: <code>http:\/\/localhost\/test.php<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Bonus Check (All Platforms)<\/h3>\n\n\n\n<p>If you\u2019re using <code>.htaccess<\/code>, ensure it doesn\u2019t override PHP handling with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RemoveHandler .php\nAddType application\/x-httpd-php .php\n<\/code><\/pre>\n\n\n\n<p>Also verify your browser isn\u2019t caching an old MIME type. Try opening the file in <strong>incognito\/private window<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udccc Conclusion<\/h3>\n\n\n\n<p>The issue where PHP files download instead of run is always tied to a <strong>missing or misconfigured PHP handler in Apache<\/strong>. Whether you\u2019re using Windows, macOS, or Ubuntu, follow the steps above to get your server running properly.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcac Need Help?<\/h3>\n\n\n\n<p>Post your <code>httpd.conf<\/code> snippet or system info in the comments\u2014I\u2019ll guide you further!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<div class=\"pld-like-dislike-wrap pld-template-1\">\n    <div class=\"pld-like-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"330\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\n                        <i class=\"fas fa-thumbs-up\"><\/i>\n                <\/a>\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"330\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\n                        <i class=\"fas fa-thumbs-down\"><\/i>\n                <\/a>\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>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. \ud83e\udde9 Introduction Ever clicked on a .php file in your browser only for it to download instead of executing? This is a very common [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-330","post","type-post","status-publish","format-standard","hentry","category-coding-help-programming-tips-code-examples-coding-resources-debug-guide-software-development-learn-to-code-coding-best-practices-coding-challenges-coding-tutorials"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/posts\/330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/comments?post=330"}],"version-history":[{"count":1,"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/posts\/330\/revisions"}],"predecessor-version":[{"id":331,"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/posts\/330\/revisions\/331"}],"wp:attachment":[{"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/media?parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/categories?post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/griffso.com\/blogs\/wp-json\/wp\/v2\/tags?post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}