A Docker Compose workflow for start PHP scripts or Laravel project using Swoole without Laravel Octane and laravel Sail.
Ports used in the project:
Software | Port |
---|---|
phpmyadmin | 8083 |
mysql | 3306 |
swoole | 1215 |
redis | 6379 |
To get started, make sure you have Docker installed on your system and Docker Compose, and then clone this repository.
-
Go to something folder and clone this project:
git clone https://github.com/ErriourRU/docker-swoole-for-laravel.git ./
-
Copy file .env.example to .env and change data to own
-
Create or Put your laravel project in the folder.
-
Install laravel-swoole package and configure.
composer require swooletw/laravel-swoole php artisan vendor:publish --tag=laravel-swoole
You have to add following params to your laravel .env file:
SWOOLE_HTTP_HOST=0.0.0.0 SWOOLE_HTTP_WEBSOCKET=true
-
Temporary problem: laravel-swoole doesn't support OpenSwoole yet. To fix it, you should add this code to package manually: Added openswoole extension check compatibility #506
-
Build the project with the next commands:
docker-compose up --build -d
The configuration of the database must be the same on both sides .
# .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
DB_ROOT_PASSWORD=secret
# src/.env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
The only change is the DB_HOST
in the src/.env
where is called to the container of mysql
:
# src/.env
DB_HOST=mysql