Skip to content

Commit 88adf2d

Browse files
authored
Merge pull request #2 from mongodb-developer/dev
Merge dev into master
2 parents 76817d2 + 033ad7e commit 88adf2d

File tree

106 files changed

+1168
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1168
-437
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error_reporting=E_ALL
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# this server config works with Laravel too
2+
server {
3+
listen 80;
4+
listen [::]:80 default_server;
5+
6+
# not needed for now
7+
# server_name example.com;
8+
9+
root /var/www/htdoc/public;
10+
11+
add_header X-Frame-Options "SAMEORIGIN";
12+
add_header X-Content-Type-Options "nosniff";
13+
14+
index index.php;
15+
16+
charset utf-8;
17+
18+
location / {
19+
try_files $uri $uri/ /index.php?$query_string;
20+
}
21+
22+
location = /favicon.ico { access_log off; log_not_found off; }
23+
location = /robots.txt { access_log off; log_not_found off; }
24+
25+
error_page 404 /index.php;
26+
27+
location ~* \.php$ {
28+
fastcgi_pass php:9000;
29+
30+
include fastcgi_params;
31+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
32+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
33+
}
34+
35+
location ~ /\.(?!well-known).* {
36+
deny all;
37+
}
38+
}

.devcontainer/.docker/php/Dockerfile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# defined in docker-compose.yml, from docker-env.env
2+
ARG RUNTIME_PHP_IMAGE
3+
4+
# Use the specified image as the base
5+
FROM ${RUNTIME_PHP_IMAGE}
6+
7+
# create the log file and provide permission to the www-data user
8+
RUN touch /tmp/xdebug.log && chown www-data:www-data /tmp/xdebug.log
9+
10+
# same thing for the PHP error log
11+
RUN touch /var/log/php-errors.log && chown www-data:www-data /var/log/php-errors.log
12+
13+
# Update the packages
14+
# Install system packages required for MongoDB extension
15+
# 'mysql-client' so we can log into mysql from the PHP container with the command 'mysql -h mysql -u root -p' where mysql is the service name
16+
# 'iputils-ping' to get the ping command
17+
RUN apt-get update \
18+
&& apt-get install -y libssl-dev wget git unzip default-mysql-client iputils-ping
19+
20+
RUN pecl apt update \
21+
&& apt install libzip-dev -y \
22+
&& docker-php-ext-install zip \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
# Required for MySQL to work in PHP
26+
RUN docker-php-ext-install mysqli && \
27+
docker-php-ext-install pdo_mysql
28+
29+
# Test if already installed and
30+
# install the <latest> mongodb PHP extension
31+
# RUN pecl install mongodb && docker-php-ext-enable mongodb
32+
RUN bash -c '[[ -n "$(pecl list | grep mongodb)" ]]\
33+
|| (pecl install mongodb && docker-php-ext-enable mongodb)'
34+
35+
# Test if already installed and
36+
# install and enable XDEBUG <latest>
37+
# RUN pecl install xdebug && docker-php-ext-enable xdebug
38+
RUN bash -c '[[ -n "$(pecl list | grep xdebug)" ]]\
39+
|| (pecl install xdebug && docker-php-ext-enable xdebug)'
40+
41+
# install Redis PHP driver
42+
RUN pecl install -o -f redis \
43+
&& rm -rf /tmp/pear \
44+
&& docker-php-ext-enable redis \
45+
&& docker-php-ext-enable pdo_mysql
46+
47+
# Task: copy rep's PHP .ini files to be automatically parsed
48+
#
49+
# directory is related to the PHP service context
50+
# dot NOT use ./filename.ext for root files
51+
# use filename.ext
52+
COPY docker-php.ini /usr/local/etc/php/conf.d/
53+
COPY xdebug.ini /usr/local/etc/php/conf.d/
54+
55+
# Install Composer
56+
# ----------------------------------------------------------
57+
# download composer
58+
RUN curl -sS https://getcomposer.org/installer | php
59+
# copy composer to a place where it can be globally executed
60+
RUN mv composer.phar /usr/local/bin/composer
61+
62+
# our repo is in var/www/htdoc
63+
# COPY init_repo.sh /var/www/htdoc/
64+
65+
# Set the working directory in the container
66+
WORKDIR /var/www/htdoc
67+
68+
# start out script that runs composer install, but ONLY if /vendor/ does not exist
69+
# WARNING: the commands below crash CodeSpaces. Not using for now.
70+
#RUN chmod +x /var/www/htdoc/init_repo.sh
71+
#ENTRYPOINT ["/var/www/htdoc/init_repo.sh"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# hubert stuff

