Laravel Docker Xdebug



By default, Xdebug is already running and ready to accept connections. If you need to enable Xdebug on the CLI, execute the sudo phpenmod xdebug command within your Homestead virtual machine. Next, follow your IDE's instructions to enable debugging. Finally, configure your browser to trigger Xdebug with an extension or bookmarklet. Running specific PHP versions for Laravel can be quite useful, especially when working with legacy applications. I work on a range of different solutions with different versions of PHP and Laravel versions. To save me time reconfiguring my local environment’s PHP version and to better represent the live systems, I have opted for Docker based. If you are using Docker, Use these settings in your php.ini file: //php.ini XDebug xdebug.remoteenable = 1 xdebug.remoteautostart = 1 xdebug.remotehost = host.docker.internal xdebug.remoteport = 9001 As of Docker version 18.03, host.docker.internal points to host IP address on Mac / Windows. For Linux, you can use this workaround. I had a lot of trouble trying to install XDebug in the Laravel Sail docker container. Once I did, I had trouble customizing the service name (from laravel.test). I also noticed th.

Here I want to publish a simple yet functional setup for a dockerized app with Laravel backend and Vue.JS frontend.

What did I want?

  • Simple setup for development with docker-compose
  • With Laravel acting as pure backend
  • XDebug
  • Vue to take over all the frontend needs
  • Hot reload for the Vue app
  • No SSL in local development environment

What did I come up with?

Laravel Docker Phpstorm Xdebug

  1. Nginx acting as web trafic router, proxying to frontend or backend, depending on request URI
  2. Backend service: Laravel running artisan serve
  3. Frontend service: Vue-cli running npm run serve
Laravel Docker Xdebug

Directory/repository structure

Legend: d: directory, f: file

As you can see, this project itself mainly serves as an infrastructure project which connects our services and glues them all together. Developer may clone a single repo and work in it, if that’s sufficient. Normally, though, everyone would want to clone this infra repo and start docker-compose stack to have all the project services running locally.

Nginx router

docker-compose part:

Xdebug Php Docker

Laravel Docker Xdebug

…and the configuration, of course.

Backend

I added a Dockerfile for the backend, because official PHP images don’t include XDebug. Also, later on, I wanted to add redis extension:

And of course, we build this image using docker-compose, that is, we automate and simultaneously document this process with a declarative approach:

Laravel Docker Xdebug

The laravel app itself is beyond the scope of this post, I will simply assume it’s a standard app built with composer create-project laravel/laravel or alike.

Laravel Docker Xdebug

Take a note of the comment above the user: ${UID} directive

Frontend

Laravel Docker Xdebug

Docker Php Fpm Xdebug

Again, the Vue app itself is out of scope. I created mine with @vue/cli, using the vue-cli-service.

Laravel Docker Debug

Docker-compose:





Comments are closed.