live-server-web-extension
live-server-web-extension copied to clipboard
PHP downloading instead of executing
I'm a new to this live server thing but for .html it worked perfectly fine! But now when I want to use it for .php it want's me to download it instead of executing it. How can I fix it? I'm using Firefox and my settings.json is:
`{ "liveServer.settings.useWebExt": true,
"liveServer.settings.proxy": {
"enable": true,
"baseUri": "/src",
"proxyUri": "http://127.0.0.1:80"
},
"liveServer.settings.CustomBrowser": "firefox",
}`
Ok Ok! I got you! You're on wrong track!
Can I know the actual address of you PHP project when you're not using Live Server? eg: http://localhost:80/php/
?
If I assume this => http://localhost:80/php/
Now, open VSCODE.
setup settings
"liveServer.settings.proxy": {
"enable": true,
"baseUri": "/",
"proxyUri": "http://localhost:80/php/"
},
"liveServer.settings.CustomBrowser": "firefox",
(assume live server
starts with port 5500)
if baseUri
is /
, http://127.0.0.1:5500/ will be mapped with http://localhost:80/php/.
if baseUri
is /scr
, http://127.0.0.1:5500/src/ will be mapped with http://localhost:80/php/.
if baseUri
is /foo
, http://127.0.0.1:5500/foo/ will be mapped with http://localhost:80/php/.
Hopefully, you got it
Sorry, still don't get it with that baseUri, does that mean I still have to keep my project files in /var/www?
Ok! Let me know what is your actual PHP URL ..!!!
BTW, set baseUri as /
always.
Hi @chomik-pawel , If it is still confusing you, follow the Direct Setup. It is now more easy & straight-forward way. [ v1.0.0 update is required]
[It is now available on Chrome Web Store]
Hi, I tried using the Direct Setup, but I am getting the same problem. I am not quite understanding what value should in the "Actual Server Address" field. Do I need my site running on a different server besides VSC Live Server?
Here is what I did, exactly:
1- created a folder on my Desktop named "myPoject", and placed an index.php inside of it.
2- opened "myProject" with VSC, and served it with Live Server on port 5500. And Chrome automatically opens on http://127.0.0.1:5500/
, where I get the list of the files on the server(index.php). If I click on index.php, it downloads automatically.
My Live Server Extension Settings are the following: Actual Server Address: http://127.0.0.1:5500 Live Server Address: http://localhost:5500/
Please let me know what I might be doing wrong, and I am excited about your extension. Thanks.
Hi @aalcindo, Live Server will not able to compile your PHP code - That's why php is downloading....
Suppose you don't have Live Server. Now how you can view the PHP code in browser? -> This is the actual server address
I've mentioned here. @aalcindo
I Eventually got it to work. For anybody who doesn't understand how to do it, I agree the documentation uses vague terms like "Now at the Actual Server add http://localhost/php/ (assuming your actual server is http://localhost/php/)" which doesn't exactly explain HOW to add??? or what does "add" mean when it comes to a server.
So this is how I got it to work:
Suppose you have a PHP project in your local wamp/xamp and the project is in a folder called "top5" You normally access it at this address: http://127.0.0.1/top5/
Now you want to make it live reload. Assuming you have installed the liveserver extension in visualstudio code and the browser extension in your browser, you should activate the browser extension and DO NOT CHECK "I don't want proxy setup" because we actually want proxy setup for live reload of php projects. Just enable it by clicking the live reload button on the extension.
Now. inside your project, you should have a .vscode folder and a settings.json file
The settings.json file should have this content
{
"liveServer.settings.useWebExt": true,
"liveServer.settings.proxy": {
"enable": true,
"baseUri": "/",
"proxyUri": "http://127.0.0.1/top5/"
},
}
You are all set. now if you go to visualstudio code and click the "Go Live" button on the blue bar at the bottom, you should see your browser open http://127.0.0.1:5500 and you will see your project. Reloading after php changes is now working.
** The firewall may ask for permission, so please allow that. Good luck.
Thank you for the plugin ritwickdey! A video tutorial would help a lot of people.
I am sorry for the documentation. I'v opened a new issue request here #4
A draft video tutorial https://www.youtube.com/watch?v=54wcX1G2GH8
@ritwickdey Thank you, that should help a lot of people. Awesome functionality! Thanks again!
Hi, I have a similar but different problem. I create virtual hosts for individual projects (e.g. http://test1.dev, http://test2.dev, etc.), but for some reason the live server always loads the localhost. I assumed that I need to change the proxyUri in settings.json, which I did to "http://test1.dev", but I get the same result (browser loads localhost). What am I doing wrong?
Turn off proxy setup!
Normal start live server form your workspace (lets assume the port is '5500')
If the Live Server Web Extension pop-up menu, Actual address => http://test1.dev LiveServer Address => http://localhost:5500
Stay on http://test1.dev/ ... hit refresh for a single time. From next time, the window will reload automatically.
https://github.com/ritwickdey/live-server-web-extension/blob/master/docs/Setup.md#direct-setup
Thanks for the quick reply, Ritwick. I forgot one detail! When I turn off the proxy setup and do as you describe, it goes to the right address (to virtual host), but PHP does not compile and I get a directory listing. That's why I originally thought this question belongs in this thread. :)
Here are my settings in settings.json and in the Chrome extension:
"liveServer.settings.donotShowInfoMsg": true, "liveServer.settings.useWebExt": true, "liveServer.settings.CustomBrowser": "chrome",
Actual address => http://test1.dev LiveServer Address => http://127.0.0.1:5500
Yes!!
Start live server.. and say on http://test1.dev (hit refresh for a single time)
And made some changes, it will reload the page where http://test1.dev page is opened.
Stay**
Does the site already need to be loaded on the browser? The updates seem to work fine that way, but when I launch chrome through the "Go Live" button on the status bar, it still gives me a directory listing even though I have already set the chrome extension to the actual server. If that is true, I guess for updating PHP it is better to set "liveServer.settings.NoBrowser": true, is that correct?
I think, you're missing my point.. just start live server... & don't browse live server's address. (If it's opening a new tab, just close ta tab)
After setting up , live server web extension, open a new tab for http://test1.dev.... (don't browse localhost:5500)
I think we are saying similar things...unless I am still missing something. So when "Go Live" button on the status bar launches a new browser window, I should just close it since the launched window will not parse PHP code? Isn't that what you mean by "if it opens a new tab, just close the tab?"
Yes! Close the tab. That server is used to send a feedback to web extension when you made any changes in your workspace.
After getting feedback, web extension will refresh tha page accordingly...
--- this is the working principal :smile:
Sounds good. Thanks.
Is this working on your machine?
Yes, it works as long as the live server is started and I physically type in the virtual host domain "test1.dev" into the browser window. I guess I was confused because I thought the browser window that opens after clicking the "Go Live" button would parse the PHP code. What I will do from now on is when the window opens to "http://127.0.0.1:5500," I will just type in the domain "test1.dev" and load the page again.
Yes! I understand! I don't know how I can make clear others about this.
If you like to contribute a tutorial or great documentation or update the extension code you're always welcome https://github.com/ritwickdey/live-server-web-extension/issues/4 .
Anyway, thanks for the feedback!
Please leave a review if you like the small extension https://chrome.google.com/webstore/detail/live-server-web-extension/fiegdmejfepffgpnejdinekhfieaogmj/reviews
I just left you a review! I can't think of a clear way to explain it, either, but thanks for helping me get it set up. :) Great work on the extension by the way! :)
Hi @ritwickdey is there any way to get this working for .html.liquid
files?
Hi guys so... I fixed the problem partly... it's no longer asking me to download a file (.php) but it doesn't auto refresh either... what do I do?
--copied the settings in settings.json
actually I forgot to add extension... :/
This is AWESOME man! may you live long and prosper!