2

As the title says, I'm trying to execute a PHP file on a localhost but it just downloads the file instead. I am using the npm package http-server. I have tried with SimpleHTTPServer from python, but it does the same thing.

I'm running MacOS Mojave. What should I do?

Emil E. Ohman
  • 153
  • 2
  • 11
  • https://www.npmjs.com/package/http-server I don't see anything about that node's http-server package will do execution of php – num8er Nov 19 '18 at 18:07
  • I mean you can, but you shouldn't; you can follow this guide http://promincproductions.com/blog/run-php-script-node-js/ – Hackerman Nov 19 '18 at 18:08
  • Possible duplicate of [PHP code is not being executed, instead code shows on the page](https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) – miken32 Nov 19 '18 at 18:17
  • Configuring php development machine like that would lead to lot confusions, try MAMP or LAMP packages from bitnami. Easy two configure, use and trash. – Ramesh Navi Nov 19 '18 at 18:20

1 Answers1

7

You can use PHP's Built-in Webserver with php -S 127.0.0.1:8080 if this is for development purposes.

Your core issue here is that you're assuming any webserver package will run PHP files, which isn't accurate.

You'll need a webserver with PHP integration or modules, such as NGINX with PHP-FPM, or Apache 2 with mod-cgi

Zachary Craig
  • 2,192
  • 4
  • 23
  • 34