├── .gitignore ├── README.md ├── docker-compose.yml ├── nginx ├── Dockerfile ├── vhost.conf └── vhost2.conf ├── php └── Dockerfile └── src ├── app └── .gitignore └── app2 └── .gitignore /.gitignore: -------------------------------------------------------------------------------- 1 | db-mysql/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Ambiente de desenvolvimento Docker com Nginx + PHP 7.3 e MySQL 3 | 4 | **Pré-requisitos:** Ter o Docker e Docker-compose instalados. 5 | 6 | 7 | [Instalando Docker no Windows 10](https://mundodacomputacaointegral.blogspot.com/2019/10/instalando-o-docker-no-windows.html) 8 | 9 | [Instalando Docker e Docker-compose no Linux (qualquer distro)](https://mundodacomputacaointegral.blogspot.com/2019/10/instalando-docker-e-docker-compose-no-Linux.html) 10 | 11 | Após ter instalado o Docker e Docker-compose, segue os procedimentos: 12 | 13 | 1. Fork do repositório 14 | 15 | 2. Clonar o repositório forkado 16 | 17 | 3. Acessar o diretório onde salvou o clone do repositório 18 | 19 | 4. Execute `docker-compose up -d` 20 | 21 | 5. Adicione no arquivo hosts 22 | 23 | **Windows:** _C:\Windows\System32\drivers\etc\hosts_ 24 | 25 | **Linux:** _/etc/hosts_ 26 | 27 | `127.0.0.1 app.local` 28 | 29 | `127.0.0.1 app2.local` 30 | 31 | 6. Acessar o container PHP para instalar o Laravel Framework 32 | `docker exec -it app bash` 33 | 34 | Dentro do container PHP, acessar no diretório _/var/www/html/app_ e execute 35 | 36 | `rm .gitignore` 37 | 38 | `composer create-project --prefer-dist laravel/laravel .` 39 | 40 | 7. No browser acesse [http://app.local](http://app.local) 41 | 42 | 8. Esse ambiente de desenvolvido inclui 2 Vhosts no Nginx de exemplo para 2 projetos, mas pode ter N vhosts, basta reutilizar o arquivo _vhost.conf_ para o novo arquivo, alterando o _server_name_ e adicionar no _Dockerfile_ do PHP. Lembrar de adicionar no arquivo hosts para cada Vhost do projeto. 43 | 44 | 9. No Linux para ter permissão no volume _src/app_ e _src/app2_, acessa até o diretório do ambiente e execute: 45 | 46 | `sudo chown -R $(whoami):$(whoami) src/app` 47 | 48 | `sudo chown -R $(whoami):$(whoami) src/app2` 49 | 50 | 10. No Laravel Framework precisa editar o _src/app/.env_ em _APP_NAME=_ para _app.local_ que nesse caso é o ServerName definido no Vhost. Para os demais Vhosts que houver também. 51 | 52 | Feito! 53 | 54 | 55 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | app: 5 | build: ./php 6 | container_name: app 7 | volumes: 8 | - ./src:/var/www/html 9 | depends_on: 10 | - app-mysql 11 | - app-redis 12 | 13 | app-mysql: 14 | image: mysql:5.7.22 15 | command: --innodb-use-native-aio=0 16 | restart: always 17 | ports: 18 | - "3306:3306" 19 | volumes: 20 | - "./db-mysql/dbdata:/var/lib/mysql" 21 | environment: 22 | - MYSQL_DATABASE= app 23 | - MYSQL_ROOT_PASSWORD= root 24 | 25 | app-redis: 26 | image: redis:alpine 27 | expose: 28 | - 6379 29 | 30 | app-nginx: 31 | build: ./nginx 32 | restart: always 33 | ports: 34 | - "80:80" 35 | volumes: 36 | - "./src:/var/www/html" 37 | depends_on: 38 | - app 39 | environment: 40 | VIRTUAL_HOST: app.local,app2.local 41 | -------------------------------------------------------------------------------- /nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.15.0-alpine 2 | RUN apk update && apk add bash 3 | 4 | RUN rm /etc/nginx/conf.d/default.conf 5 | COPY ./vhost.conf /etc/nginx/conf.d 6 | COPY ./vhost2.conf /etc/nginx/conf.d 7 | -------------------------------------------------------------------------------- /nginx/vhost.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | index index.php index.html; 4 | root /var/www/html/app/public; 5 | server_name app.local; 6 | 7 | location ~ \.php$ { 8 | try_files $uri =404; 9 | fastcgi_split_path_info ^(.+\.php)(./+)$; 10 | fastcgi_pass app:9000; 11 | fastcgi_index index.php; 12 | include fastcgi_params; 13 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 14 | fastcgi_param PATH_INFO $fastcgi_path_info; 15 | } 16 | 17 | location / { 18 | try_files $uri $uri/ /index.php?$query_string; 19 | gzip_static on; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /nginx/vhost2.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | index index.php index.html; 4 | root /var/www/html/app2/public; 5 | server_name app2.local; 6 | 7 | location ~ \.php$ { 8 | try_files $uri =404; 9 | fastcgi_split_path_info ^(.+\.php)(./+)$; 10 | fastcgi_pass app:9000; 11 | fastcgi_index index.php; 12 | include fastcgi_params; 13 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 14 | fastcgi_param PATH_INFO $fastcgi_path_info; 15 | } 16 | 17 | location / { 18 | try_files $uri $uri/ /index.php?$query_string; 19 | gzip_static on; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /php/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.3.6-fpm-alpine3.9 2 | RUN apk add --no-cache openssl bash nodejs npm 3 | RUN docker-php-ext-install pdo pdo_mysql bcmath 4 | 5 | # RUN rm -rf /var/www/html 6 | # RUN ln -s public /var/www/html/app 7 | 8 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 9 | 10 | WORKDIR /var/www/html 11 | 12 | EXPOSE 9000 13 | ENTRYPOINT ["php-fpm"] 14 | -------------------------------------------------------------------------------- /src/app/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rmsaitam/ambiente-nginx-php7.3-mysql/5480d2a9662a946d90acebf465b6ec916b7936d0/src/app/.gitignore -------------------------------------------------------------------------------- /src/app2/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rmsaitam/ambiente-nginx-php7.3-mysql/5480d2a9662a946d90acebf465b6ec916b7936d0/src/app2/.gitignore --------------------------------------------------------------------------------