Giter Site home page Giter Site logo

phponwindows's Introduction

PhpOnWindows

This is bridge from Windows to PHP installed under Windows Linux subsystem (Bash on Ubuntu on Windows) providing native integration for JetBrains IDEs, full XDebug support and simplicity for running PHP scripts.

NOTE: This project is proof of concept. Use in development environments only! Expect bugs when stepping outside of the happy path.

PhpStorm with debugging session running through PHP on Ubuntu on Windows

Prerequisites

Installation

  1. Clone this repository somewhere (e.g. C:\PhpOnWindows).

  2. Create file .php-path inside that directory. Write absolute path to your php.exe to that file. (e.g. echo C:\PHP\php.exe > C:\PhpOnWindows\.php-path)

Usage

  1. Use php.cmd script just as if it was your regular PHP executable.

Working directory is preserved. File paths in command arguments are mapped into /mnt/<drive>/ folder automatically.

Linux PHP executable running in Windows command line

Usage in JetBrains IDE

  1. Create new PHP configuration and set your php.cmd as PHP executable.

  2. That's it!

You should see that IDE reads configuration properly. XDebug, when installed, should work right now.

PhpStorm settings with path to php.cmd set

How it works?

User starts php.cmd batch.

Batch file starts Windows PHP process by running php-bridge.php script and passes to it all command line arguments.

Script starts bash.exe with arguments to run the PHP script inside the Linux. But before composing the command line passed to the Bash, following must be done:

  • Windows-like file path is mapped to Linux-like (basically C:\... gets mapped to /mnt/c/).

  • If XDebug settings are found inside command line arguments, XDebug "proxy" is started. As IDE and XDebug instance exchange file paths between each other, script takes care of file paths mapping as well.

Standard output and error output are preserved. Exit code returned by the script is preserved as well.

Troubleshooting

Open php.cmd file and set PHP_IN_BASH_LOGGING variable to 1. Then watch the script output during next run.

In case of problems just drop me a message, file an issue or create a pull request.

Contact

Michal Kočárek [email protected]https://twitter.com/michalkocarek

License

This library is licensed under the MIT License – see the LICENSE file for details.

phponwindows's People

Contributors

vassyli 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phponwindows's Issues

