Skip to content

Commit a171f0d

Browse files
author
workoverflow@ya.ru
committed
Init commit
0 parents  commit a171f0d

File tree

10 files changed

+707
-0
lines changed

10 files changed

+707
-0
lines changed

Dockerfile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
FROM php:7.4-fpm-alpine AS app
2+
3+
# Define config vars
4+
ENV APP_ENV=dev
5+
6+
ENV SYS_NGINX_DIR=/etc/nginx \
7+
SYS_PHP_DIR=/etc/php/7.4/ \
8+
SUPERVISOR_CONFIG=docker-config/supervisord/supervisord.conf \
9+
NGINX_CONFIG=docker-config/nginx/nginx.conf \
10+
HOST_CONFIG=docker-config/nginx/conf.d/default.conf \
11+
PHP_CONFIG=docker-config/php/${APP_ENV}.ini \
12+
FPM_CONFIG=docker-config/php/fpm.conf
13+
14+
RUN apk update && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
15+
curl \
16+
wget \
17+
git \
18+
nginx \
19+
supervisor \
20+
bzip2-dev \
21+
libxml2-dev \
22+
imagemagick-dev \
23+
freetype \
24+
freetype-dev \
25+
jpeg-dev \
26+
libjpeg-turbo-dev \
27+
libpng \
28+
libpng-dev \
29+
libmcrypt-dev \
30+
zlib-dev \
31+
libzip-dev \
32+
yaml-dev \
33+
tzdata \
34+
icu-dev \
35+
&& pecl install mcrypt-1.0.3 \
36+
&& pecl install redis-5.1.1 \
37+
&& pecl install xdebug-2.9.0 \
38+
&& pecl install apcu \
39+
&& pecl install zip-1.15.5 \
40+
&& rm -rf /tmp/pear \
41+
&& rm -rf ${SYS_NGINX_DIR}/sites-enabled/* ${SYS_NGINX_DIR}/sites-available/* \
42+
&& mkdir -p /var/log/supervisor
43+
44+
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime && echo "Europe/Moscow" > /etc/timezone \
45+
&& apk del tzdata \
46+
&& docker-php-ext-install -j$(nproc) bz2 mysqli pdo_mysql sockets \
47+
&& docker-php-ext-configure gd \
48+
--with-freetype \
49+
--with-jpeg \
50+
&& docker-php-ext-configure opcache --enable-opcache \
51+
&& docker-php-ext-install -j$(nproc) gd \
52+
&& docker-php-ext-install intl \
53+
&& docker-php-ext-configure intl \
54+
&& docker-php-ext-enable bz2 mysqli gd pdo_mysql mcrypt redis xdebug intl opcache apcu sockets zip
55+
56+
# Install composer
57+
COPY --from=composer /usr/bin/composer /usr/bin/composer
58+
59+
COPY . /var/www/html
60+
WORKDIR /var/www/html
61+
62+
# Copy configs
63+
COPY docker-config/supervisord/supervisord.conf /etc/supervisord.conf
64+
COPY docker-config/nginx/nginx.conf /etc/nginx/nginx.conf
65+
COPY docker-config/nginx/conf.d/default.conf ${SYS_NGINX_DIR}/conf.d/default.conf
66+
COPY docker-config/php/${APP_ENV}.ini /usr/local/etc/php/php.ini
67+
COPY docker-config/php/fpm.conf /usr/local/etc/php-fpm.d/www.conf
68+
69+
# Cleanup before start
70+
RUN mkdir /run/nginx && mkdir /run/supervisord
71+
72+
WORKDIR /var/www/html/app
73+
74+
EXPOSE 80
75+
76+
ENTRYPOINT ["/usr/bin/supervisord", "--pidfile=/run/supervisord/supervisord.pid"]

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Docker enviroment for PHP projects
2+
3+
Docker container with NGINX + PHP 7.4-FPM
4+
Ready for Symfony 5
5+
6+
**How to use?**
7+
8+
1. Clone this repository
9+
10+
```bash
11+
git clone https://github.com/Workoverflow/docker-php-env.git
12+
```
13+
14+
2. Use docker-compose or docker run
15+
16+
17+
```bash
18+
docker-compose build
19+
docker-compose up -d
20+
```
21+
22+
OR
23+
24+
```bash
25+
docker build -t php-app:latest .
26+
docker run -d -p 80:80 --name=php_app php-app:latest
27+
```
28+
29+
3. Check php info in your browser. Visit http://localhost/
30+
31+
32+
4. Attach to container
33+
34+
```bash
35+
docker-compose exec app sh
36+
```
37+
38+
OR
39+
40+
```bash
41+
doocker exec -it php_app /bin/sh
42+
```
43+
44+
5. Remove default *app* folder
45+
46+
```bash
47+
cd .. && rm -rf app
48+
```
49+
50+
6. Create new Symfony 5 project or use other framework
51+
52+
```bash
53+
composer create-project symfony/website-skeleton app
54+
```
55+
56+
7. Refresh http://localhost/

app/public/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
phpinfo();

docker-compose.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2'
2+
services:
3+
app:
4+
build: .
5+
restart: always
6+
ports:
7+
- "80:80"
8+
volumes:
9+
- ./app:/var/www/html/app
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
server {
2+
server_name app.local;
3+
index index.php index.html;
4+
error_log /var/log/nginx/error.log;
5+
access_log /var/log/nginx/access.log;
6+
root /var/www/html/app/public;
7+
8+
location / {
9+
try_files $uri /index.php$is_args$args;
10+
}
11+
12+
location ~ \.php$ {
13+
try_files $uri =404;
14+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
15+
fastcgi_pass 127.0.0.1:9000;
16+
fastcgi_index index.php;
17+
include fastcgi_params;
18+
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
19+
fastcgi_param DOCUMENT_ROOT $realpath_root;
20+
fastcgi_param PATH_INFO $fastcgi_path_info;
21+
}
22+
}

docker-config/nginx/nginx.conf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
user www-data;
2+
worker_processes 1;
3+
4+
error_log /var/log/nginx/error.log warn;
5+
pid /run/nginx/nginx.pid;
6+
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /var/log/nginx/access.log main;
22+
23+
sendfile on;
24+
client_max_body_size 200M;
25+
#tcp_nopush on;
26+
27+
keepalive_timeout 65;
28+
29+
#gzip on;
30+
31+
include /etc/nginx/conf.d/*.conf;
32+
}

docker-config/php/dev.ini

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; error_reporting = E_ERROR & ~E_NOTICE & ~E_WARNING
2+
error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING
3+
display_errors = On
4+
display_startup_errors = On
5+
memory_limit = 512M
6+
max_execution_time = 300
7+
8+
realpath_cache_size=4096K
9+
realpath_cache_ttl=600
10+
11+
[Opcache]
12+
opcache.enable=1
13+
opcache.memory_consumption=256
14+
opcache.interned_strings_buffer=16
15+
opcache.max_accelerated_files=20000
16+
opcache.validate_timestamps=1
17+
opcache.max_wasted_percentage=10
18+
opcache.revalidate_freq=0
19+
opcache.fast_shutdown=1
20+
opcache.enable_cli=1
21+
22+
[Session]
23+
24+
; After this number of seconds, stored data will be seen as 'garbage' and
25+
; cleaned up by the garbage collection process.
26+
; http://php.net/session.gc-maxlifetime
27+
; Custom: 3 days
28+
session.gc_maxlifetime = 259200
29+
30+
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
31+
; http://php.net/session.cookie-lifetime
32+
; Custom: 3 days
33+
session.cookie_lifetime = 259200
34+
35+
[Date]
36+
date.timezone = "Europe/Moscow"
37+
38+
[File Uploads]
39+
file_uploads = On
40+
upload_max_filesize = 200M
41+
max_file_uploads = 10

0 commit comments

Comments
 (0)