Skip to content

Commit 6d3b309

Browse files
committed
Create php project structure with docker
1 parent fb2688b commit 6d3b309

File tree

8 files changed

+178
-0
lines changed

8 files changed

+178
-0
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/myblog.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM php:8.0.13-fpm-alpine
2+
3+
#COPY ./src/composer.lock ./src/composer.json /var/www/html/
4+
5+
WORKDIR /var/www/html
6+
7+
#RUN docker-php-ext-install mysqli pdo pdo_mysql zip exif pcntl
8+
#RUN docker-php-ext-configure gd --with-freetype --with-jpeg
9+
#RUN docker-php-ext-install gd
10+
11+
RUN apk --update --no-cache add curl
12+
13+
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
14+
15+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
16+
17+
#RUN chown -R www-data:www-data \
18+
# /var/www/html/storage \
19+
# /var/www/html/bootstrap/cache
20+
21+
22+
COPY ./src /var/www/html
23+
24+
EXPOSE 9000
25+
CMD ["php-fpm"]
26+

docker-compose.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
version: "3"
2+
3+
4+
networks:
5+
backend:
6+
7+
8+
services:
9+
10+
11+
nginx:
12+
image: nginx:stable-alpine
13+
container_name: nginx-blog
14+
restart: unless-stopped
15+
ports:
16+
- "8000:80"
17+
- "443:443"
18+
volumes:
19+
- ./src:/var/www/html
20+
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
21+
depends_on:
22+
- php
23+
- mysql
24+
networks:
25+
- backend
26+
27+
28+
mysql:
29+
image: mysql:5.7.38
30+
container_name: mysql-blog
31+
restart: unless-stopped
32+
tty: true
33+
ports:
34+
- "3306:3306"
35+
environment:
36+
MYSQL_DATABASE: blog
37+
MYSQL_PASSWORD: root
38+
MYSQL_USER: 123456
39+
MYSQL_ROOT_PASSWORD: 123456
40+
SERVICE_TAGS: dev
41+
SERVICE_NAME: mysql
42+
volumes:
43+
- ./mysql/my.cnf:/etc/mysql/my.cnf
44+
networks:
45+
- backend
46+
47+
48+
phpmyadmin:
49+
image: phpmyadmin/phpmyadmin
50+
container_name: phpmyadmin-blog
51+
environment:
52+
PMA_HOST: mysql
53+
PMA_PORT: 3306
54+
MYSQL_ROOT_PASSWORD: 123456
55+
restart: unless-stopped
56+
ports:
57+
- 8080:80
58+
depends_on:
59+
- mysql
60+
networks:
61+
- backend
62+
63+
php:
64+
build:
65+
context: .
66+
dockerfile: Dockerfile
67+
container_name: php-blog
68+
restart: unless-stopped
69+
volumes:
70+
- ./src:/var/www/html
71+
ports:
72+
- "9000:9000"
73+
74+
healthcheck:
75+
test: curl --fail http://localhost || exit 1
76+
interval: 60s
77+
retries: 5
78+
#start_period: 20s
79+
timeout: 10s
80+
81+
networks:
82+
- backend
83+
84+
85+
86+

mysql/my.cnf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mysqld]
2+
general_log = 1
3+
general_log_file = /var/lib/mysql/general.log

nginx/default.conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
server {
2+
listen 80;
3+
listen [::]:80;
4+
server_name localhost;
5+
root /var/www/html/public;
6+
7+
add_header X-Frame-Options "SAMEORIGIN";
8+
add_header X-Content-Type-Options "nosniff";
9+
10+
index index.php index.html;
11+
12+
charset utf-8;
13+
14+
location / {
15+
try_files $uri $uri/ /index.php?$query_string;
16+
}
17+
18+
location = /favicon.ico { access_log off; log_not_found off; }
19+
location = /robots.txt { access_log off; log_not_found off; }
20+
21+
22+
location ~ \.php$ {
23+
try_files $uri = 404;
24+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
25+
fastcgi_pass php:9000;
26+
fastcgi_index index.php;
27+
include fastcgi_params;
28+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
29+
fastcgi_param PATH_INFO $fastcgi_path_info;
30+
31+
}
32+
33+
location ~ /\.(?!well-known).* {
34+
deny all;
35+
}
36+
}

src/public/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
echo 'hello world';

0 commit comments

Comments
 (0)