Skip to content

Commit f1a6cf0

Browse files
committed
Upgrade for support PHP 8.1, split php and nginx containers
1 parent 6380e43 commit f1a6cf0

File tree

11 files changed

+56
-70
lines changed

11 files changed

+56
-70
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Docker enviroment for PHP projects
22

33
Docker container with NGINX + PHP 8.1-FPM
4-
Ready for Symfony 6
4+
Ready for Symfony 6 and Laravel 9
55

66
**How to use?**
77

@@ -15,8 +15,8 @@ Ready for Symfony 6
1515

1616

1717
```bash
18-
docker-compose build
19-
docker-compose up -d
18+
docker compose build
19+
docker compose up -d
2020
```
2121

2222
OR
@@ -32,7 +32,7 @@ Ready for Symfony 6
3232
4. Attach to container
3333

3434
```bash
35-
docker-compose exec app sh
35+
docker compose exec php sh
3636
```
3737

3838
OR
@@ -47,7 +47,7 @@ Ready for Symfony 6
4747
cd .. && rm -rf app
4848
```
4949

50-
6. Create new Symfony 5 project or use other framework
50+
6. Create new Symfony 6 project or use other framework
5151

5252
```bash
5353
composer create-project symfony/website-skeleton app

docker-compose.yaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
version: '2'
1+
version: '3'
22
services:
3-
app:
4-
build: .
5-
restart: always
3+
nginx:
4+
build:
5+
context: .
6+
dockerfile: ./docker/images/nginx/Dockerfile
7+
container_name: nginx
68
ports:
79
- "80:80"
10+
- "443:443"
11+
volumes:
12+
- ./app:/var/www/app:delegated
13+
- ./storage/logs/nginx:/var/log/nginx
14+
- ./docker/config/nginx/nginx.conf:/etc/nginx/nginx.conf
15+
- ./docker/config/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
16+
links:
17+
- php
18+
php:
19+
build:
20+
context: .
21+
dockerfile: ./docker/images/php/Dockerfile
22+
args: [ "APP_ENV=dev" ]
23+
container_name: php
24+
restart: always
25+
ports:
26+
- "9000:9000"
827
volumes:
9-
- ./app:/var/www/html/app
28+
- ./app:/var/www/app:delegated
29+
environment:
30+
- APP_ENV=dev

docker-config/supervisord/supervisord.conf

Lines changed: 0 additions & 26 deletions
This file was deleted.

docker-config/nginx/conf.d/default.conf renamed to docker/config/nginx/conf.d/default.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ server {
33
index index.php index.html;
44
error_log /var/log/nginx/error.log;
55
access_log /var/log/nginx/access.log;
6-
root /var/www/html/app/public;
6+
root /var/www/app/public;
77

88
location / {
99
try_files $uri /index.php$is_args$args;
@@ -12,7 +12,7 @@ server {
1212
location ~ \.php$ {
1313
try_files $uri =404;
1414
fastcgi_split_path_info ^(.+\.php)(/.+)$;
15-
fastcgi_pass 127.0.0.1:9000;
15+
fastcgi_pass php:9000;
1616
fastcgi_index index.php;
1717
include fastcgi_params;
1818
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;

docker-config/nginx/nginx.conf renamed to docker/config/nginx/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ user www-data;
22
worker_processes 1;
33

44
error_log /var/log/nginx/error.log warn;
5-
pid /run/nginx/nginx.pid;
5+
pid /run/nginx.pid;
66

77

88
events {
File renamed without changes.
File renamed without changes.
File renamed without changes.

docker/images/nginx/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM nginx:latest AS nginx
2+
3+
ENV SYS_NGINX_DIR=/etc/nginx
4+
5+
RUN rm -rf ${SYS_NGINX_DIR}/sites-enabled/* ${SYS_NGINX_DIR}/sites-available/* /var/www/*
6+
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime && echo "Europe/Moscow" > /etc/timezone
7+
8+
# Define working directory.
9+
WORKDIR /etc/nginx
Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
FROM php:8.1-fpm-alpine AS app
1+
FROM php:8.1-fpm-alpine AS php
22

33
# Define config vars
4-
ENV APP_ENV=dev
5-
ENV SYS_NGINX_DIR=/etc/nginx
4+
ARG APP_ENV=dev
65

76
RUN apk update && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
87
curl \
98
wget \
109
git \
11-
nginx \
12-
supervisor \
1310
bzip2-dev \
1411
libxml2-dev \
1512
imagemagick-dev \
@@ -20,20 +17,18 @@ RUN apk update && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
2017
libpng \
2118
libpng-dev \
2219
libmcrypt-dev \
23-
zlib-dev \
20+
zlib-dev \
2421
libzip-dev \
2522
yaml-dev \
2623
tzdata \
2724
icu-dev \
2825
libpq-dev \
29-
# && pecl install mcrypt-1.0.3 \ not available for 8.1 =(
30-
&& pecl install redis-5.3.4 \
31-
&& pecl install xdebug-3.1.2 \
26+
libsodium-dev \
27+
&& pecl install redis \
28+
&& pecl install xdebug \
3229
&& pecl install apcu \
33-
&& pecl install zip-1.20.0 \
34-
&& rm -rf /tmp/pear \
35-
&& rm -rf ${SYS_NGINX_DIR}/sites-enabled/* ${SYS_NGINX_DIR}/sites-available/* \
36-
&& mkdir -p /var/log/supervisor
30+
&& pecl install zip \
31+
&& rm -rf /tmp/pear
3732

3833
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime && echo "Europe/Moscow" > /etc/timezone \
3934
&& apk del tzdata \
@@ -50,24 +45,11 @@ RUN apk update && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
5045
# Install composer
5146
COPY --from=composer /usr/bin/composer /usr/bin/composer
5247

53-
# Create dirs before start
54-
RUN mkdir /run/supervisord
55-
5648
# Copy source files to container
57-
COPY . /var/www/html
58-
WORKDIR /var/www/html
49+
#COPY ./app /var/www
50+
WORKDIR /var/www
51+
RUN rm -rf /var/www/*
5952

6053
# Copy configs
61-
COPY docker-config/supervisord/supervisord.conf /etc/supervisord.conf
62-
COPY docker-config/nginx/nginx.conf /etc/nginx/nginx.conf
63-
COPY docker-config/nginx/conf.d/default.conf ${SYS_NGINX_DIR}/conf.d/default.conf
64-
COPY docker-config/php/${APP_ENV}.ini /usr/local/etc/php/php.ini
65-
COPY docker-config/php/fpm.conf /usr/local/etc/php-fpm.d/www.conf
66-
67-
WORKDIR /var/www/html/app
68-
69-
# Use 80 port
70-
EXPOSE 80
71-
72-
# Start supervisor
73-
ENTRYPOINT ["/usr/bin/supervisord", "--pidfile=/run/supervisord/supervisord.pid"]
54+
ADD ./docker/config/php/${APP_ENV}.ini /usr/local/etc/php/conf.d/${APP_ENV}-custom.ini
55+
ADD ./docker/config/php/fpm.conf /usr/local/etc/php-fpm.d/www.conf

0 commit comments

Comments
 (0)