Skip to content

Add docker nginx & php-fpm #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/docker/README.md → src/Template/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@

## Included

- Nginx 1.23
- PHP-FPM 8.1
- PostgreSQL 13
- SQL Server 2019
- MySQL 5.7
- MailHog

## Setup

Copy `docker/` folder and `docker-compose.yaml` to your CodeIgniter4 project root.

```
CodeIgniter4/
├── app/
├── docker/ ... add
│   ├── nginx/
│   └── phpfpm/
├── docker-compose.yaml ... add
├── public/
```

Edit `docker-compose.yaml` to comment out unnecessary services.

## Usage

Create and start containers:
```
$ docker-compose up -d
```

Stop services:
```
$ docker-compose down
$ docker-compose stop
```

## Config
Expand Down Expand Up @@ -60,6 +80,7 @@ See https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker

```
database.default.hostname = localhost
#database.default.hostname = mysql
database.default.database = test
database.default.username = mysql
database.default.password = mysql
Expand All @@ -74,6 +95,7 @@ database.default.port = 3306
```
email.protocol = smtp
email.SMTPHost = localhost
#email.SMTPHost = mailhog
email.SMTPPort = 1025
email.SMTPCrypto =
email.fromEmail = [email protected]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
version: '3'

services:
nginx:
image: nginx:1.23
volumes:
- ./public/:/ci4proj/public
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"

phpfpm:
build:
context: ./docker/phpfpm/
dockerfile: ./Dockerfile
volumes:
- ./:/ci4proj

postgres:
image: postgres:13-alpine
ports:
Expand Down
45 changes: 45 additions & 0 deletions src/Template/docker/docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
server {
listen 80;
listen [::]:80;
server_name localhost;

root /ci4proj/public;
index index.php index.html index.htm;

#access_log /var/log/nginx/host.access.log main;

location / {
try_files $uri $uri/ /index.php$is_args$args;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass phpfpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
11 changes: 11 additions & 0 deletions src/Template/docker/docker/phpfpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM php:8.1-fpm
COPY php.ini /usr/local/etc/php/

COPY --from=composer:2.3 /usr/bin/composer /usr/bin/composer

RUN apt update && apt install -y libicu-dev libzip-dev \
&& docker-php-ext-install intl opcache mysqli \
&& docker-php-ext-configure zip && docker-php-ext-install zip \
&& pecl install apcu && docker-php-ext-enable apcu

WORKDIR /ci4proj
Loading