I built an image that is based on a php:5.6-fpm-alpine image and I run a symfony-based application therefore I run both cli and web-based php scripts.
So I spawned a shell over my running container via:
docker exec -ti ^container_id^ /bin/sh
And over the shell I exported the following enviromental variables:
export PHP_IDE_CONFIG="serverName=0.0.0.0:5092"
export XDEBUG_CONFIG="idekey=PHPSTORM"
And the IDE has been setup as explained in the following links:
Can't connect PhpStorm with xdebug with Docker
How to setup Docker + PhpStorm + xdebug on Ubuntu 16.04
But when I enable the Xdebug on phpstorm even it debugs normally I get the following error message:
Do you know why that happens.
That happend because on Servers section of the phpstorm does not have the very same name as defined in the PHP_IDE_CONFIG enviromental variable in order to solve that follow these steps:
Step 1:
Go to server settings by pressing Ctrl+Alt+S or by visiting File -> Settings from the menu.
Step 2:
Then on the open window go to Settings -> Languages & Framework -> Servers.
Step 3:
Set the Name as the one defined into:
export PHP_IDE_CONFIG="serverName=0.0.0.0:5092"
In order to work it should be 0.0.0.0:5092 as the image shows:
Related
I upgraded to WSL2 from Windows 10.
With PhpStorm, in my project that I switched under my WSL, I try to launch PHPUnit. But I have this error :
Error in bootstrap script:
Symfony\Component\Dotenv\Exception\PathException: Unable to read the
"\WSL$\UBUNTU\home\toto\symfony\myProject/.env" environment file.
By looking in the parameters at the CLI Interpreter level, I saw that there was still my Windows config:
So, if the problem is there, I imagine that I have to make sure to take the PHP Executable from my WSL. Except that .. well impossible to find it
I have the file in usr/bin/php, or usr/bin/php7.4, but neither is accepted. And in \etc\php\7.4, I have these 3 folders:
But the same, there's nothing in it that can be accepted.
You are using a PHP interpreter of the Local type, while you need to use the WSL type. Here's what the UI looks like:
Click the + icon, choose From Docker, Vagrant, VM, WSL, Remote..., and choose WSL in there.
I would like to configure PHPStorm so that I can run Artisan commands directly from my IDE's terminal. For example php artisan key:generate. However, when I do, I receive the error 'php' is not recognized as an internal or external command.
Background:
running Windows 10 as host machine
using Docker to run my webserver (Nginx) and PHP interpreter (7.2-fpm).
I followed this tutorial.
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose.
One thing the tutorial didn't cover was how to set up my remote PHP CLI interpreter. For that, I followed https://www.jetbrains.com/help/phpstorm/configuring-remote-interpreters.html and can make a successful connection as it picks up the correct PHP version 7.2.21 as seen in the screenshot.
After this, I restarted my Windows 10 host machine, fired up the container, opened my IDE and tried to run php -v from the terminal but hit the error again.
I know it has something to do with my PATH environment variable being set incorrectly, or not at all but I am not sure how to point it to the container's PHP interpreter. Any help would be greatly appreciated.
EDIT
For what it is worth, I know that I can exec into the container and run PHP commands from there, but thought I might be able to do it directly from my host machine by pointing to the container's interpreter.
The terminal in PHPstorm is the same as any other terminal on your computer. It doesn't automatically connect to docker to run the php -v command. If you want to run php from PHPstorm in docker you can right click the file:
Choose run:
And select your created docker interpreter as your runtime:
If the fix button doesn't show it can be configured through:
settings > Languages & Frameworks > PHP
And then clicking on the 3 dots at the end of "CLI interpreter"
I am currently trying to debug my tests in PhpStorm with a docker-container as remote interpreter. The problem I am facing is that, though I can connect to the remote interpreter and execute my code on it, the container seems to be unaware of the other containers from the compose file. Unlike normally he is unable to connect to the database, which runs in another container (host=mysql).
Does anybody had the same issue before and found a solution?
Are you setting up your remote interpreter as Docker or Docker Compose?
In PhpStorm go to Preferences -> PHP -> CLI Interpreter -> ... and Check if you have Docker Compose or Docker section right under the name of Interpreter. If it's not Docker Compose, add a new Interpreter and make sure to chose Docker Compose for this one
My current setup involve PhpStorm IDE in which I have imported Symfony 3 projects which is basically CLI tool. On the host machine I don't have PHP installed so I'm running the application from Docker container which has PHP and Xdebug installed.
I don't have issues to debug web applications from Docker containers but with Symfony and this CLI tool it seems a little bit more tricky.
My question is how to properly set this up and debug it from PhpStorm? I tried to create a new debug configuration (PHP Remote Debug) but breakpoints are not trigged.
Suppossing you have followed into the instructions mentioned into the following links:
Can't connect PhpStorm with xdebug with Docker
How to setup Docker + PhpStorm + xdebug on Ubuntu 16.04
Or similar questions
Then you need to follow theese steps:
Step1:
Get shell access to your container via running:
docker exec -ti ^container_id^ /bin/sh
Or if running a debian/ubuntu based one (or you installed manually bash):
docker exec -ti ^container_id^ /bin/bash
The ^container_id^ can be found via docker ps command it is the first column of the table. If running on a small window just pipe int into less -S resulting the command:
docker ps | less -S
Then export the following enviromental variables:
export PHP_IDE_CONFIG="serverName=0.0.0.0:5092"
export XDEBUG_CONFIG="idekey=PHPSTORM"
Please keep in mind to setup the correct value specified into Servers section as you see in the image:
It is important in order not to run into the problem specified in this question.
Then just enable debugger listentin into the phpstorm and spawn the cli as you do when you run a symfony application.
I installed Git version 2.6.2.windows.1. After installing, any other programs in my PATH environment variable will display a flash console whenever I check their versions.
For example, from current pointer, I run "node -v" or "php --version" (both node & php are in PATH), the result which I got is a new console just flashes.
I think the content of any commands above are displayed in that console.
And in main console which I run command to check just like below:
This thing causes so many problems for me .
I tried to setup debug on my ide - phpstorm. But it seems not to recognize php version. Because the result is displayed in a new console and that console will be disappeared most immediately.
So could anybody help me fix this?
First, forget cygwin.
Then (for a Windows 64 bits), uncompress or install in path without spaces and in lowercase (so not the default C:\Program Files\..., but rather C:\prgs\git or C:\prgs\php for instance):
php-7.0.1-Win32-VC14-x64.zip
PortableGit-2.6.4-64-bit.7z.exe
node-v4.2.3-x64.msi (it is an installer, see "How to Install Node.jsĀ® and NPM on Windows", but use a simpler path like C:\prgs\node)
phpstorm (you already have it in your case)
In a brand new CMD session, type:
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Windows\system32
set PATH=%PATH%;c:\prgs\php\bin
set PATH=%PATH%;c:\prgs\git\nodejs
cd c:\path\to\phpstorm
PhpStorm.exe
In that new PhpStorm editor, configure the path of php, and see if the issue persists.