Skip to content

Instantly share code, notes, and snippets.

@PokeGuys
Last active August 15, 2019 16:09
Show Gist options
  • Save PokeGuys/5b3c4eee3b2f189398918f5a81b696c1 to your computer and use it in GitHub Desktop.
Save PokeGuys/5b3c4eee3b2f189398918f5a81b696c1 to your computer and use it in GitHub Desktop.
LEMP with Swoole
version: '2'
services:
# The Application
app:
build: .
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
- "DB_MS_HOST=mssql"
- "DB_MS_USERNAME=sa"
- "CACHE_DRIVER=redis"
- "REDIS_HOST=cache"
command: php artisan swoole:http start
networks:
- backend
# The Web Server
web:
image: nginx
working_dir: /var/www
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:cached
volumes_from:
- app
ports:
- "8080:80"
networks:
- frontend
- backend
# The Database
database:
image: mysql:5.7
command: "--innodb_use_native_aio=0"
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "3306:3306"
networks:
- backend
# The Cache Server
cache:
image: redis:4.0
ports:
- "6379:6379"
networks:
- backend
# The Database
mssql:
image: microsoft/mssql-server-linux:latest
environment:
- "ACCEPT_EULA=Y"
- "SA_PASSWORD=YourNewStrong!Passw0rd"
ports:
- "1433:1433"
volumes:
- /var/opt/mssql
# we copy our scripts onto the container
- ./sql:/usr/src/app
# bash will be executed from that path, our scripts folder
working_dir: /usr/src/app
# run the entrypoint.sh that will import the data AND sqlserver
command: sh -c 'chmod +x ./entrypoint.sh; ./entrypoint.sh & /opt/mssql/bin/sqlservr;'
networks:
- backend
networks:
frontend:
driver: bridge
backend:
driver: bridge
FROM php:7.2.8-fpm
RUN apt-get update && apt-get install -my wget gnupg
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get update && apt-get -y --no-install-recommends install apt-transport-https
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN apt-get update && apt-get -y install unixodbc-dev
# Installing dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mysql-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Installing extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN pecl install sqlsrv pdo_sqlsrv swoole
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv swoole
# Installing composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Setting locales
RUN echo en_US.UTF-8 UTF-8 > /etc/locale.gen && locale-gen
# Allow container to write on host
RUN usermod -u 1000 www-data
gzip on;
gzip_min_length 1024;
gzip_comp_level 2;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml;
gzip_vary on;
gzip_disable "msie6";
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream swoole-http {
server app:1215;
}
server {
listen 80;
server_name your.domain.com;
root /path/to/laravel/public;
client_max_body_size 100M;
index index.php;
location = /index.php {
# Ensure that there is no such file named "not_exists"
# in your "public" directory.
try_files /not_exists @swoole;
}
location / {
try_files $uri $uri/ @swoole;
}
location @swoole {
set $suffix "";
if ($uri = /index.php) {
set $suffix "/";
}
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# IF https
# proxy_set_header HTTPS "on";
proxy_pass http://swoole-http$suffix;
}
}
gzip on;
gzip_min_length 1024;
gzip_comp_level 2;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml;
gzip_vary on;
gzip_disable "msie6";
server {
listen 80;
index index.php index.html;
root /var/www/public;
client_max_body_size 100M;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment