-
Notifications
You must be signed in to change notification settings - Fork 3
/
any.practice.code.txt
526 lines (280 loc) · 11.4 KB
/
any.practice.code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
---> Any Practice Code In This File <---
---> Rough Code <------
Links:
https://help.ubuntu.com/community/EnvironmentVariables
1. Trying to install laravel in docker container
a.
When I was trying to install laravel in docker container.
Failed to download laravel/laravel from dist: The zip extension and unzip/7z commands are both missing, skipping.
The php.ini used by your command-line PHP is:
/usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
Now trying to download from source
In GitDownloader.php line 82:
git was not found in your PATH, skipping source download
b. When I tryed to install laravel installer, Threw Errors (Path error)
composer global require laravel/installer
c. Laravel default page not properly display on browser (Permissions error)
Solutions:
a. Problem solved after installing zip and unzip using 'apt install zip unzip' command in docker container
b. Run these commands in docker container
root@5f864af62def:/var/www/html# export PATH="$PATH:$HOME/.composer/vendor/laravel/installer/bin"
root@5f864af62def:/var/www/html# source ~/.bashrc
root@5f864af62def:/var/www/html# laravel -v
source ~/.bashrc # This for Ubuntu 20.0
This is working.
c.
sudo chown -R www-data:www-data /var/www
sudo chown -R www-data:www-data /var/wwww/laravel
sudo chown -R www-data:www-data /var/wwww/html/laravel
sudo chown -R www-data:www-data /var/www/laravel/vendor
sudo chown -R www-data:www-data /var/www/laravel/storage
sudo chown -R www-data:www-data /var/www/html/laravel/vendor
sudo chown -R www-data:www-data /var/www/html/laravel/storage
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
cd into your Laravel project.
sudo chmod -R 755 storage
sudo chmod -R 755 bootstrap/cache
sudo chmod -R 755 /var/www/html/storage
Example:
Dockerfile:
FROM php:7-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && docker-php-ext-install mcrypt pdo_mysql
ADD . /var/www
RUN chown -R www-data:www-data /var/www
his makes directory /var/www owned by www-data which is the default user for php-fpm.
Since it is compiled with user www-data.
---------------------------------------------------------------------------
# Apache2 sites-available:
<VirtualHost *:80>
ServerAdmin admin@MyWebsite.com
DocumentRoot /var/www/html/laravel/public
ServerName laravel-local.com
<Directory /var/www/html/laravel/public>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
----------------------------------------------------------------------------
# Set Environment Path in linux:
To put this folder on the PATH environment variable type
export PATH="$PATH:$HOME/.composer/vendor/bin"
This appends the folder to your existing PATH, however, it is only active for your current terminal session.
If you want it to be automatically set, it depends on the shell you are using. For bash, you can append this line to $HOME/.bashrc using your favorite editor or type the following on the shell
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
In order to check if it worked, logout and login again or execute
source ~/.bashrc
Detailed instructions:
in your ~/.bashrc add these lines:
export PATH="$PATH:~/.composer/vendor/bin"
Then reload:
source ~/.bashrc
Check if its added correctly:
echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/web/bin:~/.compo
You probably wanted
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
or just
echo 'PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
since PATH has almost certainly been exported into the environment already.
Ubuntu 20.04 setting path variable to solve laravel: command not found:
export PATH="$PATH:$HOME/.config/composer/vendor/bin" >> ~/.bashrc
and
export PATH="$PATH:$HOME/.config/composer/vendor/bin" >> ~/.profile
than I did source ~/.bashrc and source ~/.profile to update those files.
You probably wanted:
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
or just
echo 'PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
-----------------------------
Extra:
I tried all of these, and it didn't work. My Laravel storage folder had access. But /var/www/storage still didn't had permission.
After reading multiple suggestions, with this in particular. I did the following (kindly note that php is the name of my container image, and i linked my laravel project directly to /var/www):
From my docker, I ran
docker-compose exec php ls -al /var/www/storage
I saw that only root had access but i need
www-data to have access.
Then I ran
docker-compose exec php chown -R $USER:www-data /var/www/storage
This gives
www-data access to the storage folder
Then I ran
docker-compose exec php chown -R $USER:www-data /var/www/bootstrap/cache
This gives
www-data access to the bootstrap/cache folder
If you run item 1 again, www-data should have access, and your Laravel app should be fine.
-------------------------------------------------------------------------
Docker Angular App:
# Stage 1: Compile and Build angular codebase
# Use official node image as the base image
FROM node:latest as build
# Set the working directory
WORKDIR /usr/local/app
# Add the source code to app
COPY ./ /usr/local/app/
# Install all the dependencies
RUN npm install
# Generate the build of the application
RUN npm run build
# Stage 2: Serve app with nginx server
# Use official nginx image as the base image
FROM nginx:latest
# Copy the build output to replace the default nginx contents.
COPY --from=build /usr/local/app/dist/dockerangular01 /usr/share/nginx/html
# Expose port 80
EXPOSE 80
--------------------------------------------------------------------------
docker=compose up -d
docker-compose down
docker-compose restart
-----------------------------------------------------------------
//Redis nginx
https://mattkomarnicki.com/articles/docker-laravel-environment-with-php-nginx-mysql-redis-and-scheduler
-----------------------------------------------------------
Docker mongo container login:
docker exec -it contId bash
abcdefff# mongo -u root -p
password: password
>
create db: use dbName ex: use mydb
show db: db // output: mydb
create collection: db.createCollection("users")
insert document :
db.users.insertOne( { name: "mark" } );
showing recores(documents):
db.users.find()
REDIS:
version: '3.5'
services:
cache:
image: redis:latest
command: ["redis-server", "/etc/redis/redis.conf"]
volumes:
- ./redis.conf:/etc/redis/redis.conf
ports:
- "6379:6379"
Redis:
docker pull redis
docker run -it --name redis-container -d redis
docker logs redis-container
docker exec -it redis-container bash
root@64163c8ed78d:/data#
root@64163c8ed78d:/data# redis-cli
127.0.0.1:6379> ping
127.0.0.1:6379> exit
root@64163c8ed78d:/data# exit
Or
127.0.0.1:6379> auth password
127.0.0.1:6379> set name ajay
127.0.0.1:6379> get name
"ajay"
127.0.0.1:6379> incr counter
(integer) 1
127.0.0.1:6379> incr counter
(integer) 2
127.0.0.1:6379> get counter
"2"
127.0.0.1:6379> exit
# exit
Connect from another linked container
docker run -it --rm --link redis1:redis --name client1 redis sh
# redis-cli -h redis
redis:6379>
redis:6379> get name
"mark"
redis:6379> get counter
"2"
redis:6379> exit
# exit
Clean up
docker stop redis1
docker rm redis1
docker image ls
docker image rm redis
------------------------------------------
Docker nginx:
Volume:
docker run --name ngx -v "$(pwd)"/php:/usr/share/nginx/html -p8080:80 -d nginx
//https://www.docker.com/blog/how-to-use-the-official-nginx-docker-image/
// --rm (container remove after exited Or stopped it
Running a basic web server:
$ docker run -it --rm -d -p 8080:80 --name web nginx
Adding Custom HTML:
docker run -it --rm -d -p 8080:80 --name web -v ~/site-content:/usr/share/nginx/html nginx
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Docker Nginx</title>
</head>
<body>
<h2>Hello from Nginx container</h2>
</body>
</html>
Build Custom NGINX Image:
FROM nginx:latest
COPY ./index.html /usr/share/nginx/html/index.html
docker build -t webserver
docker run -it --rm -d -p 8080:80 --name web webserver
Setting up a reverse proxy server:
git clone https://github.com/pmckeetx/docker-nginx.git
FROM node:12.18.2 as build
ARG REACT_APP_SERVICES_HOST=/services/m
WORKDIR /app
COPY ./package.json /app/package.json
COPY ./package-lock.json /app/package-lock.json
RUN yarn install
COPY . .
RUN yarn build
FROM nginx
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html
We configure the reverse proxy in the frontend/nginx/nginx.conf file.
server {
listen 80;
server_name frontend;
location / {
# This would be the directory where your React app's static files are stored at
root /usr/share/nginx/html;
try_files $uri /index.html;
}
location /services/m {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://backend:8080/services/m;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
As you can see in the second location section thatall traffic targeted to /services/m will be proxy_pass to http://backend:8080/services/m
In the root of the project is a Docker Compose file that will start both our frontend and backend services. Let’s start up our application and test if the reverse proxy is working correctly.
docker-compose -up
Creating network "docker-nginx_frontend" with the default driver
Creating network "docker-nginx_backend" with the default driver
Creating docker-nginx_frontend_1 ... done
Creating docker-nginx_backend_1 ... done
Attaching to docker-nginx_backend_1, docker-nginx_frontend_1
frontend_1 | /docker-entrypoint.sh: Configuration complete; ready for start up
backend_1 | Listening on port 8080
Shipping Our Image:
$ docker login
$ docker tag nginx-frontend <dockerid>/nginx-frontend
$ docker push <dockerid>/nginx-frontend
---------------------------------------
Bank Widthdaw from zebpay:
4000.00 w2407093 2
2000.00 W1917195 2
2000.00 W1879121 2
1000.00 W1820223 2 years
1000.00 W1773441 2 years
1000.00 W1729858 2 years ago
widthraw 5007.12 inr w1537847 4
15000.00 payment ref no W502468 5 years ago
---------------------------------------------------------------------------------