diff --git a/README.md b/README.md index 4c86b6a..8643cdb 100644 --- a/README.md +++ b/README.md @@ -63,4 +63,38 @@ Creates a new PHP development environment and mounts your project files. > **Required?** ❌ > > Does not install a webserver (so no Nginx). Useful if you just need a PHP container to run -> unit tests or something. \ No newline at end of file +> unit tests or something. + +> #### Option: --disable-xdebug +> +> **Required?** ❌ +> +> Do not install XDebug in your environment. + +## XDebug Setup + +These instructions are for PHPStorm. I don't know about working with other IDE's, although they +should be fairly universal. + +### Server Settings + +- `File` -> `Settings` (`Preferences` on MacOS) +- `PHP` -> `Servers` -> `+` +- Give your "server" a name and use the values shown below. + +| Setting | Value | +|-------------------------|----------------------------------------------------------------------------------------------------------------| +| Host | 127.0.0.1 | +| Port | **Local** port **PHP** container is running on. i.e. if your docker container shows 52033:9003, use **52033**. | +| Debugger | Xdebug | +| Use path mappings? | ✅ | +| File/Directory | Select **your project root** | +| Absolute path on server | /var/www/html | + +### Remote Debugger + +- `Run` -> `Edit Configurations` +- `+` -> `PHP Remote Debug` +- Give it a name +- Use the server you created before +- Use **SPINNER** as IDE key \ No newline at end of file diff --git a/config/php-fpm/XDebug.Dockerfile b/config/php-fpm/XDebug.Dockerfile index cd28869..95fd859 100644 --- a/config/php-fpm/XDebug.Dockerfile +++ b/config/php-fpm/XDebug.Dockerfile @@ -1,6 +1,10 @@ -RUN pecl install xdebug redis \ - && docker-php-ext-enable redis +#RUN pecl install xdebug redis \ +# && docker-php-ext-enable redis +# +#COPY ./xdebug.ini.tmp "${PHP_INI_DIR}/conf.d/xdebug.ini" +#RUN docker-php-ext-install opcache > /dev/null +#COPY ./opcache.ini "${PHP_INI_DIR}/conf.d" -COPY ./xdebug.ini.tmp "${PHP_INI_DIR}/conf.d/xdebug.ini" -RUN docker-php-ext-install opcache > /dev/null -COPY ./opcache.ini "${PHP_INI_DIR}/conf.d" \ No newline at end of file +RUN pecl install xdebug + +COPY ./xdebug.ini "${PHP_INI_DIR}/conf.d/xdebug.ini" \ No newline at end of file diff --git a/config/php-fpm/xdebug.ini b/config/php-fpm/xdebug.ini new file mode 100644 index 0000000..d424487 --- /dev/null +++ b/config/php-fpm/xdebug.ini @@ -0,0 +1,8 @@ +[xdebug] +zend_extension=xdebug.so +xdebug.mode=debug,develop,coverage +xdebug.start_with_request=yes +xdebug.client_host=host.docker.internal +xdebug.client_port=9003 +xdebug.idekey=SPINNER +xdebug.log=/tmp/xdebug.log \ No newline at end of file diff --git a/config/spinner.yaml b/config/spinner.yaml index 8a6b2c3..d8cf155 100644 --- a/config/spinner.yaml +++ b/config/spinner.yaml @@ -2,6 +2,7 @@ options: environment: php: version: 8.4 + xdebug: true node: enabled: true version: 23 diff --git a/src/Classes/Config/Config.php b/src/Classes/Config/Config.php index 7a52b9d..1329e3c 100644 --- a/src/Classes/Config/Config.php +++ b/src/Classes/Config/Config.php @@ -71,6 +71,18 @@ class Config return $this->getEnvironmentOption('server', 'enabled'); } + /** + * @throws \Exception + */ + public function isXDebugEnabled(InputInterface $input): bool + { + if ($input->getOption('disable-xdebug')) { + return false; + } + + return $this->getEnvironmentOption('php', 'xdebug'); + } + /** * @throws \Exception */ @@ -126,6 +138,8 @@ class Config DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE), DataPathInterface::CONFIG_NGINX_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_NGINX_DOCKERFILE), 'nodeDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/Node.Dockerfile'), + 'xdebugIniTemplate' => new SpinnerFilePath('config/php-fpm/xdebug.ini'), + 'xdebugDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/XDebug.Dockerfile'), ]); } } \ No newline at end of file diff --git a/src/Classes/File/PHPDockerFileBuilder.php b/src/Classes/File/PHPDockerFileBuilder.php index 5018a7b..eb855ef 100644 --- a/src/Classes/File/PHPDockerFileBuilder.php +++ b/src/Classes/File/PHPDockerFileBuilder.php @@ -34,10 +34,20 @@ class PHPDockerFileBuilder extends AbstractFileBuilder $this->content = str_replace('${PHP_VERSION}', (string) $this->config->getPhpVersion($input), $this->content); if ($this->config->isNodeEnabled($input)) { - $this->content .= "\r\n\r\n" . file_get_contents($this->config->getFilePaths()->get('nodeDockerfileTemplate')->getAbsolutePath()); + $this->addNewLine(); + $this->content .= file_get_contents($this->config->getFilePaths()->get('nodeDockerfileTemplate')->getAbsolutePath()); $this->content = str_replace('${NODE_VERSION}', (string) $this->config->getNodeVersion($input), $this->content); } + if ($this->config->isXdebugEnabled($input)) { + $this->addNewLine(); + $this->content .= file_get_contents($this->config->getFilePaths()->get('xdebugDockerfileTemplate')->getAbsolutePath()); + file_put_contents( + (new SpinnerFilePath(sprintf('data/environments/%s/php-fpm/xdebug.ini', $input->getArgument('name'))))->getProvidedPath(), + file_get_contents($this->config->getFilePaths()->get('xdebugIniTemplate')->getAbsolutePath()) + ); + } + return $this; } diff --git a/src/Command/SpinCommand.php b/src/Command/SpinCommand.php index 7482801..8558719 100644 --- a/src/Command/SpinCommand.php +++ b/src/Command/SpinCommand.php @@ -59,6 +59,12 @@ class SpinCommand extends AbstractSpinnerCommand InputOption::VALUE_NONE, 'Set this flag to disable Node.js for your environment.' ) + ->addOption( + 'disable-xdebug', + null, + InputOption::VALUE_NONE, + 'Set this flag to disable XDebug for your environment.' + ) ->addOption('node', null, InputOption::VALUE_OPTIONAL, 'The Node.js version to use (e.g. 20).'); }