Debugging PHP Remotely on AWS EC2 with PhpStorm and Xdebug
This note describes how to debug PHP remotely using PhpStorm and Xdebug.
This note describes how to debug PHP remotely using PhpStorm and Xdebug.
Avoid debugging directly in production to prevent performance and security issues.
Server Configuration
Add the necessary Xdebug settings to the php.ini file:
[xdebug]zend_extension="/opt/remi/php71/root/usr/lib64/php/modules/xdebug.so"xdebug.remote_enable = 1xdebug.remote_connect_back = 1xdebug.remote_host = "127.0.0.1"xdebug.idekey = "IDE_KEY"xdebug.remote_autostart=trueRestart Apache by running:
sudo service httpd restartPhpStorm Configuration
Open Run > Edit Configurations... in PhpStorm, then select PHP Remote Debug.

Click Servers and add a target server with the following configuration:
- Name: Remote host private IP
- Host: Remote host public IP
- Debugger: Xdebug
- Use path mappings: ON
- Absolute path:
/var/www/html/<YOUR_WEB_APP_ROOT>

Set the IDE key you defined in the xdebug.idekey field of php.ini.

Port Forwarding
If you are using a network router, configure port mapping to allow incoming connections to port 9000 and forward them to your localhost.
Debugging
To start debugging:
- Place a breakpoint at the desired position in your PHP code.
- Enable Listen for PHP Debug Connections mode in PhpStorm.
- Access your remote server.
When the breakpoint is triggered, PhpStorm will pause execution, allowing you to inspect and debug the code.

Related posts
Connecting to EC2 with Session Manager (No SSH Required)
This note describes how to use Systems Manager - Session Manager.
Securely Accessing EC2 Windows Instances via SSH Port Forwarding
This note describes how to securely access an EC2 Windows instance in a private subnet through a bastion host in a public subnet.
Running Proxy.py as a Lightweight HTTP Proxy on EC2
This note describes how to set up Proxy.py, a lightweight HTTP proxy server, on an EC2 instance.
Sign in with Slack Using Cognito User Pools and OIDC
This note describes how to federate Cognito user pools with Slack using OIDC to implement "Sign in with Slack".
Deploying FastAPI on AWS Lambda with Lambda Web Adapter
This example guides you through the process of developing API backends with FastAPI using Lambda Web Adapter.
