File tree 9 files changed +225
-1
lines changed
9 files changed +225
-1
lines changed Original file line number Diff line number Diff line change
1
+ DOCKER_NGINX_EXTERNAL_PORT = 8080
2
+ DOCKER_MYSQL_EXTERNAL_PORT = 3306
Original file line number Diff line number Diff line change
1
+ /node_modules
2
+ /vendor
3
+ .env
4
+ /.idea
Original file line number Diff line number Diff line change 1
- # php-with-docker-template
1
+ # php-with-docker-template
2
+
3
+ ## Installation
4
+
5
+ Copy the ` .env ` file
6
+
7
+ ```
8
+ cp env.example .env
9
+ ```
10
+
11
+ Build docker image
12
+
13
+ ```
14
+ docker-compose build
15
+ ```
16
+
17
+ Run docker image
18
+
19
+ ```
20
+ docker-compose up
21
+ ```
22
+
23
+ Run the following command to install the package through Composer:
24
+
25
+ ``` bash
26
+ docker-compose exec composer install
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Stop docker
32
+
33
+ ```
34
+ docker-compose down
35
+ ```
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " coccoc/php-with-docker-template" ,
3
+ "description" : " Template of PHP course 2022." ,
4
+ "keywords" : [" framework" ],
5
+ "type" : " project" ,
6
+ "version" : " v1.0.1" ,
7
+ "require" : {
8
+ "php" : " ^7.4" ,
9
+ "ext-json" : " *" ,
10
+ "ext-mysqli" : " *"
11
+ },
12
+ "require-dev" : {
13
+ "mockery/mockery" : " ^1.4" ,
14
+ "phpunit/phpunit" : " ^9.5"
15
+ },
16
+ "config" : {
17
+ "optimize-autoloader" : true ,
18
+ "preferred-install" : " dist" ,
19
+ "sort-packages" : true
20
+ },
21
+ "autoload" : {
22
+ },
23
+ "autoload-dev" : {
24
+ "psr-4" : {
25
+ "Tests\\ " : " tests/"
26
+ }
27
+ },
28
+ "minimum-stability" : " dev" ,
29
+ "prefer-stable" : true ,
30
+ "scripts" : {
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ version : " 3"
2
+
3
+ services :
4
+ nginx :
5
+ image : nginx:latest
6
+ container_name : php_course_nginx
7
+ depends_on :
8
+ - app
9
+ volumes :
10
+ - ./:/var/www
11
+ - ./docker/nginx/server.conf:/etc/nginx/conf.d/default.conf
12
+ ports :
13
+ - ' ${DOCKER_NGINX_EXTERNAL_PORT}:80'
14
+ networks :
15
+ - default
16
+ app :
17
+ build :
18
+ args :
19
+ BUILD_ENV : local
20
+ context : .
21
+ dockerfile : ./docker/php/Dockerfile
22
+ container_name : php_course_app
23
+ depends_on :
24
+ - db
25
+ volumes :
26
+ - ./:/var/www
27
+ expose :
28
+ - ' 9000'
29
+ environment :
30
+ PHP_OPCACHE_VALIDATE_TIMESTAMPS : 1
31
+ networks :
32
+ - default
33
+ db :
34
+ image : mariadb:10.4
35
+ container_name : php_course_mysql
36
+ tty : true
37
+ ports :
38
+ - ' ${DOCKER_MYSQL_EXTERNAL_PORT}:3306'
39
+ environment :
40
+ MYSQL_DATABASE : php_course
41
+ MYSQL_USER : php_course
42
+ MYSQL_PASSWORD : dev@123
43
+ MYSQL_ROOT_PASSWORD : dev@123
44
+ MYSQL_ROOT_HOST : ' %'
45
+ TZ : Asia/Ho_Chi_Minh
46
+ volumes :
47
+ - mysql-db:/var/lib/mysql/
48
+ command : mysqld --sql_mode=""
49
+ networks :
50
+ - default
51
+
52
+ volumes :
53
+ mysql-db :
54
+ driver : local
55
+ networks :
56
+ default :
57
+ driver : bridge
Original file line number Diff line number Diff line change
1
+
2
+ server {
3
+ listen 80;
4
+ server_name _;
5
+ index index.php index.html;
6
+
7
+ error_log /dev/stdout info;
8
+ access_log /dev/stdout;
9
+
10
+ root /var/www/public;
11
+
12
+ client_max_body_size 10M;
13
+
14
+ location / {
15
+ try_files $uri $uri/ /index.php?$query_string;
16
+ gzip_static on;
17
+ gzip on;
18
+ }
19
+
20
+ location ~ \.php$ {
21
+ try_files $uri =404;
22
+ fastcgi_split_path_info ^(.+\.php)(/.+)$;
23
+ fastcgi_pass app:9000;
24
+ fastcgi_index index.php;
25
+ include fastcgi_params;
26
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
27
+ fastcgi_param PATH_INFO $fastcgi_path_info;
28
+ fastcgi_param PHP_VALUE "upload_max_filesize=5M \n post_max_size=5M";
29
+ fastcgi_buffers 128 16k;
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ FROM php:7.4-fpm as php
2
+
3
+ RUN apt-get update -y \
4
+ && apt-get install -y zlib1g-dev \
5
+ libicu-dev \
6
+ g++ \
7
+ libzip-dev \
8
+ zip \
9
+ unzip \
10
+ ssh \
11
+ git \
12
+ libssl-dev \
13
+ && apt-get clean \
14
+ && rm -rf /var/lib/apt/lists/*
15
+
16
+ ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
17
+ PHP_OPCACHE_MAX_ACCELERATED_FILES="10000" \
18
+ PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
19
+ PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"
20
+
21
+ RUN docker-php-ext-configure intl \
22
+ && docker-php-ext-install intl mysqli opcache pdo_mysql zip \
23
+ && pecl install redis \
24
+ && docker-php-ext-enable redis \
25
+ && pecl install apcu \
26
+ && docker-php-ext-enable apcu
27
+
28
+
29
+ COPY ./docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
30
+
31
+ RUN echo 'max_execution_time = 120' >> /usr/local/etc/php/conf.d/docker-php.ini;
32
+ RUN echo 'expose_php = off' >> /usr/local/etc/php/conf.d/docker-php.ini;
33
+
34
+ ARG PUID=10000
35
+ ENV PUID ${PUID}
36
+ ARG PGID=10000
37
+ ENV PGID ${PGID}
38
+
39
+ RUN groupmod -o -g ${PGID} www-data && \
40
+ usermod -o -u ${PUID} -g www-data www-data
41
+
42
+ COPY --chown=www-data:www-data . /var/www
43
+
44
+ WORKDIR /var/www
45
+
46
+ RUN apt-get clean && \
47
+ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
48
+ rm /var/log/lastlog /var/log/faillog
49
+
50
+ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
51
+
52
+ RUN composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts --no-dev --optimize-autoloader
Original file line number Diff line number Diff line change
1
+ [opcache]
2
+ opcache.enable =1
3
+ opcache.revalidate_freq =0
4
+ opcache.validate_timestamps =${PHP_OPCACHE_VALIDATE_TIMESTAMPS}
5
+ opcache.max_accelerated_files =10000
6
+ opcache.memory_consumption =192
7
+ opcache.max_wasted_percentage =10
8
+ opcache.interned_strings_buffer =16
9
+ opcache.fast_shutdown =1
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ echo "Welcome to CocCoc PHP Course 2022. " ;
You can’t perform that action at this time.
0 commit comments