I have been trying to develop web pages locally (in Windows 10) and running in my local browser (chrome, vivaldi). Right now I have 3 different ways to run simple servers locally: php's built in server, python's http.server module, and vscode's LiveServer. When I run the php server, I can execute php code properly, as one would expect. But calling php urls using the other two, I get a "Save File" dialog! Where is that coming from? Instead of a simple "not found" I get the dialog. So I have two questions: (1) Why am I getting the save file dialog? (2) Is it possible to process php files using LiveServer or python's http.server module (which I don't expect can ever support php)
2 Answers
if the save dialog is being shown it's cause the server can't interpret php code. You have to check these servers configs to check their integration with PHP (if they they can do that).

- 11
- 1
-
I had assumed that it couldn't interpret the file, but my question is: What is the logic that makes the browser open up a save dialog? – RufusVS Jun 07 '20 at 02:56
Good questions. Erick has answered the 1st one. I'll just elaborate more on it and then answer the 2nd one.
Why do you get save file dialog?
At a high level, a web server is serving files. When serving HTML/CSS/JS files to the browser, life is easy. Your browser understands HTML/CSS/JS and knows how to render it for the user. If your browser was sent unprocessed PHP file (assuming that file was present), the browser won't know what to do with <?php .. ?>
tags and such. So, the browser offers the user to download the file. Same thing with a zip file. If you went to http://someurl.com/abc.zip, if the webserver found that file under the root of someurl.com, it'll send it to the browser and the browser will offer the user to download it. There's more to it than just that.
So, how does a web server process PHP files? It depends on the web server, but the common thing is that they need help in processing PHP files. Web server is configured to send the request to php.exe or some other system such as PHP-FPM, which processes the file and returns back to the web server to send it to the user. Processing of the file converts echo "<div>$variable</div>";
to clean HTML <div>I am awesome</div>
. This processing system (php.exe or PHP-FPM) tag team with web server to serve to the browser what it can render.
Is it possible to cross-render languages?
Yes, you can in multiple ways. One of the common ways is to find the best processing system for the language of choice. For example, PHP can be processed with PHP-FPM running as a service. So, http://someurl.com/test/index.php could run through PHP-FPM. Python may use WSGI and you may choose gunicorn to process Python files. In that case, your webserver can be asked to send python-related directories/subdomains directly to gunicorn (essentially a proxy).
Reverse proxy
Let's say you have multiple sites with multiple language needs.
- http://py.someurl.com serves Python/Django
- http://someurl.com serves straight HTML
- http://ph.someurl.com services PHP
- http://js.someurl.com is powered by NodeJS
py.someurl.com could run on the server using gunicorn web server (or other wsgi-friendly servers) on port 8000. Node could be serving using Express web server on port 9000.
You could run NGINX server that serves straight HTML and also serves ph.someurl.com by sending requests to PHP-FPM service. It can also be configured to take all requests to js.someurl.com and hand it off to http://localhost:9000 where Node will service the request and send output back to NGINX and NGINX can send the request to the browser. Similarly, requests to py.someurl.com can be sent to localhost:8000 where gunicorn processes the request and sends the request back to NGINX, which forwards the request to the browser.
From a user's perspective, all they know is the NGINX server. All the other things in the background are known to NGINX. NGINX, in that case, serves as a web server and a proxy.

- 35,121
- 5
- 64
- 63
-
Thanks for this answer, and I'll probably start a new thread with my fundamental problem: When I run code with vscode's live server, my php files aren't being processed by the server. I did find live-server-web-extension during this process, which installs an extension in the browser for auto-reload. But still no php. – RufusVS Jun 08 '20 at 04:12
-
@RufusVS are you talking about https://github.com/ritwickdey/live-server-web-extension extension? If so, note this: https://github.com/ritwickdey/live-server-web-extension#the-common-misconception. My recommendation would be that you just set up NGINX, PHP-FPM, configure a site on NGINX and you'd be set for development. Yes, there may be some initial pain but there's long-term gain. – zedfoxus Jun 08 '20 at 04:14
-
I haven't looked into NGINX but have seen the name. So I gather I could install NGINX in my computer, and configure VSCODE to use NGINX for the live server? – RufusVS Jun 08 '20 at 04:33
-
You won't need live server. When you save your PHP file, click refresh in the browser and NGINX will reflect your changes. Are you on Windows, OSX or Linux? – zedfoxus Jun 08 '20 at 04:35
-
The beauty of the live server is the browser is auto-refreshed on every file save. I have already been doing the edit, save, move over to browser and click refresh routine with php's built-in browser and was trying to avoid the extra clicks. (Win10,Chrome, btw) – RufusVS Jun 08 '20 at 04:41
-
Got it. Open a new question with details of what you might want and someone might help you. The question may be suitable for SuperUser or ServerFault.com, but perhaps someone on StackOverflow might also be able to help out. – zedfoxus Jun 08 '20 at 04:46
-
[Done] (https://stackoverflow.com/questions/62255030/how-do-i-configure-vscode-live-server-to-process-php-files-properly-im-using-w?noredirect=1#comment110103238_62255030) – RufusVS Jun 08 '20 at 04:59