Skip to content

Commit d7ad488

Browse files
committed
[1.0.0]
0 parents  commit d7ad488

File tree

9 files changed

+485
-0
lines changed

9 files changed

+485
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
www/*
3+
!www/hello.loc
4+
hosts/*
5+
!hosts/hello-loc.conf
6+
!hosts/phpmyadmin-loc.conf

README.MD

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
## Docker Image
2+
Stack:
3+
- Nginx
4+
- PHP FPM 7.2
5+
- Maria DB 10.2
6+
- Phpmyadmin 5.0.1
7+
8+
## Magento 2 supported versions:
9+
- 2.3.0
10+
- 2.3.1
11+
- 2.3.2
12+
- 2.3.3
13+
- 2.3.4
14+
- 2.3.5
15+
- 2.3.6
16+
17+
## How to use
18+
19+
### Test run:
20+
1) Install Docker and Docker compose
21+
2) Clone the repository to your local machine
22+
3) Modify your hosts file by adding these two lines or your own:
23+
```
24+
127.0.0.1 hello.loc
25+
127.0.0.1 phpmyadmin.loc
26+
```
27+
4) Run ``docker compose up -d`` from the root folder you just cloned
28+
5) Go ``http://hello.loc/`` to see PHP info default page or ``http://phpmyadmin.loc`` to see phpmyadmin panel to wor with databases
29+
30+
### Create your domains:
31+
7) Create your own hosts for further work based on ``./hosts/hello-loc.conf``. Just copy it, rename and modify and edit. Example:
32+
```
33+
server {
34+
index index.php;
35+
server_name my-new-project.loc;
36+
error_log /var/log/nginx/error.log;
37+
access_log /var/log/nginx/access.log;
38+
root /var/www/my-new-project.loc;
39+
40+
location ~ \.php$ {
41+
try_files $uri =404;
42+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
43+
fastcgi_pass php:9000;
44+
fastcgi_index index.php;
45+
include fastcgi_params;
46+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
47+
fastcgi_param PATH_INFO $fastcgi_path_info;
48+
}
49+
}
50+
```
51+
8) Don't forget to add your new domain ``my-new-project.loc`` to your computer **hosts** file
52+
9) Go ``http://my-new-project.loc/`` to see your project
53+
54+
### Configure Magento:
55+
10) Create ``auth.json`` file in the root of your magento project and make sure it is git ignored. Fill it with your Adobe account keys and with your github oath key. Any extra credentials for any 3-rd party extensions can be added as well. Example:
56+
```
57+
{
58+
"http-basic": {
59+
"repo.magento.com": {
60+
"username": "XXXXXXXX",
61+
"password": "XXXXXXXX"
62+
}
63+
},
64+
"github-oauth": {
65+
"github.com": "ghp_XXXXXXXXXXXXXXXXXXXXXXX"
66+
}
67+
}
68+
```
69+
70+
11) Create ``app/etc/env.php``. And fill it with the data needed (host name, db name, etc.). Example:
71+
```
72+
<?php
73+
return [
74+
'backend' => [
75+
'frontName' => 'admin'
76+
],
77+
'crypt' => [
78+
'key' => 'eb54762b26d8bf1b484c9b57ec914cf6'
79+
],
80+
'db' => [
81+
'table_prefix' => '',
82+
'connection' => [
83+
'default' => [
84+
'host' => 'maria',
85+
'dbname' => 'test_db',
86+
'username' => 'root',
87+
'password' => 'root',
88+
'active' => '1',
89+
'driver_options' => [
90+
1014 => false,
91+
1001 => true
92+
],
93+
'model' => 'mysql4',
94+
'engine' => 'innodb',
95+
'initStatements' => 'SET NAMES utf8;'
96+
]
97+
]
98+
],
99+
'resource' => [
100+
'default_setup' => [
101+
'connection' => 'default'
102+
]
103+
],
104+
'x-frame-options' => 'SAMEORIGIN',
105+
'MAGE_MODE' => 'developer',
106+
'session' => [
107+
'save' => 'files'
108+
],
109+
'cache' => [
110+
'frontend' => [
111+
'default' => [
112+
'id_prefix' => '40d_'
113+
],
114+
'page_cache' => [
115+
'id_prefix' => '40d_'
116+
]
117+
]
118+
],
119+
'lock' => [
120+
'provider' => 'db',
121+
'config' => [
122+
'prefix' => ''
123+
]
124+
],
125+
'cache_types' => [
126+
'config' => 1,
127+
'layout' => 1,
128+
'block_html' => 1,
129+
'collections' => 1,
130+
'reflection' => 1,
131+
'db_ddl' => 1,
132+
'compiled_config' => 1,
133+
'eav' => 1,
134+
'customer_notification' => 1,
135+
'config_integration' => 1,
136+
'config_integration_api' => 1,
137+
'full_page' => 1,
138+
'config_webservice' => 1,
139+
'translate' => 1,
140+
'vertex' => 1,
141+
'target_rule' => 1
142+
],
143+
'downloadable_domains' => [
144+
'jpw-b2c.loc'
145+
],
146+
'install' => [
147+
'date' => 'Fri, 07 Feb 2020 09:05:51 +0000'
148+
],
149+
'queue' => [
150+
'consumers_wait_for_messages' => 1
151+
],
152+
'cron' => [
153+
'enabled' => 0
154+
],
155+
'directories' => [
156+
'document_root_is_pub' => true
157+
]
158+
];
159+
```
160+
161+
12) Run composer install or other commands needed. See bash scripts bellow in the bonus section.
162+
163+
## Bonus
164+
Add these bash scripts to your ``.bashrc`` files. Function name can be any you like.
165+
166+
Enter your PHP container via CLI.
167+
Please, note that your container name MUST contain ``php-`` in the grep part.
168+
```
169+
enterServer(){
170+
docker exec -it $(docker ps --format "{{.Names}}" | grep "php-") bash
171+
}
172+
```
173+
174+
Stop all running containers:
175+
``
176+
stopAllContainers(){
177+
docker stop $(docker ps -q)
178+
}
179+
``
180+
181+
Run ``composer install`` for a particular project.
182+
Pass your project folder name as an argument. Example ``composerInstall hello.loc``
183+
Please, note that your container name MUST contain ``php-`` in the grep part.
184+
```
185+
composerInstall(){
186+
docker exec -i $(docker ps --format "{{.Names}}" | grep "php-") composer install --working-dir=/var/www/$1
187+
}
188+
```
189+
190+
Import the database where you should pass:
191+
1) You MySQL/MariaDb container name
192+
2) Your database name
193+
3) Your dump path
194+
```
195+
importDb(){
196+
docker exec -i $1 mysql -uroot -proot $2 < $3
197+
}
198+
```
199+
200+
Export the database where you should pass:
201+
1) You MySQL/MariaDb container name
202+
2) Your database name
203+
```
204+
exportDb(){
205+
docker exec -i $1 mysqldump -uroot -proot $2 | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | gzip > $2.sql.gz
206+
}
207+
```
208+
209+
### Magento 2 specific commands
210+
Clear back-end cache.
211+
Please, note that your container name MUST contain ``php-`` in the grep part.
212+
Pass your project folder name as an argument. Example ``removeBackCache hello.loc``
213+
```
214+
removeBackCache(){
215+
docker exec -i $(docker ps --format "{{.Names}}" | grep "php-") rm -fr /var/www/$1/var/cache /var/www/$1/generated/metadata /var/www/$1/generated/code /var/www/$1/var/view_preprocessed /var/www/$1/var/page_cache
216+
}
217+
```
218+
219+
Clear front-end cache.
220+
Please, note that your container name MUST contain ``php-`` in the grep part.
221+
Pass your project folder name as an argument. Example ``removeFrontCache hello.loc``
222+
```
223+
removeFrontCache(){
224+
docker exec -i $(docker ps --format "{{.Names}}" | grep "php-") rm -fr /var/www/$1/var/cache /var/www/$1/var/view_preprocessed /var/www/$1/var/page_cache /var/www/$1/pub/static/frontend /var/www/$1/pub/static/_cache
225+
}
226+
```
227+
228+
Run ``php bin/magento setup:upgrade``
229+
Please, note that your container name MUST contain ``php-`` in the grep part.
230+
Pass your project folder name as an argument. Example ``upgrade hello.loc``
231+
```
232+
upgrade(){
233+
docker exec -i $(docker ps --format "{{.Names}}" | grep "php-") php /var/www/$1/bin/magento setup:upgrade
234+
}
235+
```
236+
237+
Set developer mode ``php bin/magento deploy:mode:set developer``
238+
Please, note that your container name MUST contain ``php-`` in the grep part.
239+
Pass your project folder name as an argument. Example ``setDev hello.loc``
240+
```
241+
setDev(){
242+
docker exec -i $(docker ps --format "{{.Names}}" | grep "php-") php /var/www/$1/bin/magento deploy:mode:set developer
243+
}
244+
```
245+
246+
Set developer mode ``php bin/magento deploy:mode:set production``
247+
Please, note that your container name MUST contain ``php-`` in the grep part.
248+
Pass your project folder name as an argument. Example ``setProd hello.loc``
249+
```
250+
setProd(){
251+
docker exec -i $(docker ps --format "{{.Names}}" | grep "php-") php /var/www/$1/bin/magento deploy:mode:set production
252+
}
253+
```
254+
255+
Please, note that your container name MUST contain ``php-`` in the grep part.
256+
Pass your project folder name and db name as arguments.
257+
Example ``installFreshMagento hello.loc test_db``
258+
```
259+
installFreshMagento(){
260+
docker exec -i $1 php /var/www/$1/bin/magento setup:install \
261+
--base-url=http://$1/ \
262+
--db-host=mysql-server \
263+
--db-name=$2 \
264+
--db-user=root \
265+
--db-password=root \
266+
--admin-firstname=admin \
267+
--admin-lastname=admin \
268+
--admin-email=test@test.com \
269+
--admin-user=admin \
270+
--admin-password=123123 \
271+
--language=en_US \
272+
--currency=USD \
273+
--timezone=America/Chicago \
274+
--use-rewrites=1 \
275+
--elasticsearch-host=elasticsearch \
276+
--backend-frontname=admin
277+
}
278+
```

docker-compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: '3.7'
2+
services:
3+
nginx:
4+
image: nginx:latest
5+
ports:
6+
- "80:80"
7+
- "443:443"
8+
volumes:
9+
- ./hosts:/etc/nginx/conf.d
10+
- ./www:/var/www
11+
- ./logs:/var/log/nginx
12+
depends_on:
13+
- php
14+
- maria
15+
php:
16+
build: ./images/php
17+
depends_on:
18+
- maria
19+
volumes:
20+
- ./www:/var/www
21+
- ./images/php/php.ini:/usr/local/etc/php/conf.d/40-custom.ini
22+
- ~/.ssh:/root/.ssh
23+
maria:
24+
image: mariadb:10.2
25+
ports:
26+
- "3306:3306"
27+
environment:
28+
MYSQL_ROOT_PASSWORD: root
29+
phpmyadmin:
30+
image: phpmyadmin/phpmyadmin:5.0.1
31+
environment:
32+
PMA_HOST: maria
33+
PMA_USER: root
34+
PMA_PASSWORD: root
35+
PMA_ABSOLUTE_URI: "http://phpmyadmin.loc/"
36+
depends_on:
37+
- maria
38+
- php
39+
- nginx

hosts/hello-loc.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
server {
2+
index index.php;
3+
server_name hello.loc;
4+
error_log /var/log/nginx/error.log;
5+
access_log /var/log/nginx/access.log;
6+
root /var/www/hello.loc;
7+
8+
location ~ \.php$ {
9+
try_files $uri =404;
10+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
11+
fastcgi_pass php:9000;
12+
fastcgi_index index.php;
13+
include fastcgi_params;
14+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
15+
fastcgi_param PATH_INFO $fastcgi_path_info;
16+
}
17+
}

hosts/phpmyadmin-loc.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server {
2+
listen 80;
3+
index index.php index.html;
4+
server_name phpmyadmin.loc;
5+
error_log /var/log/nginx/phpmyadmin-error.log;
6+
access_log /var/log/nginx/phpmyadmin-access.log;
7+
root /var/www/html;
8+
9+
location ^~ / {
10+
proxy_set_header X-Real-IP $remote_addr;
11+
proxy_set_header X-Forwarded-For $remote_addr;
12+
proxy_set_header Host $host;
13+
proxy_pass http://phpmyadmin/;
14+
}
15+
}

0 commit comments

Comments
 (0)