Coder Social home page Coder Social logo

vscode-phpserver's Introduction

Buy Me a Coffee at ko-fi.com

Host / serve current workspace (or subfolder) with PHP.

demo

Getting started

There are multiple ways of running PHP server:

  • CTRL + SHIFT + P and searching for PHP Server: Serve project command
  • Clicking on vscode's editor button (icon on the top-right corner)
  • Right-clicking on vscode's editor when a .php or an .html is open.

To stop the server, the PHP Server: Stop project command can be executed likewise.

Commands

All commands can be executed by pressing CTRL + SHIFT + P and typing the name of the command.

Command Notes
PHP Server: Serve project
PHP Server: Stop project
PHP Server: Reload server Stops the running server and starts it again.
PHP Server: Open file in browser Quickly opens the URL of the active file in the browser. If the server is not running, this command will fail.

Settings

Setting Default Notes
phpserver.autoOpenOnReload true Enable/disable automatic opening of server's URL in the browser after server has been reloaded.
phpserver.browser null App used to open the server URL. If empty, it will use the default browser.
You can put any browser name here as long as it's installed in your machine (e.g. google-chrome, firefox, chromium-browser...)
phpserver.ip localhost Server's ip/hostname (e.g. localhost, 0.0.0.0...)
phpserver.phpConfigPath null Path to php.ini file. If empty, the extension uses the default path.
phpserver.phpPath null Path to PHP executable. If empty, the extension will try to get the path from the $PATH environment variable.
phpserver.port 3000 Server's port number.
phpserver.relativePath "." Path relative to project. This is useful when you want to serve a different folder than the one from current workspace.
phpserver.router null Path to custom router script that will be used by PHP server. Example.
If a custom router script is used on a Windows machine, there will be no console output unless a logger like this is included in the script.

Requirements

  • PHP needs to be installed in order to be able to use this extension.

Author

Brais Piñeiro

vscode-phpserver's People

Contributors

brapifra avatar dependabot[bot] avatar falahati avatar lalocespedes avatar venom-code avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vscode-phpserver's Issues

Serve project always from homepage setting + open browser

Is it possible to add a setting that when clicked on "Serve project" it would open homepage instead of current file from which PHP server has been initiated? Basically IP+port?

Plus when clicking on "Serve project" icon from top right icons https://monosnap.com/file/Vb57mTO8sLyVj7Gnx9PTuNGfwY2Cen# if the server is running, it could open the browser with new tab instead of simple error message "Server is already running". It's like, I know it does, it could just be simpler to go to browser with server tab open than searching in which tab I have it opened ;o) This could also be controled in settings. Not everyone need this.

Why does it always show this?

When I click the Server Project with Php Server, the Browser Show me this

404 Not Found
The requested resource / was not found on this server.

this is my PHP DEBUG 's launch.json
{
"name": "Xdebug",
"type": "php",
"request": "launch",
"port": 9000
}

this is my setting.json
"phpserver.browser":"edge",
"phpserver.port":3000

BUT i can use ApacheServer normally , so ,i wanna to know if there is any mistake with my setting.

THANKs!!!

Can not stop server

I installed this on mac.
I can start server by typing "Serve Project with PHP" or by clicking "Serve Project with PHP" in popup menu of vs code.
but I can't find "Stop PHP Server" from the Cmd+Shift+P or popup menu of editor.
How can I stop the server so that I can release the used port 3000?

No stop server command in mac

On mac there are only 3 options

  • serve project
  • open file in browser
  • reload server

Platform versions

  • MacOS 10.13.6
  • VS Code 1.26.0
  • PHP Server 2.4.4
  • PHP 7.2.8

using phpserver with Debug

Is there a way to debug php files served by phpserver plugin?
I have XDebug installed and set, php-debug extension in VSCode seems to be working too (when php file is run from the command line the breakpoints work), however when php code is run by phpserver, breakpoints do not break.
Are there some settings I am missing?
Thanks

PHP File Extension (Navigation Question)

I'm using your extension for work where we write a lot of internal links without the *.php extension (ex: "www.mysite.com/about" as opposed to "www.mysite.com/about.php"), which works on the live server. However, when hosting the site with your PHP server extension locally, it gives me the "file not found" page. Is there a setting that possibly supports this? Any help is greatly appreciated.

Alternate localhost

I think that you should be able to choose an alternate to localhost though a config option, with the default being "localhost". That way people can bind to a custom IP or hostname for the machine (like for those who can't alter the hosts file, then they could simply bind to 127.0.0.1 directly).

Unknown: failed to open stream: No such file or directory in Unknown on line 0

I am having a bit of trouble trying to get this extension to work. I'm New to coding so please excuse my ignorance. This was working about 4 or 5 months ago, but now I cant seem to figure it out.

I have my paths set as ""phpserver.phpPath": "C:/xampp/php/php.exe", and "phpserver.relativePath": "C:/xampp/htdocs",

I am not running xampp because I would like to replace it with this tool.

my terminal in vs code shows:
" "PHP Fatal error: Unknown: Failed opening required 'c:\Users********.vscode\extensions\brapifra.phpserver-2.4.6\src\logger.php' (include_path='C:\xampp\php\PEAR') in Unknown on line 0"

I don't have a logger.php file in my php folder, pear folder, htdocs, or in the src folder, do I need to create one?

I don't know what a router is but googling suggests a windows startup script I don't think I have any or at least any I set up myself. (It would be nice if the documentation was a bit more clear on where one would typically find such a file or even how a start up script would effect a plugin. Then again I am new so pardon my ignorance.)

I'm using windows 10. I was at one point able to get the error in #42 and #43. I have since uninstalled xampp and vs code, and made sure no configuration files remained. I then reinstalled xampp, vs code and this extension. I do have a new firewall, however I have the server ports set to allow in this range and the firewall itself is on ask to connect and I haven't blocked anything that was obviously this. Any help would be greatly appreciated this tool makes learning so much less tedious! Thank you for your hard work!

No console output with 1.1.0

Hello again :),

with the last update the console in vscode have no ouput and you cant stop the server with crtl + c (tested with 2 pc´s).

But i like the open browser feature, thanks !

Greetings

Error when starting the server

This is the error im getting:

Server error: Error: spawn php ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:229:19) at onErrorNT (internal/child_process.js:406:16) at process._tickCallback (internal/process/next_tick.js:63:19)

Server still running after stopping

Heya, I ran into an issue where the server is still running even though I uninstalled it.

I reinstalled PHP Server to stop it from serving files and it's somehow still able to serve the pages.

Is there a shortcut to open the currently worked on file in the browser?

Would like an "Open in browser" option which will open the current php file I'm working on in the current browser with the right url.

For example if I'm working on test.php I want to be able to right click, press "Open in browser", and have the webpage "localhost:3000/test.php" open up in my browser.

Opened browser before project files were parsed

The Serve Project command opened the browser before it had finished parsing my project and the browser was unable to connect. It took 15/20ish seconds to finish parsing the project. I didn't realize it was still parsing the files & thought the server had stopped working. Maybe it should wait to open the browser until the whole project has been parsed?

root-path ≠ current work directory on Multi-root Workspaces situation

On the Occasion : Multi-root Workspaces in Visual Studio Code ,It may not working correctly.Because vscode.workspace.rootPath corresponds to the first entry of workspaceFolders

Core API:
workspace.workspaceFolders access to all WorkspaceFolder (can be undefined when no workspace is opened!)
workspace.onDidChangeWorkspaceFolders be notified when WorkspaceFolder are added or removed
workspace.getWorkspaceFolder(uri)

So,To make it work, we can use workspace.getWorkspaceFolder(uri) to get the root-path instead.

Settings

Hi, I am not figuring out where to place the settings, I tried user and workspace and no go :) I would need to set a subfolder as root and change the port number. Thanks!

Content not refreshing

After serving my php page once, that version of the content is all that is ever served.

.htaccess not reading in

I have a project that i am maintaining and it is trying to processing html files as php files.
using the following line in the .htaccess file.
AddType application/x-httpd-php .html

If i set it up through apache it will work fine but when running through phpserver it treats it as an html file. Am i missing something?

Server not shutting down

Starts fine but will not shut down on right-click as indicated in your instructions. Only Stop PHP Server command works.

404 not found!

Hi friend your extn works well but i have a issue it works only for the first folder in workspace.... For other folders i got "404 not found" and missing characters how to fix it plz

Normal version of Chrome being selected instead of Chrome Dev despite focus

Hello,

To put this into context, basically, I would very much like to be able to tie the server, to starting only in Chrome Dev, as I have many other Chrome profiles open, in which I really don't want the server to start it.

In the past I solved this issue by focusing Chrome Dev so that the server would open inside of it upon reloading... however, for some reason currently, the server only opens in the normal version of Chrome, rather than the Dev, despite focusing it before reloading the server... (probably a Chrome Dev/Chrome update that ruined this somehow)

So yeah, could there perhaps be an implementation of an option, that ties the server to a specific Chrome version/browser directory?

Another live server extension, handles this beautifully where one can simply apply:

"liveServer.settings.AdvanceCustomBrowserCmdLine": "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --profile-directory=Profile 8",

Inside of the settings.json of VSCode

Thereby permanently tying a live server to an X browser/version/directory of it, instead of being stuck to something undesirable and largely inconvenient, as per one's custom setup

Kind regards.
Leo

router script addition

