Post actualizado el día octubre 26, 2026 by DeiviSanzPlay
You fire up XAMPP, Apache says it’s running, you hit localhost, and instead of your PHP page you get raw code, a blank screen, or a 404. Classic. If that’s you, you’re not alone: PHP not working on a local XAMPP server is one of the most searched headaches among devs setting up a local environment in 2026.
I’ve broken this down the way I’d explain it to a friend over coffee: no fluff, no «in conclusion», just what actually fixes the error and why. Because 90% of the time it’s the same handful of culprits, and none of them are mysterious.
Why XAMPP stops executing PHP files (the real causes)
Before you reinstall anything, understand this: XAMPP is just a bundle — Apache, MySQL, PHP, and Perl — glued together. If PHP isn’t executing, the problem is almost always one of these: you’re opening the file through the wrong protocol (file:/// instead of http://localhost/), the file isn’t inside htdocs, or Apache isn’t actually loading the PHP module.
The XAMPP local server PHP error that shows your PHP as plain text is the most common and the most telling. It means Apache is serving the file but treating it as static HTML. That’s a handler problem, not a code problem.
Check the file location first. PHP only runs from inside the XAMPP web root. On Windows that’s C:xampphtdocs, on Linux /opt/lampp/htdocs. If your file lives on your Desktop, you’re opening it with the file protocol and PHP will never fire.
The php.ini and httpd.conf checks nobody does properly
Open the XAMPP control panel, click Config next to Apache, and open httpd.conf. Search for the line LoadModule php_module. If it’s commented out with a #, that’s your problem. Uncomment it, save, restart Apache. Done.
Then hit php.ini. Two things matter: the extension_dir path pointing to the right folder, and any extension you actually need (like mysqli or gd) being uncommented. A missing extension won’t crash your whole page, but it will throw fatal errors that look like PHP is broken.
Here’s a trick most tutorials skip: create a file called info.php inside htdocs with just <?php phpinfo(); ?> and open it at http://localhost/info.php. If that renders, PHP works and your issue is elsewhere. If it shows the code as text, Apache isn’t parsing PHP at all.
Port conflicts: the silent killer behind «localhost refused to connect»
You’ve probably seen the infamous Apache shutdown unexpectedly error. It’s almost always a port conflict. Skype, IIS, VMware, and even some Windows services grab port 80 before XAMPP can.
Fix it by opening httpd.conf and changing Listen 80 to Listen 8080, and ServerName localhost:80 to ServerName localhost:8080. Then access your site at http://localhost:8080. Do the same for the SSL port (443 → 4433) in httpd-ssl.conf if Apache still refuses to start.
If Apache starts but localhost refuses to connect, 8 times out of 10 you’ve got another service squatting on port 80. Change the port, don’t fight the service.
MySQL won’t start? This is what’s actually broken
The XAMPP MySQL shutdown unexpectedly error is a different beast. It usually means corrupted InnoDB files in xampp/mysql/data. The fix that works most often is deleting ib_logfile0 and ib_logfile1 from that folder and restarting MySQL from the control panel.
If that fails, back up ibdata1, then restore it from a clean install or backup. And if you get cannot create file xampp-control.ini, just run XAMPP as administrator — it’s a permissions issue, not a config one.
Quick checklist for PHP failures in XAMPP
- File is inside htdocs and accessed via http://localhost/, not file:///.
- PHP module is uncommented in httpd.conf.
- Port 80 is free (or changed to 8080).
- MySQL is actually running when your script hits the database.
- Your PHP version matches what your code expects (PHP 8.x is standard in 2026).
Version mismatch and permissions: two underrated culprits
If you’re running legacy code written for PHP 5 on a modern XAMPP stack, functions like mysql_connect() are gone. That’s not an XAMPP error, that’s a deprecated code error. Either update the code or downgrade PHP — but downgrading in 2026 is a bad idea for security.
On Linux and macOS, permissions bite hard. If Apache can’t read your files, PHP silently fails. Run sudo chmod -R 755 /opt/lampp/htdocs and make sure your user owns the files. Then restart with sudo /opt/lampp/lampp restart.
For Ubuntu and Debian users, install XAMPP by downloading from Apache Friends, running chmod +x xampp-linux-x64-installer.run, then sudo ./xampp-linux-x64-installer.run. Start services with sudo /opt/lampp/lampp start. If you skip that and try running it from the GUI, you’ll get weird permission errors that look like PHP bugs.
When to stop fixing and start over
If you’ve checked modules, ports, permissions, and MySQL, and it still fails, reinstall. Not because it’s elegant, but because a corrupted XAMPP install wastes more hours than a clean one. Back up htdocs and mysql/data, uninstall, grab the latest stable version, and drop your files back in.
The truth is that XAMPP PHP execution errors are rarely about PHP itself. They’re about Apache not knowing it should run PHP, a port already taken, or a file sitting in the wrong folder. Get those three right and you’ll spend your afternoon coding instead of cursing your local server.