.devcontainer/.docker/php/xdebug.ini

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; already loaded in /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
2+
;zend_extension=xdebug
3+
4+
; FIXME : should be elsewhere, like docker-php.ini
5+
error_log = /var/log/php-errors.log
6+
catch_workers_output = yes
7+
8+
[xdebug]
9+
; 'debug' means we're enabling step-by-step debugging
10+
xdebug.mode=debug
11+
12+
xdebug.client_port=9003
13+
14+
; xdebug.client_host is the IP address of the system where VS Code runs
15+
; that IP address is DIFFERENT depending on WHERE VS Code is launched in Windows/Mac, WSL, Container/devcontainer/codespaces
16+
;
17+
; the PHP container sends debugging data OUT to xdebug.client_host:xdebug.client_port
18+
19+
20+
; localhost is used when running btoh VS Code and PHP from within **the same PHP container**
21+
; after opening the project in the Container
22+
xdebug.client_host=localhost
23+
24+
; if using Docker Desktop 'host.docker.internal' is supposed to hold the IP Address of
25+
; the Docker host, but that's not always true. DOUBLE-CHECK
26+
27+
;xdebug.client_host=host.docker.internal
28+
29+
; 'yes': This will always initiate a debugging, profiling, or tracing session as soon as a request is received, without needing any specific trigger
30+
; 'no' : This will never initiate a session regardless of the presence of any trigger
31+
; 'trigger' : This will initiate a session only if a specific trigger, like a GET/POST variable or a cookie, is present in the request.
32+
xdebug.start_with_request=yes
33+
34+
; OPTIONAL: idekey
35+
; in the browser add a URL param , if not using a browser utility
36+
; url.to.debug?XDEBUG_SESSION_START=PHPSTORM
37+
; sets up a coockie called "XDEBUG_SESSION_START" with the value "PHPSTORM", which is the "trigger"
38+
; xdebug.idekey=PHPSTORM
39+
40+
; defines a log file. This is created, with touch, and initialized (permissions) in the PHP container Dockerfile
41+
xdebug.log=/tmp/xdebug.log

.devcontainer/.env

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# PATHs are relative to docker-compose.yml
2+
3+
NGINX_IMAGE=nginx:alpine
4+
NGINX_HOST_PORT=80
5+
NGINX_CONTAINER_PORT=80
6+
NGINX_HOST_CONFD_DIR=./.docker/nginx/conf.d
7+
NGINX_CONTAINER_CONFD_DIR=/etc/nginx/conf.d
8+
9+
PHP_WEBROOT_HOST_PATH=../src/
10+
PHP_WEBROOT_CONTAINER_PATH=/var/www/htdoc
11+
12+
NGINX_WEBROOT_HOST_PATH=../src/
13+
NGINX_WEBROOT_CONTAINER_PATH=/var/www/htdoc
14+
15+
MYSQL_IMAGE=mysql:5.7
16+
MYSQL_DATA_HOST_PATH=./data/mysql
17+
MYSQL_DATA_CONTAINER_PATH=/var/lib/mysql
18+
MYSQL_HOST_PORT=3306
19+
MYSQL_CONTAINER_PORT=3306
20+
21+
MYSQL_ROOT_PASSWORD=rootpassword
22+
MYSQL_DATABASE=mydatabase
23+
24+
PHP_IMAGE=php:8.2-fpm
25+
26+
27+
REDIS_DATA_HOST_PATH=./data/redis
28+
REDIS_DATA_CONTAINER_PATH=/etc/data

.devcontainer/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/data/
2+
/www/

.devcontainer/devcontainer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "laravel9-mongodb-tutorial",
3+
4+
// Mandatory definition for .devcontainer
5+
//
6+
// which service AS DEFINED IN .devcontainer/docker-compose.yml
7+
// do we want VS Code to attach to?
8+
// here, we choose the "php" service since that's where our code is executed
9+
"service": "php",
10+
11+
// we have multiple containers (nginx, PHP, MySQL, redis)
12+
// so we'll use a compose .yml file instead of defining the services in devcontainer.json
13+
"dockerComposeFile": "./docker-compose.yml",
14+
15+
"shutdownAction": "stopCompose",
16+
17+
// Mandatory definition for .devcontainer
18+
//
19+
// workspaceFolder describes the CONTAINER folder
20+
// in which the "service" (php here) is configured to mount the project
21+
// in our case, "/var/www/htdoc" refers to
22+
// ${WEBROOT_HOST_PATH}:${WEBROOT_CONTAINER_PATH} in our "php" service "volumeS"
23+
// these are defined in .devcontainer/.env as follows:
24+
// WEBROOT_HOST_PATH=../src
25+
// WEBROOT_CONTAINER_PATH=/var/www/htdoc
26+
"workspaceFolder": "/var/www/htdoc",
27+
28+
// NOT REQUIRED, because our mounts are defined in the .yml file
29+
//
30+
// mount defined in docker-compose.yml
31+
//"mounts": [
32+
// "source=${localWorkspaceFolder},target=/src,type=bind"
33+
//],
34+
35+
// "xdebug.php-debug" = official XDEBUG extension
36+
"customizations": {
37+
"vscode": {
38+
"extensions": [
39+
"xdebug.php-debug"
40+
]
41+
}
42+
},
43+
44+
"forwardPorts": [80],
45+
46+
// execute our one-time repo init if /vendor/ does not exist
47+
"postCreateCommand": "sh init_repo.sh"
48+
}

