Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP downloading instead of executing #3

Open
chomik-pawel opened this issue Oct 24, 2017 · 36 comments
Open

PHP downloading instead of executing #3

chomik-pawel opened this issue Oct 24, 2017 · 36 comments
Labels

Comments

@chomik-pawel
Copy link

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",

}`

@ritwickdey
Copy link
Owner

ritwickdey commented Oct 24, 2017

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

@chomik-pawel
Copy link
Author

Sorry, still don't get it with that baseUri, does that mean I still have to keep my project files in /var/www?

@ritwickdey
Copy link
Owner

Ok! Let me know what is your actual PHP URL ..!!!

BTW, set baseUri as / always.

@ritwickdey
Copy link
Owner

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]

@aalcindo
Copy link

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.

@ritwickdey
Copy link
Owner

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

@ritwickdey
Copy link
Owner

I've mentioned here. @aalcindo

image

@CristianEnache
Copy link

CristianEnache commented Oct 31, 2017

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.

@ritwickdey
Copy link
Owner

I am sorry for the documentation. I'v opened a new issue request here #4

@ritwickdey
Copy link
Owner

A draft video tutorial https://www.youtube.com/watch?v=54wcX1G2GH8

@CristianEnache
Copy link

@ritwickdey Thank you, that should help a lot of people. Awesome functionality! Thanks again!

@petersykim
Copy link

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?

@ritwickdey
Copy link
Owner

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.

@petersykim
Copy link

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. :)

@petersykim
Copy link

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

@ritwickdey
Copy link
Owner

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.

@ritwickdey
Copy link
Owner

Stay**

@petersykim
Copy link

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?

@ritwickdey
Copy link
Owner

ritwickdey commented Jan 29, 2018

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)

@petersykim
Copy link

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?"

@ritwickdey
Copy link
Owner

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 😄

@petersykim
Copy link

Sounds good. Thanks.

@ritwickdey
Copy link
Owner

Is this working on your machine?

@petersykim
Copy link

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.

@ritwickdey
Copy link
Owner

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 #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

@petersykim
Copy link

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! :)

@kevprice83
Copy link

Hi @ritwickdey is there any way to get this working for .html.liquid files?

@Aleksandar-jocic
Copy link

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

@Aleksandar-jocic
Copy link

actually I forgot to add extension... :/

This is AWESOME man! may you live long and prosper!

@ghost
Copy link

ghost commented Dec 12, 2018

still not working 👎 with extension or without extension, for the php i am using brackets for long time lol, gg, this is the bug coming from Apache i think that is the reason it's not working i don't know what is doing vscode thay have to fix this bug to debug, compile and code in every platform, any extension is not useful BTW code is not running so what is use of extension. for php

@unkilling
Copy link

Hi all
Interesting post.
I have a question. The live server works fine with PHP file but since it works, CSS and JS file aren't update anymore. If I change php extension by html, everything is refreshing fine.
Any idea how to fix it ? Is it possible live server to work with all files (html, php, css, js, and so on ...) ?
Thanks by advance for your help

@unkilling
Copy link

Me again, i found the solution finally.

You must add :

"liveServer.settings.useWebExt":true

to your settings.json then all works fine ;)

@theiqbalpk
Copy link

please check this video tutorial. thanks
https://youtu.be/2RsapQV9OLg

@Luizgpp
Copy link

Luizgpp commented May 17, 2019

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

This is the best asnwer! Thanks!

@marif0025
Copy link

The Basic setup work form me. I am using VS code, Live reload Extension (for browser and for vscode) and xampp server for php execution.

Thanks for all your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests