Chuyển đến nội dung chính

Xdebug, PhpStorm and Docker - Why it not working?

 


Lately, i start new job with Magento, and while setup IDE for project i face problem with Xdebug, PhpStorm and Docker. It took me a lot of hours to find out and make it work. So i write this post to save some step for you guys also me some way to solve the stuck when we got.


1. How Xdebug work:

Link i founded this article with quite easy understand explanation how xdebug work, so spend some minutes to read it, we need to understans the thing we do to easy to solve it.

2: Define Xdebug is installed on server:



With php -v you should see Xdebug showed.




And with phpinfo()


If you dont see it showed, it mean you have not installed it or it not enable

Checking if you have enable extension from your php ini.
Or if you have not installed it, consider its document: Link.

3. Now if you make sure xdebug installed but your break point at PhpStorm not break, continue these steps:


In phpinfo(), make sure xdebug.remote_enable is On cause you are using docker container, also checking xdebug.remote_host and xdebug.remote_port is right config your local machine.

ALso make sure you can curl host.docker.internal:9000,  If not, maybe your container dont understand that domain, sometime happend when using docker compose, so add host.docker.internal to your /etc/hosts map it with the docker network ip, you can try ifconfig on your local machine i similar here:

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:55ff:fee7:c69c  prefixlen 64  scopeid 0x20<link>
        ether 02:42:55:e7:c6:9c  txqueuelen 0  (Ethernet)
        RX packets 71293  bytes 5295130 (5.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 157731  bytes 357009921 (357.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Other way to debug is watching log, make sure when you request xdebug from browser or PhpStorm, it generate a log at that path, if you dont see the log, it mean you  xdebug cant connect  to your browser

xdebug.remote_log/tmp/xdebug.log

Make sure you dont add the folder you are debugging to exlusive, in my case with phpstorm, i added the vendor folder to exclusive so when i my debug step into that folder, it return 502 or blank page.


You can try to use php script to check xdebug working, it will generate script run directly from cli instead from browser.

[docker-compose://[/home/www/Sites/project/docker/docker-compose.override.yml]:phpfpm/]:php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=172.17.0.1 /var/www/html/bin/debug


And finally some config i use in php.ini:

xdebug.idekey = PHPSTORM
xdebug.client_port="9000"
xdebug.remote_log="/tmp/xdebug.log"
xdebug.remote_enable=1
xdebug.remote_host="host.docker.internal"

4. If you got error when use step over with phpstorm and xdebug, this is the answer:


It took me a lot of hours to find out. The issue is describe in these link:

To solve this issue: If on 2022.2, in Settings (Preferences) | PHP | Debug please disable Enable 'toString' object view.

Above is some steps i walk through to make my xdebug working with PhpStorm and Docker. Hope it can help you guys figure out your issue.

Thanks for your reading.

Nhận xét

Bài đăng phổ biến từ blog này

5 minute setup Firebase for .NET C#

  Step 1: - Access firebase console and create a project: - At the project you just created, go to Firestore Database and create a collection you want: - Next, go to the project setting: - At tab  Service account generate your private key. Step 2: - Create a C# project. - Use Nuget to install following packages: - Create folder to store private key. - Finally, the code to make everything run: using Google.Apis.Auth.OAuth2; using Google.Cloud.Firestore; using Google.Cloud.Firestore.V1; using Google.Cloud.Storage.V1; using Grpc.Auth; using Grpc.Core; using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; namespace FireBaseConnect {     class Program     {         static void Main(string[] args)         {             MyFireStore myfs = new MyFireStore();             myfs.GetLicense().Wait();         }...

Tổng hợp danh sách các trang web lấy backlink cực tốt (P.1)

Đi backlink  trong SEO là điều mà ai cũng phải biết và đầu tư cho nó nhiều nhất. Dưới đây, mình chia sẻ các trang web có thể đi backlink khá tốt cho mọi người. Mỗi ngày các bạn tạo 1 bài post sau đó post lên 10 trang trong tổng số 40 trang này, hôm sau cũng viết 1 bài khác rồi post lên 10 trang kế, khi hết thì quay vòng lại 10 trang đầu, mình sẽ update thêm các website nên các bạn cứ yên tâm không lo hết. (Các bạn nhớ bookmark lại kẻo quên trang mình nha :) ) Nếu các bạn không rõ về DA PA IN-EXTERNAL Links thì xem ở đây:  Các chỉ số quan trọng cần biết khi làm SEO ID URL DA PA Internal Links External Links Alexa Global Rank Alexa Local Rank 1 http://diendan.zing.vn/ 63,17 54,5 168 19 701 9 2 http://vatgia.com/ 62,61 57,34 984 23 8086 71 3 http://forum.ueh.edu.vn/ 49,82 38,88 555 43 92060 774 4 http://www.5giay.vn/ 47,12 55,72 445 ...