├── .gitignore ├── docker ├── php │ ├── php-ini-overrides.ini │ ├── supervisord.conf │ └── Dockerfile └── nginx │ ├── conf │ └── nginx.conf │ └── conf.d │ └── default.conf ├── README.md └── docker-compose.yml /.gitignore: -------------------------------------------------------------------------------- 1 | app/ 2 | .env 3 | .DS_Store 4 | .vscode 5 | -------------------------------------------------------------------------------- /docker/php/php-ini-overrides.ini: -------------------------------------------------------------------------------- 1 | upload_max_filesize = 100M 2 | post_max_size = 108M 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Laravel 8 + PHP Swoole with Docker Compose 2 | 3 | Laravel + PHP Swoole in Supervisor 4 | 5 | ## YAML 6 | 7 | - NGINX (latest) 8 | - PHP-FPM (7.4) 9 | 10 | ## Usage 11 | 12 | build & start 13 | ``` 14 | sudo docker-compose up -d --build 15 | ``` 16 | 17 | remove 18 | ``` 19 | sudo docker-compose down 20 | ``` 21 | 22 | remove everything (volumes, images, etc.) 23 | ``` 24 | sudo docker-compose down --rmi all -v --remove-orphans 25 | ``` 26 | 27 | ## License 28 | 29 | The Laravel Swoole Docker is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). 30 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.1" 2 | services: 3 | nginx: 4 | image: nginx:alpine 5 | container_name: my-nginx 6 | working_dir: /app 7 | volumes: 8 | - ./app:/app 9 | - ./docker/nginx/conf/nginx.conf:/etc/nginx/conf/nginx.conf:ro 10 | - ./docker/nginx/conf.d:/etc/nginx/conf.d:ro 11 | ports: 12 | - "80:80" # HTTP 13 | 14 | php: 15 | build: docker/php 16 | container_name: my-php 17 | working_dir: /app 18 | volumes: 19 | # Change directory name to your project name. Example "./app/YOUR_DIRECTORY_NAME:/app" 20 | - ./app/laravel-swoole-tutorial:/app 21 | - ./docker/php/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini 22 | ports: 23 | - "1215:1215" # Swoole port 24 | # - "9000:9000" # PHP-FPM port 25 | -------------------------------------------------------------------------------- /docker/php/supervisord.conf: -------------------------------------------------------------------------------- 1 | # [program:php-fpm] 2 | # command=/usr/local/sbin/php-fpm 3 | # numprocs=1 4 | # autostart=true 5 | # autorestart=true 6 | # priority=100 7 | 8 | [program:laravel-worker] 9 | process_name=%(program_name)s_%(process_num)02d 10 | command=php /app/laravel-swoole-tutorial/artisan queue:work --sleep=3 --tries=3 --max-time=3600 11 | autostart=true 12 | autorestart=true 13 | stopasgroup=true 14 | killasgroup=true 15 | numprocs=8 16 | redirect_stderr=true 17 | stopwaitsecs=3600 18 | 19 | [program:swoole] 20 | command=php /app/laravel-swoole-tutorial/artisan swoole:http start 21 | redirect_stderr=true 22 | autostart=true 23 | autorestart=true 24 | numprocs=1 25 | process_name=%(program_name)s_%(process_num)s 26 | stdout_logfile=/app/laravel-swoole-tutorial/storage/logs/swoole_http.log -------------------------------------------------------------------------------- /docker/php/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4-fpm 2 | WORKDIR "/app" 3 | 4 | # Fix debconf warnings upon build 5 | ARG DEBIAN_FRONTEND=noninteractive 6 | RUN apt-get update && apt-get install -y --no-install-recommends apt-utils 7 | 8 | # Update packages & Install Git and Supervisor 9 | RUN apt-get update -y && \ 10 | apt-get install -yq git supervisor 11 | 12 | # Install GD extension 13 | RUN docker-php-ext-configure gd --with-freetype --with-jpeg 14 | RUN docker-php-ext-install -j "$(nproc)" gd 15 | 16 | # Install Swoole extension 17 | RUN pecl install swoole 18 | RUN docker-php-ext-enable swoole 19 | 20 | # Install Composer 21 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 22 | 23 | # Added supervisor config 24 | COPY supervisord.conf /etc/supervisor/conf.d/supervisor.conf 25 | CMD ["/usr/bin/supervisord", "-n"] 26 | -------------------------------------------------------------------------------- /docker/nginx/conf/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes auto; 2 | 3 | daemon off; 4 | 5 | events { 6 | worker_connections 1024; 7 | } 8 | 9 | error_log /var/log/nginx/error.log warn; 10 | pid /var/run/nginx.pid; 11 | 12 | http { 13 | include /etc/nginx/conf/mime.types; 14 | 15 | default_type application/octet-stream; 16 | 17 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 18 | '$status $body_bytes_sent "$http_referer" ' 19 | '"$http_user_agent" "$http_x_forwarded_for"'; 20 | 21 | access_log /var/log/nginx/access.log main; 22 | 23 | sendfile on; 24 | #tcp_nopush on; 25 | keepalive_timeout 65; 26 | 27 | client_max_body_size 108M; 28 | 29 | gzip on; 30 | gzip_disable "msie6"; 31 | gzip_vary on; 32 | gzip_proxied any; 33 | gzip_comp_level 6; 34 | gzip_buffers 16 8k; 35 | gzip_http_version 1.1; 36 | gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 37 | # tells the server to use on-the-fly gzip compression. 38 | 39 | include /etc/nginx/conf.d/*.conf; 40 | } -------------------------------------------------------------------------------- /docker/nginx/conf.d/default.conf: -------------------------------------------------------------------------------- 1 | # Swoole configuration 2 | upstream swoole-http { 3 | server php-fpm:1215; 4 | } 5 | map $http_upgrade $connection_upgrade { 6 | default upgrade; 7 | '' close; 8 | } 9 | 10 | # PHP-FPM 11 | # server { 12 | # listen 80 default; 13 | 14 | # root /app/laravel-swoole-tutorial/public; 15 | # index index.php; 16 | # location / { 17 | # # Redirect everything that isn't a real file to index.php 18 | # try_files $uri $uri/ /index.php$is_args$args; 19 | # } 20 | # location ~ \.php$ { 21 | # include fastcgi_params; 22 | # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 23 | # fastcgi_pass php-fpm:9000; 24 | # try_files $uri =404; 25 | # } 26 | # location ~ /\.(ht|svn|git) { 27 | # deny all; 28 | # } 29 | # } 30 | 31 | # Laravel Swoole 32 | server { 33 | listen 80 default; 34 | 35 | root /app/laravel-swoole-tutorial/public; 36 | index index.php; 37 | 38 | add_header X-Frame-Options "SAMEORIGIN"; 39 | add_header X-XSS-Protection "1; mode=block"; 40 | add_header X-Content-Type-Options "nosniff"; 41 | 42 | ## Swoole configuration 43 | location = /index.php { 44 | # Ensure that there is no such file named "not_exists" 45 | # in your "public" directory. 46 | try_files /not_exists @swoole; 47 | } 48 | 49 | location / { 50 | try_files $uri $uri/ @swoole; 51 | } 52 | 53 | location @swoole { 54 | set $suffix ""; 55 | 56 | if ($uri = /index.php) { 57 | set $suffix ?$query_string; 58 | } 59 | 60 | proxy_http_version 1.1; 61 | proxy_set_header Host $http_host; 62 | proxy_set_header Scheme $scheme; 63 | proxy_set_header SERVER_PORT $server_port; 64 | proxy_set_header REMOTE_ADDR $remote_addr; 65 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 66 | proxy_set_header Upgrade $http_upgrade; 67 | proxy_set_header Connection $connection_upgrade; 68 | 69 | # IF https 70 | # proxy_set_header HTTPS "on"; 71 | 72 | proxy_pass http://swoole-http$suffix; 73 | } 74 | } 75 | --------------------------------------------------------------------------------