Debugging Remote PHP Codes on EC2 with PhpStorm and Xdebug

Debugging Remote PHP Codes on EC2 with PhpStorm and Xdebug

Takahiro Iwasa
(岩佐 孝浩)
Takahiro Iwasa (岩佐 孝浩)
2 min read
EC2 PHP PhpStorm

PHP codes running in remote EC2 instances can be debugged with PhpStorm and Xdebug.

Prerequisites

SoftwareVersion
PHP7.1.7
Apache2.2.32-1.9
PhpStorm2017.1.4

Settings

Server

Add Xdebug settings to php.ini and restart Apache by running sudo service httpd restart.

[xdebug]
zend_extension="/opt/remi/php71/root/usr/lib64/php/modules/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_host = "127.0.0.1"
xdebug.idekey = "IDE_KEY"
xdebug.remote_autostart=true

PhpStorm

Open Run > Edit Configurations..., then select PHP Remote Debug.

Click Servers, and add a target server running your WEB application based on the following configuration.

FieldValue
NameEC2 private IP
HostEC2 public IP
DebuggerXdebug
Use path mappingsON
Absolute path on the server/var/www/html/<YOUR_WEB_APP_ROOT>

Set the IDE key wrote in xdebug.idekey field in php.ini.

Router

If you use a network router, configure port mapping to allow incoming connections to port 9000 to be forwarded to your localhost.

Debugging

Put a breakpoint on any position and turn on Listen mode. After accessing the EC2 instance using WEB browsers, PhpStorm will stop at the breakpoint.

Takahiro Iwasa
(岩佐 孝浩)

Takahiro Iwasa (岩佐 孝浩)

Software Developer at iret, Inc.
Architecting and developing cloud native applications mainly with AWS. Japan AWS Top Engineers 2020-2023