Skip to content

Laravel Docker to Development (Apple Silicon): Traefik + Nginx + Redis + PHP-FPM + MySQL + xDebug + Mailpit + RabbitMQ + OpenSearch + Varnish

License

Notifications You must be signed in to change notification settings

ityetti/laravel-docker

Repository files navigation

Laravel 2 Docker to Development (Apple Silicon)

Traefik + Nginx + Redis + PHP-FPM + MySQL + XDebug + Mailpit + RabbitMQ + OpenSearch + Varnish

The docker stack is composed of the following containers

Name Version
traefik 3.2
nginx 1.27
php-fpm 8.2
php-fpm-xdebug 3.2.2
redis 7.4
mysql 8.4.3
mailpit 1.21
rabbitmq 4.0.4
opensearch 2.18
opensearch-dashboard 2.18
varnish 7.6

Container traefik

Starts a reverse proxy and load balancer for project
Opens local port: 80, 443

Container nginx

Builds from the nginx folder.
Mounts the folder laravel from the project main folder into the container volume /home/laravel.

Container php-fpm

Builds from the php-fpm folder.
Mounts the folder laravel from the project main folder into the container volume /home/laravel.
This container includes all dependencies for Laravel.

Container php-fpm-xdebug

Builds from the php-fpm-xdebug folder.
Mounts the folder laravel from the project main folder into the container volume /home/laravel.
This container includes all dependencies for Laravel (also contain xDebug).

Container redis:

Starts a redis container.

Container mysql:

Please change or set the mysql environment variables

MYSQL_DATABASE: 'xxxx'
MYSQL_ROOT_PASSWORD: 'xxxx'
MYSQL_USER: 'xxxx'
MYSQL_PASSWORD: 'xxxx'
MYSQL_ALLOW_EMPTY_PASSWORD: 'xxxxx'

Default values:

MYSQL_DATABASE: 'laravel'
MYSQL_ROOT_PASSWORD: 'root_pass'
MYSQL_USER: 'laravel_user'
MYSQL_PASSWORD: 'PASSWD#'
MYSQL_ALLOW_EMPTY_PASSWORD: 'false'

Opens up port: 3306

Note: On your host, port 3306 might already be in use. So before running docker-compose.yml, under the docker-compose.yml's mysql section change the host's port number to something other than 3306, select any as long as that port is not already being used locally on your machine.

Container mailpit:

Starts a mailpit container.
Opens up port: 8025

Container rabbitmq:

Starts a rabbitmq container.
Opens up port: 15672

Container opensearch:

Starts an opensearch container.

Container opensearch-dashboard:

Starts an opensearch dashboard container.
Opens up port: 5601

Container varnish:

Builds from the varnish folder. Starts a varnish container.
Opens up port: 6081

Setup

Copy your .env.sample to .env file in root folder, and change PROJECT_NAME and PROJECT_VIRTUAL_HOST:
PROJECT_NAME - help you to create simple and clear container names.
PROJECT_VIRTUAL_HOST - it is your main url address.

For example:

PROJECT_NAME=laravel
PROJECT_VIRTUAL_HOST=laravel.test

Edit your /etc/hosts and add next line:
127.0.0.1 laravel.test traefik.laravel.test mail.laravel.test search.laravel.test dashboard.laravel.test rabbit.laravel.test

To start/build the stack.
Use - docker-compose up or docker-compose up -d to run the container on detached mode.
Compose will take some time to execute.
After the build has finished you can press the ctrl+c and docker-compose stop all containers.

Installing Laravel

To the run installation process use next commands.
Create and install new project:

./scripts/composer create-project laravel/laravel .
./scripts/npm install
./scripts/npm run build
./scripts/php artisan key:generate
./scripts/php artisan migrate

Setting up Laravel

To access the laravel homepage, go to the following url: https://laravel.test

Storing sessions and cache in redis.
As reference, you could use files from laravel_config folder.

Setting up vite.config.js (you need to add the correct server configuration).

   server: {
        host: 'nginx',
        port: 5175,
        https: true,
    },

Setting up the boot method in /app/Providers/AppServiceProvider.php (it is necessary for the correct use of HTTPS locally).

public function boot(): void
    {
        if (config('app.env') === 'local') {
            URL::forceScheme('https');
        }
    }

Don't forget to change the following parameters in the .env file of the Laravel app folder.

APP_URL=https://laravel.test
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD="PASSWD#"
REDIS_CLIENT=redis
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_HOST=mailpit

How to use xDebug

You could enable or disable xDebug with the next command: ./scripts/switch_mode [fpm|xdebug]
fpm - Enable container without xDebug
xdebug - Enable container with xDebug

Also, you can open:
https://traefik.laravel.test - Traefik Dashboard (traefik/traefik123 for access)
https://mail.laravel.test - Mailpit
https://search.laravel.test - OpenSearch
https://dashboard.laravel.test - OpenSearch Dashboard
https://rabbit.laravel.test - RabbitMQ (guest/guest for access)

Feature Updates

  • v1.0.0 - Initial release

Branches

Name Laravel
main 11.x

About

Laravel Docker to Development (Apple Silicon): Traefik + Nginx + Redis + PHP-FPM + MySQL + xDebug + Mailpit + RabbitMQ + OpenSearch + Varnish

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published