├── LICENSE ├── README.md ├── docker-compose.yml ├── nginx └── default.conf └── php └── Dockerfile /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Gary Clarke 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nginx-php7.4-mysql8-node-docker-network 2 | Fast lightweight Docker network using PHP MySQL Nginx and Node 3 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | networks: 4 | nginx-php74-mysql8-node: 5 | 6 | services: 7 | 8 | # nginx 9 | nginx-service: 10 | image: nginx:stable-alpine 11 | container_name: nginx-container 12 | ports: 13 | - "8080:80" 14 | volumes: 15 | - ./app:/var/www/project 16 | - ./nginx/default.conf:/etc/nginx/conf.d/default.conf 17 | depends_on: 18 | - php74-service 19 | - mysql8-service 20 | networks: 21 | - nginx-php74-mysql8-node 22 | 23 | # php 24 | php74-service: 25 | build: 26 | context: . 27 | dockerfile: ./php/Dockerfile 28 | container_name: php74-container 29 | ports: 30 | - "9000:9000" 31 | volumes: 32 | - ./app:/var/www/project 33 | networks: 34 | - nginx-php74-mysql8-node 35 | 36 | # mysql 37 | mysql8-service: 38 | image: mysql:8 39 | container_name: mysql8-container 40 | ports: 41 | - "4306:3306" 42 | volumes: 43 | - ./mysql:/var/lib/mysql 44 | command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 45 | restart: always # always restart unless stopped manually 46 | environment: 47 | MYSQL_ROOT_PASSWORD: secret 48 | MYSQL_PASSWORD: secret 49 | networks: 50 | - nginx-php74-mysql8-node 51 | 52 | # node 53 | node-service: 54 | image: node:latest 55 | container_name: node-container 56 | volumes: 57 | - ./app:/var/www/project 58 | working_dir: /var/www/project 59 | networks: 60 | - nginx-php74-mysql8-node -------------------------------------------------------------------------------- /nginx/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | 3 | listen 80; 4 | index index.php; 5 | server_name localhost; 6 | root /var/www/project/public; 7 | error_log /var/log/nginx/project_error.log; 8 | access_log /var/log/nginx/project_access.log; 9 | 10 | location / { 11 | # try to serve file directly, fallback to index.php 12 | try_files $uri /index.php$is_args$args; 13 | } 14 | 15 | # optionally disable falling back to PHP script for the asset directories; 16 | # nginx will return a 404 error when files are not found instead of passing the 17 | # request to Symfony (improves performance but Symfony's 404 page is not displayed) 18 | # location /bundles { 19 | # try_files $uri =404; 20 | # } 21 | 22 | location ~ ^/index\.php(/|$) { 23 | 24 | # Sets the address of a FastCGI server. The address can be specified as a domain name or IP address, and a port 25 | # fastcgi_pass php:9000; 26 | fastcgi_pass php74-service:9000; 27 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 28 | include fastcgi_params; 29 | 30 | # optionally set the value of the environment variables used in the application 31 | # fastcgi_param APP_ENV prod; 32 | # fastcgi_param APP_SECRET ; 33 | # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"; 34 | 35 | # When you are using symlinks to link the document root to the 36 | # current version of your application, you should pass the real 37 | # application path instead of the path to the symlink to PHP 38 | # FPM. 39 | # Otherwise, PHP's OPcache may not properly detect changes to 40 | # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 41 | # for more information). 42 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 43 | fastcgi_param DOCUMENT_ROOT $realpath_root; 44 | 45 | # Avoid upstream sent too big header while reading error 46 | # https://stackoverflow.com/questions/17708152/nginx-overwrites-general-symfony-errors-with-502-bad-gateway 47 | fastcgi_buffer_size 128k; 48 | fastcgi_buffers 4 256k; 49 | fastcgi_busy_buffers_size 256k; 50 | 51 | # Prevents URIs that include the front controller. This will 404: 52 | # http://domain.tld/index.php/some-path 53 | # Remove the internal directive to allow URIs like this 54 | internal; 55 | } 56 | 57 | # return 404 for all other php files not matching the front controller 58 | # this prevents access to other php files you don't want to be accessible. 59 | location ~ \.php$ { 60 | return 404; 61 | } 62 | } -------------------------------------------------------------------------------- /php/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4-fpm 2 | 3 | RUN apt-get update && apt-get install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \ 4 | && docker-php-ext-install intl opcache pdo pdo_mysql \ 5 | && pecl install apcu \ 6 | && docker-php-ext-enable apcu \ 7 | && docker-php-ext-configure zip \ 8 | && docker-php-ext-install zip 9 | 10 | WORKDIR /var/www/project 11 | 12 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 13 | 14 | RUN curl -sS https://get.symfony.com/cli/installer | bash 15 | RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony --------------------------------------------------------------------------------