Thanks for the extension! Are you able to add in an additional parameter for a router script? (See https://secure.php.net/manual/en/features.commandline.webserver.php , Example 3) I tried to define a file within the relativePath parameter ( "relativePath": "foo .htrouter.php"), but the extension would immediately die everytime I tried to start the server, so for a workaround I have to start the server manually in the terminal instead.

Normally the command would look something similar like this: "php -S localhost:8000 -t foo/ .htrouter.php"

Thanks again.

Can't connect to localhost:3000

Hi there. I tried start the server and it open my browser with localhost:3000 url but then I get a "The connection with localhost was refused. ERR_CONNECTION_REFUSED" on Chrome. Any suggestions what would it be? I'm using the default configs, just changed the "phpserver.browser" to "chrome"

bump version to 1.1.1 to enable localhost / external binding

@brapifra could you push the latest version(bump to 1.1.0) in this repo to the vscode extension marketplace

so we can have the external binding functionality

i have manually copied the changes that exist on the master to my local extension folder and it works great.

but it would be nice to have the latest changes in the market place..

Running on windows

I'm trying to run this on windows but can't get the server to work.

I'm currently learning php and have a small web project in my hard drive. Opened VSCode to work on that project folder, selected one of the project's .php file to edit and used this extension to "start php server".
The message which tells you that the server has started up successfully and project is being served appeared. So far so good, then went into chrome to access this php file and all I see is the content, it's not getting run at all...

Probably I'm missing something really stupid but I can't get what it is :(. It would be good to find a small example on the docs or something like that to get started.

PHP version is 7.0, my OS is Windows 10, and I configured the settings.json to use Chrome as my web-browser with this VS extension. Any help appreciated.

Regards

Mysql support

Cant use mysqli.
"Fatal error: Uncaught Error: Call to undefined function mysqli_connect()"

Theres no php.ini file to import mysqli.

ZendFramework project issue

Hello,

i have an issue when i start the PHPServer in an Zendframework folder.

Microsoft Windows [Version 10.0.14393]                                                                                                                                                           
(c) 2016 Microsoft Corporation. All rights reserved.                                                                                                                                             

c:\Users\Malte\Desktop\untitled\public>php -S localhost:3000 -t c:\Users\Malte\Desktop\untitled\public/                                                                                          
Directory c:\Users\Malte\Desktop\untitled\public/ does not exist.                                                                                                                                

c:\Users\Malte\Desktop\untitled\public>     

The slash next to public make this error. Can you fix it ?

Hope you get it !

router is not work

the run() is execute in Server's constructor function, but setRouter() is not run at this time

PHP include code working oddly?

OK, with reference to closed issue #40. I have an update:

Using <!--#include virtual="./includes/footer.php" --> works on the live server (NOT VScode's Live server extension; the actual web server the site is stored on), but it doesn't' work on the localhost using vscode-phpserver extension.

HOWEVER
Using <?php include './includes/footer.php';?> works on localhost, using the vscode-phpserver, but not on the live server.

To get this to work on both I've added the footer twice, like so:

</section>
</main>
<!--#include virtual="./includes/footer.php" -->
<?php include './includes/footer.php'; ?>
</body>

On viewing the browser source code, the footer is only present once in each case, even though the actual HTML has both includes added, as shown above.

It's probably something to do with my system (Windows 10 Pro Insider), but I haven't a clue what could be causing this behaviour.

TIA

Can't run on other files than index.php

Hi,
whenever I click on "Start Project with PHP" it runs it on index.php and not on a file I want it to run. Is it possible to point it to a different file?
Thanks!

It shows this error please help

Server error: Error: spawn php ENOENT at _errnoException (util.js:1024:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19) at onErrorNT (internal/child_process.js:372:16) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)

White page

I get a white page if I run the server

Error displaying code in extension

its asking for php viewer and as well to change the server settings am Using Mamp server as my local host how to i change the default settings to the one in mamp.
screenshot 16

It opens Firefox instead of Firefox Nightly in macOS

Hola Brais,

The apps Firefox, Firefox Developer and Firefox Nightly have the same command name of 'firefox'. But it opens Firefox instead of Firefox Nightly.

I have already set 'firefox-nightly' to "phpserver.browser":, instead of firefox, but it doesn't open Firefox Nightly because the true command name of this app is 'firefox'.

¿Alguna solución?

¡Gracias!

Custom Server IP

I want to change the IP value from localhost to 127.0.0.1. I updated user settings like in the screenshot below:

screen shot 2017-09-28 at 9 24 02 pm

Please tell if this is fine or not because as soon as I make this change, I can't start the server. It starts and immediately stops automatically.

Option to hide context menus and start button

I have a minor request which is annoying me when working with non-php projects and files.

There is always the PHP menus in the right click context menu and the serve project button on the top right. As workaround I modified the package.json to remove the menus. I can still access the PHP commands using the Ctrl+Shift+P menu.

Would it be possible to add an option to hide the context menu options and the button without hacking on the package.json?

Time server error

I'm having error related to time. applications such as wordpress have expired links error.
How can I configure server time?

thanks

The requested resource / was not found on this server.

Installed the plugin and have left it with the default settings. However whenever I select "Serve project with PHP" it opens http://localhost:3000 and I see a page showing:

Not Found
The requested resource / was not found on this server.

Where is it getting the "/" value from? Shouldn't it open the file I have selected in the editor?

How to enable auto open in localhost?

If I understood everything right, after serving the project with PHP server, the page should open automatically in a browser with this setting?

How should I do that? I am running VS Code on Mac OS High Sierra.

Thanks

Error opening server

I receive this error:

Server error: Error: spawn php ENOENT
at _errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

Is it any way to solve this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.