├── .docker
├── nginx
│ └── default.conf
└── php
│ └── Dockerfile
├── .gitignore
├── LICENSE
├── README.md
├── docker-compose.yml
└── src
└── index.php
/.docker/nginx/default.conf:
--------------------------------------------------------------------------------
1 | server {
2 | listen 80;
3 | listen 443 ssl;
4 |
5 | #ssl on;
6 | ssl_certificate /etc/nginx/ssl/server.pem;
7 | ssl_certificate_key /etc/nginx/ssl/server-key.pem;
8 |
9 | root /var/www/html;
10 | index index.php index.html index.html;
11 |
12 | server_name localhost;
13 |
14 | location / {
15 | try_files $uri $uri/ /index.php?$query_string;
16 | }
17 |
18 | location ~ \.php$ {
19 | try_files $uri /index.php =404;
20 | fastcgi_split_path_info ^(.+\.php)(/.+)$;
21 | fastcgi_pass php-srv:9000;
22 | fastcgi_index index.php;
23 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
24 | include fastcgi_params;
25 | #fastcgi_param PATH_INFO $fastcgi_path_info;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/.docker/php/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM php:7.3.7-fpm
2 |
3 | RUN apt-get update && apt-get install -y --no-install-recommends \
4 | autoconf \
5 | build-essential \
6 | apt-utils \
7 | zlib1g-dev \
8 | libzip-dev \
9 | unzip \
10 | zip \
11 | libmagick++-dev \
12 | libmagickwand-dev \
13 | libpq-dev \
14 | libfreetype6-dev \
15 | libjpeg62-turbo-dev \
16 | libpng-dev
17 |
18 | RUN docker-php-ext-configure gd \
19 | --with-png-dir=/usr/include/ \
20 | --with-jpeg-dir=/usr/include/ \
21 | --with-freetype-dir=/usr/include/
22 |
23 | RUN docker-php-ext-configure zip --with-libzip
24 |
25 | RUN docker-php-ext-install gd intl pdo_mysql pdo_pgsql mysqli zip \
26 | && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
27 |
28 | RUN pecl install imagick-3.4.3
29 |
30 | RUN pecl install xdebug && docker-php-ext-enable xdebug
31 |
32 | RUN docker-php-ext-enable imagick
33 |
34 | RUN curl -sS https://getcomposer.org/installer | php
35 | RUN mv composer.phar /usr/bin/composer
36 |
37 | WORKDIR /var/www/html
38 |
39 | EXPOSE 80
40 | EXPOSE 443
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .docker/db
2 | .docker/nginx/server.pem
3 | .docker/nginx/server-key.pem
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Willian Robert
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 | # Docker | Nginx | PHP 7.3.7 | Postgres | SSL
2 |
3 | ## Installation
4 |
5 | #### 1. Create a Self-Signed SSL Certificate
6 |
7 | Install Certutil
8 |
9 | - sudo apt install libnss3-tools -y
10 |
11 | Install mkcert
12 |
13 | - wget https://github.com/FiloSottile/mkcert/releases/download/v1.1.2/mkcert-v1.1.2-linux-amd64
14 | - mv mkcert-v1.1.2-linux-amd64 mkcert
15 | - chmod +x mkcert
16 | - sudo cp mkcert /usr/local/bin/
17 |
18 | Generate Local CA
19 |
20 | - mkcert -install
21 |
22 | Generate Local SSL Certificates
23 |
24 | - sudo mkcert example.com '\*.example.com' localhost 127.0.0.1 ::1
25 |
26 | Copy the certificate example.com+4.pem and key example.com+4-key.pem into folder .docker/nginx of your project.
27 |
28 | Rename these files to server.pem and server-key.pem and give the permission 644.
29 |
30 | - sudo chmod 644 server.pem
31 | - sudo chmod 644 server-key.pem
32 |
33 | References
34 |
35 | - https://github.com/FiloSottile/mkcert
36 |
37 | ---
38 |
39 | #### 2. Run Docker
40 |
41 | Start Server (in background)
42 |
43 | - docker-compose up -d
44 |
45 | Stop Server
46 |
47 | - docker-compose down
48 |
49 | Rebuild Server
50 |
51 | - docker-compose up -d --build
52 |
53 | ---
54 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 | services:
3 | php:
4 | build: .docker/php
5 | container_name: "php-srv"
6 | image: server-php-nginx
7 | volumes:
8 | - ./src:/var/www/html
9 | ports:
10 | - "9000:9000"
11 | restart: always
12 | networks:
13 | - mynetwork
14 |
15 | nginx:
16 | image: nginx
17 | container_name: "nginx-srv"
18 | volumes:
19 | - .docker/nginx/server.pem:/etc/nginx/ssl/server.pem
20 | - .docker/nginx/server-key.pem:/etc/nginx/ssl/server-key.pem
21 | - .docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
22 | - ./src:/var/www/html
23 | ports:
24 | - "80:80"
25 | - "443:443"
26 | restart: always
27 | networks:
28 | - mynetwork
29 |
30 | postgres:
31 | image: postgres:latest
32 | container_name: "postgres-srv"
33 | ports:
34 | - "5432:5432"
35 | volumes:
36 | - .docker/db:/var/lib/postgresql/data
37 | environment:
38 | POSTGRES_PASSWORD: "docker"
39 | restart: always
40 | networks:
41 | - mynetwork
42 |
43 | networks:
44 | mynetwork:
45 | driver: bridge
46 |
--------------------------------------------------------------------------------
/src/index.php:
--------------------------------------------------------------------------------
1 |