I used docker compose to stand up MariaDB and Apache web server in containers.
I'm using php7 with CentOS 7.2. I had to install "php70w-pecl-xdebug.x86_64". I also added the following the Dockerfile
RUN echo "xdebug.idekey = PHPSTORM" >> /etc/php.d/xdebug.ini &&
echo "xdebug.default_enable = 0" >> /etc/php.d/xdebug.ini &&
echo "xdebug.remote_enable = 1" >> /etc/php.d/xdebug.ini &&
echo "xdebug.remote_autostart = 0" >> /etc/php.d/xdebug.ini &&
echo "xdebug.remote_connect_back = 0" >> /etc/php.d/xdebug.ini &&
echo "xdebug.profiler_enable = 0" >> /etc/php.d/xdebug.ini &&
echo "xdebug.remote_host = 10.254.254.254" >> /etc/php.d/xdebug.ini
vesion: '2' services: web: build: . image: web expose: - "9000" ports: - "80:80" environment: PHP_XDEBUG_ENABLED: 1 XDEBUG_CONFIG: remote_host=10.254.254.254 volumes: - .:/app links: - db depends_on: - db
version 2017.1.2
Instead of having to worry about figuring the IP address of my laptop, I set up an alias: sudo ifconfig en0 alias 10.254.254.254 255.255.255.0
In PHP Storm, go to Preferences -> Languages & Frameworks -> PHP -> Servers. Add a server, named "localhost", set the port
whichever port Apache is listening on (80 in my case). Set the Debugger to "Xdebug". Check the "Use path mappings", and map the
source code from your laptop directory to the directory path in the container. Based on my docker-compose.yml
, I map the directory
where my source code is to /app
in the container, so I configure that in the "Use path mappings" section.
Next, in PHP Storm, go to Preferences -> Languages & Frmaeworks -> PHP -> Debug -> DBGp Proxy. Set IDE key to "PHPSTORM"
(this comes from the xdebug.idekey
setup in the Dockerfile), set Host to 10.254.254.254 and Port to 9000 (the port we exposed via docker-compse.yml).
Then, follow step 2 to begin listening for debug connections. Set some breakpoints in PHP Storm, load a page in your browser and you're all set!
thanks ^^