diff --git a/docs/10_Requirements.md b/docs/10_Requirements.md new file mode 100644 index 0000000000000000000000000000000000000000..41a319e296fa7e068b5365862088300377e77686 --- /dev/null +++ b/docs/10_Requirements.md @@ -0,0 +1,4 @@ +## Requirements ## + +* Bash (tested on Linux only) +* Docker Non-root installation - see <https://docs.docker.com/engine/security/rootless/> diff --git a/docs/20_Init_a_new_project.md b/docs/20_Init_a_new_project.md new file mode 100644 index 0000000000000000000000000000000000000000..275093f0f1c1a7401549f3639fbcf2bf6917cbc7 --- /dev/null +++ b/docs/20_Init_a_new_project.md @@ -0,0 +1,74 @@ + +## How to use this template ## + +### Create a new project folder ### + +Copy downloaded and extracted folder to a new name: + +```shell +cp -r docker-php-starterkit my-new-php-app +``` + +OR + +```shell +git clone https://gitlab.iml.unibe.ch/iml-open-source/docker-php-starterkit.git my-new-php-app +``` + +In the new folder remove the docs of the kit and its git repo + +```shell +cd my-new-php-app && rm -rf docs .git +``` + +The initial file structure looks like this: + +```txt +. +├── docker # Docker data +│ ├── init.sh << shellscript for initialization +│ ├── init.sh.cfg << config file +│ └── templates << folder with templates +│ ├── docker-compose.yml +│ ├── dot_env +│ ├── extra-php-config.ini +│ ├── my.cnf +│ ├── readme.md +│ ├── vhost_app.conf +│ └── web-server-Dockerfile +├── public_html # your webroot for your project +│ └── index.php +└── readme.md +``` + +### Edit variables and files ### + +* edit ```./docker/init.sh.cfg``` ... and edit + * ```APP_NAME=my_new_app``` + * optional: set a new port ```APP_PORT=8001``` + * set APP_* variables for packages to install or PHP version + * set DB_ADD to true or false to say if a database container is needed + * If a database is needed then set DB_PORT and MYSQL_* variables +* edit ```./docker/templates/vhost_app.conf``` to describe apache vhost config +* edit php settings in ```./docker/templates/extra-php.ini``` +* edit mysql settings in ```./docker/templates/my.cnf``` + +### First start ### + +* start init script in the docker folder: ```./docker/init.sh``` + * use "g" to remove git data of the starterkit + * use "i" for init ... it sets an ACL on the ./public_html/ subdir to allow write access for your current user and the apache user in the docker container + * use "t" to generate config files from templates with the settings from ./docker/init.sh.cfg + * use "u" to bring up the container (OR run ```docker-compose up -d``` ) + +### Edit files ### + +* If the container was started you can ... + * open in your browser http://localhost:8001 to access ```./public_html/``` + * edit files with the IDE of your choice + +### Remarks ### + +You can start ./docker/init.sh with a single letter in the interactive menu too, i.e. ```./docker/init.sh u``` to bring up the docker instance. + +If you created the config files from templates you can repeat the creation ```./docker/init.sh t```. Before applying a change you should shutdown your docker instance. diff --git a/docs/30_Configuration/10_init.sh.cfg.md b/docs/30_Configuration/10_init.sh.cfg.md new file mode 100644 index 0000000000000000000000000000000000000000..6f747e41130472670a3cb44756ad5657b39178e1 --- /dev/null +++ b/docs/30_Configuration/10_init.sh.cfg.md @@ -0,0 +1,123 @@ +# init.sh.cfg + +This is the main configuration file. +Its variables will be used by the templates. You can define your own additional variables to use them in templates too. + +It is a MUST to change + +* APP_NAME + +You SHOULD change the portmappings in + +* APP_PORT +* DB_PORT + +Check needed packages and modules in + +* APP_APT_PACKAGES +* APP_PHP_MODULES + +You can change versions + +* APP_PHP_VERSION +* MYSQL_IMAGE + +## Initial config + +```shell +# ====================================================================== +# +# settings for init.sh and base values for replacements in template files +# This script is sourced by init.sh ... this file is bash syntax +# +# ---------------------------------------------------------------------- +# 2021-12-17 <axel.hahn@iml.unibe.ch> +# ====================================================================== + +APP_NAME=my_new_app + +# web port 80 in container is seen on localhost as ... +APP_PORT=8001 + +APP_APT_PACKAGES="git unzip zip" + +#APP_APACHE_MODULES="rewrite" +APP_APACHE_MODULES="" + +APP_PHP_VERSION=8.1 +# APP_PHP_MODULES="curl pdo_mysql mbstring xml zip xdebug" +APP_PHP_MODULES="curl mbstring xml zip xdebug" + +# optional exec command after container was started with init.sh script +# APP_ONSTARTUP="php /var/www/${APP_NAME}/public_html/myservice.php" +APP_ONSTARTUP="" + +# ---------------------------------------------------------------------- + +# add a container with database? +DB_ADD=false + +# ---------------------------------------------------------------------- +# for an optional database server + +DB_PORT=13306 + +# ----- database settings +MYSQL_IMAGE=mariadb:10.5.9 +MYSQL_RANDOM_ROOT_PASSWORD=0 +MYSQL_ALLOW_EMPTY_PASSWORD=0 +MYSQL_ROOT_PASS=12345678 +MYSQL_USER=${APP_NAME} +MYSQL_PASS=mypassword +MYSQL_DB=${APP_NAME} + + + +# ====================================================================== +# ignore things below + + +# where to set acl where local user and web user in container +# can write simultanously +WRITABLEDIR=../public_html + + +# web service user in container +DOCKER_USER_UID=33 + +# document root inside web-server container +WEBROOT=/var/www/${APP_NAME}/public_html + +CUTTER_NO_DATABASE="CUT-HERE-FOR-NO-DATABASE" + +frontendurl=http://localhost:${APP_PORT}/ + +# ---------------------------------------------------------------------- +``` + +## Description + +In alphabetic order: + +| variable | type | description | +|-----------------------------|--------|---------------| +APP_APACHE_MODULES | string | list of additional apache modules in apache container; separated with spaces +APP_APT_PACKAGES | string | list of additional packages in apache container; example: "git unzip zip" +APP_NAME | string | a uniq application name. It will be used as prefix for containers, network and other places. It is a MUST to change it in every new project. +APP_ONSTARTUP | string | optional command to execut if the apache container is up "" +APP_PHP_MODULES | string | list of additional php modules in apache container; separated with spaces; example: "curl mbstring xml zip xdebug" +APP_PHP_VERSION | string | PHP version in apache container; example: 8.1 +APP_PORT | int | port number for your local machine that will be maped to port 80 in the container; Change it if you run multiple projects in parallel; example: 8001 +CUTTER_NO_DATABASE | const | do not change it; the string is used to cut templates from there if no database is used +DB_ADD | bool | flag: do you add a Mariadb container? default: false +DB_PORT | int | port number for your local machine that will be mapped to port 3306 in the container; You can use it in a local db manager; remark: tha apache container needs 3306 and not the mapped port. +DOCKER_USER_UID | int | unix uid of the httpd service user in apache container; it's not needed to change; default: 33 +MYSQL_ALLOW_EMPTY_PASSWORD | int | flag: 0 +MYSQL_DB | string | name of database; defaut is app name ${APP_NAME} +MYSQL_IMAGE | string | image to use; default: mariadb:10.5.9 +MYSQL_PASS | string | mypassword +MYSQL_RANDOM_ROOT_PASSWORD | string | 0 +MYSQL_ROOT_PASS | string | 12345678 +MYSQL_USER | string | ${APP_NAME} +WEBROOT | string | webroot directory inside apache container; default: /var/www/${APP_NAME}/public_html +WRITABLEDIR | string | local webroot directory; default: ../public_html diff --git a/docs/30_Configuration/20_Templates.md b/docs/30_Configuration/20_Templates.md new file mode 100644 index 0000000000000000000000000000000000000000..c1cd7d53ec9349fbd8c96f7f7aafc7cc43fe6de2 --- /dev/null +++ b/docs/30_Configuration/20_Templates.md @@ -0,0 +1,35 @@ +# Basic rules + +* All files in the `docker/templates/` directory will be processed. +* in the first line must be a line `# TARGET: [name of target file]` to define the target file. If this line does not exist, then the file will be skipped. +* Placeholdrs have the syntax variable in double brackets, i.e. `{{VARNAME}}` +* variables to be replaced are those in docker/init.sh.cfg and `{{genrator}}` + +# Templates + +## docker-compose.yml + +Main configuration for docker conposer. + +## dot_env + +The template for `.env` of docker composer. + +## web-server-Dockerfile + +Docker container file for Apache httpd and PHP. +It uses the oficial PHP docker images by default. + +## vhost_app.conf + +Apache vhost configuration for your app. +Setup modules and the vhost including rewrites , ... + +## extra-php-config.ini + +Custom PHP config file for you additional settings. + +## my.cnf + +If you use a Mariadb a 2nd container will be initialized using this my.cnf. + diff --git a/docs/_index.md b/docs/_index.md new file mode 100644 index 0000000000000000000000000000000000000000..7ad29c8d13510f3c7c3eea3ece2ee8f1a63e1603 --- /dev/null +++ b/docs/_index.md @@ -0,0 +1,24 @@ + +# Docker starter kit # + +Free software and Open Source from University of Bern :: IML - Institute of Medical Education + +📄 Source: <https://git-repo.iml.unibe.ch/iml-open-source/docker-php-starterkit> \ +📜 License: GNU GPL 3.0 \ +📖 Docs: <https://os-docs.iml.unibe.ch/docker-php-starterkit/> + +- - - + +## About this template ## + +This template folder brings up a docker container with a PHP 8.x dev environment with Apache httpd2 + mod_php. + +You also can add 2nd container with a Mariadb instance. + + + +The init script + +* sets permisssions for container and local user +* generates needed files for docker from configuration and a set of templates +* starts/ stops your container diff --git a/docs/config.json b/docs/config.json new file mode 100644 index 0000000000000000000000000000000000000000..40f94ed2c567a8834070ea35728366abf5baa8e4 --- /dev/null +++ b/docs/config.json @@ -0,0 +1,25 @@ +{ + "title": "Docker starter kit", + "author": "Axel Hahn", + "tagline": "Bring up a docker container with a PHP 8.x dev environment", + "ignore": { + "files": ["30_PHP-client/Plugins/Checks/_skeleton.md"], + "folders": ["99_Not_Ready"] + }, + "html": { + "auto_toc": true, + "auto_landing": false, + "date_modified": false, + "jump_buttons": true, + "edit_on_github_": "iml-it/__PROJECT__/tree/master/docs", + "edit_on": { + "name": "Gitlab", + "basepath": "https://git-repo.iml.unibe.ch/iml-open-source/docker-php-starterkit/tree/master/docs" + }, + "links": { + "Git Repo": "https://git-repo.iml.unibe.ch/iml-open-source/docker-php-starterkit" + }, + "theme": "daux-blue", + "search": true + } +} \ No newline at end of file diff --git a/docs/images/main_menu.png b/docs/images/main_menu.png new file mode 100644 index 0000000000000000000000000000000000000000..ca709ab3b97e57a63c1853155d517642a4a0b263 Binary files /dev/null and b/docs/images/main_menu.png differ diff --git a/docs/style.css b/docs/style.css new file mode 100644 index 0000000000000000000000000000000000000000..909562cb91d2a8335f4470332ef1e07bdb2ee44c --- /dev/null +++ b/docs/style.css @@ -0,0 +1,176 @@ +/* + + patch css elements of daux.io blue theme + version 2022-05-13 + +*/ + + +/* ---------- vars ---------- */ + +:root{ + + /* background colors */ + --bg:none; + --bg-body: #fff; + --bg-navlinkactive:#f4f4f4; + --bg-navlinkactive: linear-gradient(-90deg,rgba(0,0,0,0), rgba(40,60,80,0.05) 30%); + --bg-pre:#f8f8f8; + --bg-toc: #fff; + + /* foreground colors */ + --color: #234; + --navlinkactive:#f33; + --title: #aaa; + + --link:#12a; + --toclink:rgba(40,60,80,0.8); + + --h1: rgba(40,60,80,0.8); + --h1-bottom: 1px solid rgba(40,60,80,0.1); + --h2: #468; + --h3: #579; + +} + +/* ---------- tags ---------- */ + +a.Brand::before { + background: rgb(255,0,51); + color: #fff; + font-family: arial; + font-weight: bold; + padding: 0.5em 0.3em; + content: 'IML'; + margin-right: 0.4em; +} + +body, *{color: var(--color);} +body{background: var(--bg-body);} + + +a{color: var(--link);} +a:hover{opacity: 0.7;} + +h1>a{ color:var(--title);} +_h1:nth-child(1){position: fixed; background: var(--bg); box-shadow: 0 0 1em #ccc; padding: 0 1em} +h1:nth-child(1)>a{ color:var(--navlinkactive); } + +.s-content h1{color: var(--h1); font-size: 200%; font-weight:bold; margin-top: 2em; border-bottom: var(--h1-bottom);} +.s-content h2{color: var(--h2); font-size: 160%; } +.s-content h3{color: var(--h3); font-size: 140%; } +.s-content h4{margin: 0; font-size: 100%; text-align: center; background-color: rgba(0,0,0,0.05);padding: 0.3em;} + +.s-content pre{ + background: var(--bg-pre); +} + +/* ---------- classes ---------- */ + +.required{color:#a42;} +.optional{color:#888;} + + +/* ----- top left */ +.Brand, +.Columns__left { + background: var(--bg); + border-right: 0px solid #e7e7e9; + color: var(--color); +} +.Brand{font-size: 200%; + background_: linear-gradient(-10deg,#fff 50%, #ddd); + background: var(--bg); +} +.Columns__right__content { + background: var(--bg); +} + +/* ----- Navi left */ + +.Nav a:hover{ + background: none; + color: var(--navlinkactive) !important; +} + +.Nav__item--active { + border-right_: 0.3em solid var(--navlinkactive); +} +.Nav__item--active > a{ + background: var(--bg-navlinkactive); + color: var(--navlinkactive); +} +.Nav .Nav .Nav__item--active a { + color: var(--navlinkactive); +} +.Nav .Nav .Nav__item a { + opacity: 1; +} +.Nav__item--open > a { + background-color: var(--bg); +} + +.Nav a[href*="__Welcome"]{ + background: url("/icons/house.png") no-repeat 10px 4px ; + padding-left: 40px; +} +.Nav a[href*="__How_does_it_work"]{ + background: url("/icons/light-bulb.png") no-repeat 10px 4px ; + padding-left: 40px; +} + + + + +/* ---------- classes ---------- */ + +/* FIX smaller fnt size in tables */ +.s-content table { + font-size: 1em; +} + + +/* TOC */ +@media(min-width:1700px){ + .TableOfContentsContainer{ + position: fixed; + right: 2em; + top: 1em; + } +} + +.TableOfContentsContainer{ + border-top-left-radius: 1em; + background-color: var(--bg-toc); + border-left: 2px solid rgba(0,0,0,0.05); + padding: 0em; +} +.TableOfContentsContainer__content { + + border: none; + font-size: 0.5em; + +} +ul.TableOfContents ul{ + list-style-type: none; + padding-left: 1em; +} +.TableOfContentsContainer a{ color:var(--toclink);} + +.TableOfContentsContainer__content > .TableOfContents > li + li { + border-top: none; +} +.TableOfContentsContainer__content > .TableOfContents > li { + border-bottom: 1px dashed #ddd; +} + +/* pager - prev .. next */ +.s-content{ + margin-bottom: 6em; +} +.Pager{ + border-top: 1px dashed #aaa; margin: 0; padding: 1em; +} +.Pager a{ + color:var(--navlinkactive); +} diff --git a/readme.md b/readme.md index 0b94813de1c7068625d3aadbdfb7462f27a44ba6..cc35ae79bd819d5d3f651f0f87517ed9383e2d97 100755 --- a/readme.md +++ b/readme.md @@ -1,78 +1,18 @@ -# PHP App Template # +# Docker starter kit # Free software and Open Source from University of Bern :: IML - Institute of Medical Education -Repo: <https://git-repo.iml.unibe.ch/iml-open-source/docker-php-starterkit> +📄 Source: <https://git-repo.iml.unibe.ch/iml-open-source/docker-php-starterkit> \ +📜 License: GNU GPL 3.0 \ +📖 Docs: <https://os-docs.iml.unibe.ch/docker-php-starterkit/> - - - ## About this template ## -This template folder brings up a docker container with a PHP 8.1 dev environment with Apache httpd2 + mod_php. +This template folder brings up a docker container with a PHP 8.x dev environment with Apache httpd2 + mod_php. You also can add 2nd container with a Mariadb instance. -The subdir ```./public_html/``` will be mounted as webroot that you can edit files locally which are visible inside the container too. - -## Requirements ## - -* Docker Non-root installation - see <https://docs.docker.com/engine/security/rootless/> - -## How to use this template ## - -### Create a new project folder ### - -Copy folder to a new name: ```cp -r template-php my-new-php-app; cd my-new-php-app``` - -The initial file structure looks like this: - -```txt -. -├── docker # Docker data -│ ├── init.sh << shellscript for initialization -│ ├── init.sh.cfg << config file -│ └── templates << folder with templates -│ ├── docker-compose.yml -│ ├── dot_env -│ ├── extra-php-config.ini -│ ├── my.cnf -│ ├── readme.md -│ ├── vhost_app.conf -│ └── web-server-Dockerfile -├── public_html # your webroot for your project -│ └── index.php -└── readme.md -``` - -### Edit variables and files ### - -* edit ```./docker/init.sh.cfg``` ... and edit - * ```APP_NAME=my_new_app``` - * optional: set a new port ```APP_PORT=8001``` - * set APP_* variables for packages to install or PHP version - * set DB_ADD to true or false to say if a database container is needed - * If a database is needed then set DB_PORT and MYSQL_* variables -* edit ```./docker/templates/vhost_app.conf``` to describe apache vhost config -* edit php settings in ```./docker/templates/extra-php.ini``` -* edit mysql settings in ```./docker/templates/my.cnf``` - -### First start ### - -* start init script in the docker folder: ```./docker/init.sh``` - * use "g" to remove git data of the starterkit - * use "i" for init ... it sets an ACL on the ./public_html/ subdir to allow write access for your current user and the apache user in the docker container - * use "t" to generate config files from templates with the settings from ./docker/init.sh.cfg - * use "u" to bring up the container (OR run ```docker-compose up -d``` ) - -### Edit files ### - -* If the container was started you can ... - * open in your browser http://localhost:8001 to access ```./public_html/``` - * edit files with the IDE of your choice - -### Remarks ### - -You can start ./docker/init.sh with a single letter in the interactive menu too, i.e. ```./docker/init.sh u``` to bring up the docker instance. - -If you created the config files from templates you can repeat the creation ```./docker/init.sh t```. Before applying a change you should shutdown your docker instance. +