PHP App Template
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
About this template
This template folder brings up a docker container with a PHP 8.1 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:
.
├── 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 editAPP_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
- open in your browser http://localhost:8001 to access
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.