Skip to content

Commit d4cea02

Browse files
committed
re-organizing the repo structure to add Docker / devcontainer
.devcontainer directory and LEMP container(s) added, but the setup for Laravel is not yet working. There are issues with setting up PHP and NGINX to serve only /public/ on the homepage of localhost
1 parent 76817d2 commit d4cea02

File tree

103 files changed

+250
-0
lines changed

Some content is hidden

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

103 files changed

+250
-0
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
server {
3+
listen 80 default_server;
4+
listen [::]:80 default_server;
5+
root /var/www/htdoc;
6+
index index.php;
7+
8+
location ~* \.php$ {
9+
fastcgi_pass php:9000;
10+
include fastcgi_params;
11+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
12+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
13+
}
14+
}

.devcontainer/.docker/php/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
# Update the packages
8+
# Install system packages required for MongoDB extension
9+
RUN apt-get update \
10+
&& apt-get install -y libssl-dev wget git unzip
11+
12+
RUN pecl apt update \
13+
&& apt install libzip-dev -y \
14+
&& docker-php-ext-install zip \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Required for MySQL to work in PHP
18+
RUN docker-php-ext-install mysqli
19+
20+
# Test if already installed and
21+
# install the <latest> mongodb PHP extension
22+
# RUN pecl install mongodb && docker-php-ext-enable mongodb
23+
RUN bash -c '[[ -n "$(pecl list | grep mongodb)" ]]\
24+
|| (pecl install mongodb && docker-php-ext-enable mongodb)'
25+
26+
# Test if already installed and
27+
# install and enable XDEBUG <latest>
28+
# RUN pecl install xdebug && docker-php-ext-enable xdebug
29+
RUN bash -c '[[ -n "$(pecl list | grep xdebug)" ]]\
30+
|| (pecl install xdebug && docker-php-ext-enable xdebug)'
31+
32+
# install Redis PHP driver
33+
RUN pecl install -o -f redis \
34+
&& rm -rf /tmp/pear \
35+
&& docker-php-ext-enable redis
36+
37+
# Task: copy rep's PHP .ini files to be automatically parsed
38+
#
39+
# directory is related to the PHP service context
40+
# dot NOT use ./filename.ext for root files
41+
# use filename.ext
42+
COPY docker-php.ini /usr/local/etc/php/conf.d/
43+
COPY xdebug.ini /usr/local/etc/php/conf.d/
44+
45+
# Install Composer
46+
# ----------------------------------------------------------
47+
# download composer
48+
RUN curl -sS https://getcomposer.org/installer | php
49+
# copy composer to a place where it can be globally executed
50+
RUN mv composer.phar /usr/local/bin/composer
51+
52+
# NOT REQUIRED
53+
# Change to non-root privilege
54+
# USER www-data
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# already loaded in /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
2+
#zend_extension=xdebug
3+
4+
[xdebug]
5+
xdebug.mode=debug
6+
xdebug.client_host=host.docker.internal
7+
xdebug.start_with_request=yes
8+
;xdebug.discover_client_host=1
9+
xdebug.client_port=9003
10+
xdebug.idekey=PHPSTORM
11+
xdebug.log=/tmp/xdebug.log

.devcontainer/.env

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
WEBROOT_HOST_PATH=../src/public
10+
WEBROOT_CONTAINER_PATH=/var/www/htdoc
11+
12+
NGINX_WEBROOT_HOST_PATH=../src/public
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+
PHP_IMAGE=php:8.2-fpm
22+
23+
24+
REDIS_DATA_HOST_PATH=./data/redis
25+
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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
// Mandatory definition for .devcontainer
3+
//
4+
// which service AS DEFINED IN .devcontainer/docker-compose.yml
5+
// do we want VS Code to attach to?
6+
// here, we choose the "php" service since that's where our code is executed
7+
"service": "php",
8+
9+
// we have multiple containers (nginx, PHP, MySQL, redis)
10+
// so we'll use a compose .yml file instead of defining the services in devcontainer.json
11+
"dockerComposeFile": "./docker-compose.yml",
12+
13+
// Mandatory definition for .devcontainer
14+
//
15+
// workspaceFolder describes the CONTAINER folder
16+
// in which the "service" (php here) is configured to mount the project
17+
// in our case, "/var/www/htdoc" refers to
18+
// ${WEBROOT_HOST_PATH}:${WEBROOT_CONTAINER_PATH} in our "php" service "volumeS"
19+
// these are defined in .devcontainer/.env as follows:
20+
// WEBROOT_HOST_PATH=../src
21+
// WEBROOT_CONTAINER_PATH=/var/www/htdoc
22+
"workspaceFolder": "/var/www/htdoc",
23+
24+
// NOT REQUIRED, because our mounts are defined in the .yml file
25+
//
26+
// mount defined in docker-compose.yml
27+
//"mounts": [
28+
// "source=${localWorkspaceFolder},target=/src,type=bind"
29+
//],
30+
31+
// "xdebug.php-debug" = official XDEBUG extension
32+
"customizations": {
33+
"vscode": {
34+
"extensions": ["xdebug.php-debug"]
35+
}
36+
}
37+
}

.devcontainer/docker-compose.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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
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: ${WEBROOT_CONTAINER_PATH}
40+
# disk local-path
41+
volumes:
42+
- ${WEBROOT_HOST_PATH}:${WEBROOT_CONTAINER_PATH}
43+
44+
45+
# MySQL Service
46+
mysql:
47+
image: ${MYSQL_IMAGE}
48+
environment:
49+
MYSQL_ROOT_PASSWORD: rootpassword
50+
MYSQL_DATABASE: mydatabase
51+
MYSQL_USER: rootuser
52+
MYSQL_PASSWORD: mypassword
53+
volumes:
54+
# map local /data/ folder to container /var/lib/mysql for MySQL data persistence
55+
- ${MYSQL_DATA_HOST_PATH}:${MYSQL_DATA_CONTAINER_PATH}
56+
ports:
57+
- "${MYSQL_HOST_PORT}:${MYSQL_CONTAINER_PORT}"
58+
59+
60+
redis:
61+
image: redis:latest
62+
ports:
63+
- "6379:6379"
64+
volumes:
65+
- ${REDIS_DATA_HOST_PATH}:${REDIS_DATA_CONTAINER_PATH}
66+
67+
# Notes:
68+
#
69+
# 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).
70+
#

DockerSetup.md

Lines changed: 35 additions & 0 deletions

0 commit comments

Comments
 (0)