# Prerequire:
- Install docker
- Any way to install laravel https://laravel.com/docs/8.x/installation
> Make sure you have the docker-compose.yml that generate by default

## generate docker file
Execute the following script will generate a dockerfile under root directory
```sh
php artisan sail:publish
```

## .env: add the following line

```
SAIL_XDEBUG_MODE=debug
```
> Set **off** if you don't want to run xdebug.

## chooese any version of php you want to debug
For example, I want to use php 8.1 for debug. So open the **php.ini** from **docker/8.1/** and append the following settings:
```
[XDebug]
zend_extension = xdebug.so
xdebug.start_with_request = yes
xdebug.discover_client_host = true
xdebug.idekey = VSC
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
```

## Run the laravel container
```sh
./vendor/bin/sail up -d --build
```

# For vscode

1. Install the extension of felixfbecker.php-debug
2. Copy the **launch.json** to .vscode/ to config the debug extesion
3. Set some break point and press F5 to start debuggin

# PhpStorm 
1. toolbar > run > Start listening for PHP debug connections
2. Open link http://localhost/ and the PHPStorm will pop up a window to let you setup Xdebug. All you need to do is click Accept button. Then setup finished.