Unexpected token near `('

Hi,
i'm not sure if the thing i found is a bug or if it's my fault. I installed a new symfony project in the Linux subsystem and runned phpunit. It seems like that your script is working fine (if i run the php.cmd it looks alright), but if i try to run the default unittest in phpstorm it's aborting with this:

[.] Bash path: C:\Windows\System32\bash.exe
[.] CWD: C:\Users\muell\AppData\Local\lxss\home\Marvin\OwnWebProject\api\tests\AppBundle\Controller
[.] ENV:
[.] Input arguments: C:/Users/muell/AppData/Local/Temp/ide-phpunit.php --no-configuration --filter /::testIndex( .*)?$/ Tests\AppBundle\Controller\DefaultControllerTest C:\Users\muell\AppData\Local\lxss\home\Marvin\OwnWebProject\api\tests\AppBundle\Controller\DefaultControllerTest.php
[.] Linux arguments: /mnt/c/Users/muell/AppData/Local/Temp/ide-phpunit.php --no-configuration --filter /::testIndex( .*)?$/ Tests\AppBundle\Controller\DefaultControllerTest /mnt/c/Users/muell/AppData/Local/lxss/home/Marvin/OwnWebProject/api/tests/AppBundle/Controller/DefaultControllerTest.php
[.] Linux command: php /mnt/c/Users/muell/AppData/Local/Temp/ide-phpunit.php --no-configuration --filter /::testIndex( .*)?$/ Tests\AppBundle\Controller\DefaultControllerTest /mnt/c/Users/muell/AppData/Local/lxss/home/Marvin/OwnWebProject/api/tests/AppBundle/Controller/DefaultControllerTest.php
[.] Windows command: C:\Windows\System32\bash.exe -c "php /mnt/c/Users/muell/AppData/Local/Temp/ide-phpunit.php --no-configuration --filter /::testIndex( .*)?$/ Tests\AppBundle\Controller\DefaultControllerTest /mnt/c/Users/muell/AppData/Local/lxss/home/Marvin/OwnWebProject/api/tests/AppBundle/Controller/DefaultControllerTest.php"

/bin/bash: -c: line 0: syntax error near unexpected token (' /bin/bash: -c: line 0: php /mnt/c/Users/muell/AppData/Local/Temp/ide-phpunit.php --no-configuration --filter /::testIndex( .*)?$/ Tests\AppBundle\Controller\DefaultControllerTest /mnt/c/Users/muell/AppData/Local/lxss/home/Marvin/OwnWebProject/api/tests/AppBundle/Controller/DefaultControllerTest.php'

I'm pretty sure somewhere is the wrong character used, but i dont have any idea where.
On WIndows i'm using the latest php 7.1.6 without xdebug (i think it's not necessary), on Ubuntu 7.0.18 with xdebug, and symfony is in version 3.3.2.

I hope my english will not trigger you, but i'm a very bloody german without any languageskills except a few programming languages :D
Best regards from Karlsruhe ^^

PHP Inbuilt Server doesn't hit breakpoints

When using the inbuilt server option from PHP Storm, I can't hit breakpoints in my code.

image

This works if I switch PHPStorm to use the native Windows PHP version, but then I have all the weirdness of running PHP in Windows, which is why I found your great project.

Works incorrectly

Hello!
I use Windows 10 for main operations system and use bash for web development (php + apache + mysql), but in this way I can't use xdebug extension. I found the repository and tried to configurate xdebug with bash of windows 10. But finally I ran into a probleb: xdebug works incorrectly! When I start xdebug session, it ignore my breakpoints and stop process on the index files:
screenshot_2

How I setted xdebug:

  1. php.ini
    screenshot_1

  2. PHPStorm:
    screenshot_3

Could you please to help me with the issue?

PHP inbuilt server does not exit

Running PHP inbuilt server in PHPStorm through PhpOnWindows works great, but when the script ends, the server is left connected.

  1. Create a new PHP Storm project with single file: index.php
  2. Set up PhpOnWindows so that PHP CLI is using PhpOnWindows
  3. Create new Run Configuration of "In built server"
  4. Click the Play button: C:\php\PhpOnWindows\php.cmd -S localhost:8080 -t C:\Users\g105b\php-storm-test
  5. http://localhost:8080 shows index.php as expected
  6. Press the Stop button - Process finished with exit code 1
  7. http://localhost:8080 still shows index.php, and trying to do work on other projects is prevented until reboot.

Does not work

When I try to add the php.cmd as a new CLI Interpretor in PHPStorm the "Checking PHP Installation" window opens and does not finish at all. If I click the "Cancel" button, the window will close and all the fields will be filled. But "Open php.ini in Editor" give me an error. Please see screenshorts.
As a result, xdubug don't work. Could you help me?
error
error 2

PHP version: Not installed

I ran every test succesfull with php.cmd alias but when importing path of php.cmd into PHPStorm that's said : PHP version not installed.

sans-titre-1

phpunit does not get called properly

I'm currently trying to set up PhpStorm with Bash on Windows and PhpOnWindows which, at least for running basic commands, works great.

However, phpunit doesn't seem to get called properly - it exits simply with a Could not open input file error due to php-cli not finding the correct file.

bash.exe -c "php C:/Users/sauterb/bin/lotgd/core/vendor/phpunit/phpunit/phpunit --configuration C:\Users\sauterb\bin\lotgd\core\phpunit.xml --teamcity"
Could not open input file: C:/Users/sauterb/bin/lotgd/core/vendor/phpunit/phpunit/phpunit 

Obviously, this is due to the windows file path being in "unix style" using slashes instead of "windows style" with backslashes, thus the conversion seems to fail.

Unable to connect to 127.0.0.1:9000

This was working fine but all of a sudden iv started getting

fsockopen(): unable to connect to 127.0.0.1:9000 (No connection could be made because the target machine actively refused it.
) in C:\PhpOnWindows\php-bridge.php on line 199

Something must have changed but i cant see what?

PHPUnit fails if execute separate test method

Possible solution is to add quotes for param --filter in php-bridge.php:

unset($argument);

// For PHPUnit
for($i = 0; $i < count($arguments); $i++) {
	if($arguments[$i] == '--filter' && isset($arguments[$i+1])) {
		$arguments[$i+1] = "'" . $arguments[$i+1] . "'";
		break;
	}
}

dbg('Linux arguments: ' . implode(' ', $arguments));

Use "WSL" in github project title / description

Hi,
It might be an idea to put the term "WSL" in the project title or the description. Or even PHP WSL bridge or something. I had to install it on a new laptop and had a hard time finding it back on github.

Doesn't work without "sudo" on Windows 10 1803

Just workaround for the ones who's facing the issues like me.
Need to change php-bridge.php::150 line to
$linuxCmd = ($envValues ? $envValues . ' ' : '') . 'echo 1111 | sudo -S php ' . implode(' ', $arguments);$linuxCmd = ($envValues ? $envValues . ' ' : '') . 'echo YOUR_SU_PASSWORD sudo -S php ' . implode(' ', $arguments);

Script is slow every other request

Not sure what can be causing this one, but every other time I make a request to the PHP file in the example I get a normal response time, then the other time I get >300ms response time.

image

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.