.devcontainer/docker-compose.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# build command: docker compose build
2+
# docker uses the .env file BY DEFAULT. Any other name and you'll have to specify it in the command line
3+
# docker compose --env-file FILENAME.env build
4+
5+
# docker compose version
6+
version: '3.4'
7+
8+
# Services
9+
services:
10+
11+
# Nginx Service
12+
nginx:
13+
14+
image: ${NGINX_IMAGE}
15+
ports:
16+
- ${NGINX_HOST_PORT}:${NGINX_CONTAINER_PORT}
17+
18+
# path is relative to where the docker-compose.yml file is.
19+
# local-path : container-path
20+
#
21+
volumes:
22+
# public web files
23+
- ${NGINX_WEBROOT_HOST_PATH}:${NGINX_WEBROOT_CONTAINER_PATH}
24+
# .ini location
25+
- ${NGINX_HOST_CONFD_DIR}:${NGINX_CONTAINER_CONFD_DIR}
26+
depends_on:
27+
- php
28+
- mysql_service
29+
30+
# PHP Service
31+
php:
32+
build:
33+
context: ./.docker/php
34+
dockerfile: Dockerfile
35+
args:
36+
RUNTIME_PHP_IMAGE: ${PHP_IMAGE}
37+
image: ${PHP_IMAGE}
38+
# container-path
39+
working_dir: ${PHP_WEBROOT_CONTAINER_PATH}
40+
# disk local-path
41+
volumes:
42+
- ${PHP_WEBROOT_HOST_PATH}:${PHP_WEBROOT_CONTAINER_PATH}
43+
# we don't need to expose the port 9003 here for Xdebug because the
44+
# connection comes from inside the PHP container to the IDE via port 9003
45+
environment:
46+
# laravel's default mysql config looks for the DATABASE_URL environment variable
47+
- DATABASE_URL=mysql://root:${MYSQL_ROOT_PASSWORD}@mysql_service:3306/${MYSQL_DATABASE}
48+
depends_on:
49+
- mysql_service
50+
51+
# MySQL Service
52+
mysql_service:
53+
image: ${MYSQL_IMAGE}
54+
55+
environment:
56+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
57+
MYSQL_DATABASE: ${MYSQL_DATABASE}
58+
59+
# the two variales below don't seem to be used at all. Commenting out for now
60+
#MYSQL_USER: myuser
61+
#MYSQL_PASSWORD: mypassword
62+
63+
# do NOT try mounting a volume in CodeSpaces as it will fail and MySQL will not launch (try pinging mysql_service)
64+
# this is only useful when working locally on a website with a non-ephemeral database
65+
#volumes:
66+
# map local /data/ folder to container /var/lib/mysql for MySQL data persistence
67+
# - ${MYSQL_DATA_HOST_PATH}:${MYSQL_DATA_CONTAINER_PATH}
68+
69+
ports:
70+
- "3306:3306"
71+
# syntax = host_port:container_port
72+
73+
74+
# redis:
75+
# image: redis:latest
76+
# ports:
77+
# - "6379:6379"
78+
# volumes:
79+
# - ${REDIS_DATA_HOST_PATH}:${REDIS_DATA_CONTAINER_PATH}
80+
81+
# Notes:
82+
#
83+
# From Docker Compose version 3.4 the name of the volume can be dynamically generated from environment variables placed in an .env file (this file has to be in the same folder as docker-compose.yml is).
84+
#

.vscode/launch.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Listen for Xdebug",
9+
"type": "php",
10+
"request": "launch",
11+
"port": 9003,
12+
// ${workspaceFolder} == directory where /.vscode/ is
13+
// the syntax is SERVER_PATH : LOCAL_PATH
14+
"pathMappings": {
15+
"/var/www/htdoc": "${workspaceFolder}/src"
16+
}
17+
},
18+
{
19+
"name": "Launch currently open script",
20+
"type": "php",
21+
"request": "launch",
22+
"program": "${file}",
23+
"cwd": "${fileDirname}",
24+
"port": 0,
25+
"runtimeArgs": [
26+
"-dxdebug.start_with_request=yes"
27+
],
28+
"env": {
29+
"XDEBUG_MODE": "debug,develop",
30+
"XDEBUG_CONFIG": "client_port=${port}"
31+
}
32+
},
33+
{
34+
"name": "Launch Built-in web server",
35+
"type": "php",
36+
"request": "launch",
37+
"runtimeArgs": [
38+
"-dxdebug.mode=debug",
39+
"-dxdebug.start_with_request=yes",
40+
"-S",
41+
"localhost:0"
42+
],
43+
"program": "",
44+
"cwd": "${workspaceRoot}",
45+
"port": 9003,
46+
"serverReadyAction": {
47+
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
48+
"uriFormat": "http://localhost:%s",
49+
"action": "openExternally"
50+
}
51+
}
52+
]
53+
}

0 commit comments

Comments
 (0)