Is it possible for me to run Symfony web-server from the PhpStorm? I know I can run it from the command line:
php app/console server:run --env=dev
I just wonder if there is any way how to configure PhpStorm to do it for me.
Run -> Edit Configurations
+
(add)PHP Script
from the drop down listSymfony Web-Server
bin/console
eg: /path/to/symfony/bin/console
Activate Tool Window
to prevent it from popping up when startedserver:run
This will provide you with a Run Symfony Web-Server
and Debug Symfony Web-Server
option to select. To debug the running server, you must tell PHPStorm to listen for debug connections prior to running the server script. To configure debugging in your Settings -> Languages & Frameworks -> PHP -> Servers
ensure you have 127.0.0.1:8000
created, disable Path Mapping
and you have Xdebug set as the debugger. Optionally disable stop at first line in the Debug -> XDebug
settings.
Now you can start the server by selecting it in your Run configuration drop down, and clicking the Play button, or by clicking Run -> Symfony Web-Server
.
Be sure to tell PHPStorm to Listen for Debug connections first.
Add breakpoints, then launch your browser to a Route affected by the breakpoint(s) and PHPStorm should capture the debug session and break as desired.
If debugging fails at first, close all of the running PHPStorm services, and try running the Debug Symfony Web-Server
(ensuring that PHPStorm is listening for Debug Connections) and then re-launch your browser.
For some reason Xdebug may not initialize otherwise, but this behavior is sporadic and hard to reproduce consistently. After it initializes you can run the non-debug web-server while listening is enabled, and it seems to work fine.
Special note, running the
Debug Symfony Web-Server
will only monitor the bin/console script. This is because the Symfony server php process is forked and the debug session will be left monitoring the parent process. So you must tell PHPStorm to listen for debug connections when debugging the web server.
The Symfony Web-Server was added to the new Symfony CLI binary. To continue using the Symfony web server as a PHP Script, described above, you must install the symfony/web-server-bundle
compatible with your version of Symfony.
The
symfony/web-server-bundle
is depreciated as of Symfony 4.4 and will be removed in Syfmony 5.0
To set up the Symfony CLI web-server in PHPStorm, you can create an External Tool.
Program: symfony
Arguments: server:start --no-tls
Working Directory: $ProjectFileDir$
You can then run the command from your Tools menu.
Or you can execute it from a Run/Debug configuration, similarly to the Symfony WebServer Bundle configuration above, that instead executes the External Tool you created.
When running either of the above, you should get a new Run dialog CLI inside PHPStorm.
As the Symfony CLI web-server runs outside of the PHP script configuration, it does not suffer the random issues with X-Debug and PHPStorm not listening. I was unable to reproduce the issues in my testing.
However, PHPStorm requires that your server host be changed from http://localhost
to http://localhost:8000
for the X-Debug path mapping in PHPStorm to work.
If you do not update the host, PHPStorm will prompt you for the configuration when it encounters a break-point, just click Accept for a new server to be automatically added.
Result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With