Newbie with a VSCode question. #150431
-
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
problem usually comes down to two things:
solution: -- Open the Correct Workspace Folder: -- Use the Proper JSON Settings:
If Using Workspace Variables: Absolute Paths (if needed):
-- File Execution vs. Downloading: -- Now restart the server : Now go to http://localhost:4000 in your browser after restarting PHP server from vs code. You should see your PHP files executed rather than simply listed or downloaded. |
Beta Was this translation helpful? Give feedback.
-
Hashir, I don’t know how to thank you.
I have been trying and re=trying all over, uninstalling and re-installing everything, not getting any help from anywhere, and all of a sudden, thanks to your detailed helps, it all works like a charm.
Just one more thing: the preview does not seem to auto update like Live Server does (just a minor problem to me), is that normal?
Thank you ever so much again.
Frankie.
From: Hashir Akbar ***@***.***>
Sent: 01 February 2025 05:57
To: community/community ***@***.***>
Cc: m6vmo ***@***.***>; Author ***@***.***>
Subject: Re: [community/community] Newbie with a VSCode question. (Discussion #150431)
problem usually comes down to two things:
1. How the PHP Server extension “sees” your workspace versus an absolute path: Many PHP server extensions (for example, the popular “PHP Server” extension in VS Code) expect the document root to be specified relative to your current workspace folder. If you try to give it an absolute path (like C:/Users/frank/sites) but your VS Code workspace isn’t actually set to C:/Users/frank, then the extension won’t be able to find your files.
2. Path formatting on Windows: In JSON you must either escape backslashes (i.e. use \) or use forward slashes. Not doing so can lead to “Invalid path” errors.
solution:
…-- Open the Correct Workspace Folder:
If your files are in C:\Users\frank\sites, then it’s best to open the folder C:\Users\frank as your VS Code workspace (or even better, open the sites folder itself if that’s your project). This way you can reference the document root using the built-in variable ${workspaceFolder}.
-- Use the Proper JSON Settings:
Here’s an example settings.json snippet that you might use (adjusting for your PHP executable path):
{
// If you’re using an extension like "PHP Server", you may need to set the path to your PHP executable:
"phpserver.phpPath": "C:/path/to/php.exe",
// Set the port you want the server to listen on:
"phpserver.port": 4000,
// Set the document root. If you opened C:\Users\frank as your workspace,
// then your sites folder is a subfolder, and you can reference it like this:
"phpserver.root": "${workspaceFolder}/sites",
// Set the relative path from that root to your starting file.
// If your index file is at the root of your sites folder, use "/":
"phpserver.relativePath": "/"
}
If Using Workspace Variables:
The ${workspaceFolder} variable is replaced by the folder you’ve opened in VS Code. So if you open C:\Users\frank, then ${workspaceFolder}/sites correctly points to C:\Users\frank\sites.
Absolute Paths (if needed):
If you prefer to use an absolute path (and your workspace isn’t set to include C:\Users\frank), then you must escape the backslashes. For example:
{
"phpserver.root": "C:\Users\frank\sites",
"phpserver.relativePath": "/",
"phpserver.port": 4000,
"phpserver.phpPath": "C:/path/to/php.exe"
}
-- File Execution vs. Downloading:
If clicking on your PHP files causes them to be downloaded rather than executed, it often means that the server isn’t processing them with PHP. Double-check that your PHP executable is correctly set in the settings (the "phpserver.phpPath" setting) and that your server extension is actually running PHP (and not just serving static files).
-- Now restart the server :
Now go to http://localhost:4000 in your browser after restarting PHP server from vs code. You should see your PHP files executed rather than simply listed or downloaded.
—
Reply to this email directly, view it on GitHub <#150431 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/BLAQGDDCVLTZONZH4QB2BOT2NRO3DAVCNFSM6AAAAABWIN4PYWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMBSGQYTQMY> .
You are receiving this because you authored the thread. <https://github.com/notifications/beacon/BLAQGDFRRCY3FZAQCQVAJCD2NRO3DA5CNFSM6AAAAABWIN4PYWWGG33NNVSW45C7OR4XAZNRIRUXGY3VONZWS33OINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAW54XO.gif> Message ID: ***@***.*** ***@***.***> >
|
Beta Was this translation helpful? Give feedback.
-
Oh, apologies, Hashir.
Of course I will accept it.
I am quite a newbie to Github.
Kind regards,
Frankie.
Oh, one more question if you don’t mind, if I am working on projects in a different folder, do I always have to change the settings in settings.json then? (Forgive my ignorance).
From: Hashir Akbar ***@***.***>
Sent: 01 February 2025 11:40
To: community/community ***@***.***>
Cc: m6vmo ***@***.***>; Author ***@***.***>
Subject: Re: [community/community] Newbie with a VSCode question. (Discussion #150431)
Yes, that's normal for many PHP server extensions. Unlike Live Server, which is designed with live-reloading in mind, some PHP server extensions don't automatically refresh the preview when files change. If auto-update (live reload) is important for your workflow, you might want to look into extensions that specifically support it or consider integrating a tool that provides live-reload functionality with your PHP development environment.
And in last if my answer was helpful can you accept it 😁
—
Reply to this email directly, view it on GitHub <#150431 (reply in thread)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/BLAQGDGNULZD4JIFADBGLA32NSXB5AVCNFSM6AAAAABWIN4PYWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMBSGU2DIOA> .
You are receiving this because you authored the thread. <https://github.com/notifications/beacon/BLAQGDFOHLHM4NTTNC2F6JD2NSXB5A5CNFSM6AAAAABWIN4PYWWGG33NNVSW45C7OR4XAZNRIRUXGY3VONZWS33OINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAW57GQ.gif> Message ID: ***@***.*** ***@***.***> >
|
Beta Was this translation helpful? Give feedback.
problem usually comes down to two things:
How the PHP Server extension “sees” your workspace versus an absolute path: Many PHP server extensions (for example, the popular “PHP Server” extension in VS Code) expect the document root to be specified relative to your current workspace folder. If you try to give it an absolute path (like C:/Users/frank/sites) but your VS Code workspace isn’t actually set to C:/Users/frank, then the extension won’t be able to find your files.
Path formatting on Windows: In JSON you must either escape backslashes (i.e. use \) or use forward slashes. Not doing so can lead to “Invalid path” errors.
solution:
-- Open the Correct Workspace Folder:
If your file…