This project was built with php SLIM 4 framework with ADR mode, whcich is a compatible resolution of RESTful Api.
- Framework - SLIM 4
- Container - Docker
- Test - Codeception
- Api Document - Swagger-ui
- ORM - Medoo
- CI/CD - Github Actions
- docker/docker-compose
- php: >=8.0
- composer
Run this command from the directory in which you want to install your new Slim application. You will require PHP 8.0 or newer.
composer create-project poabob/slim-4-framework [my-app]
- Write your Db schema
init.sql
CREATE DATABASE IF NOT EXISTS Example;
USE Example;
CREATE TABLE IF NOT EXISTS `Example`.`Users` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT , `name` VARCHAR(64) NOT NULL, `password` VARCHAR(64) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
- DB config
If you use sqlite for your database, juse commit mysql config.
docker-compose.yml
mysql:
...
environment:
- MYSQL_DATABASE={DB}
- MYSQL_ROOT_PASSWORD={root_password}
- MYSQL_USER={user}
- MYSQL_PASSWORD={user_password}
- Generate Secret Key for Jwt
# Generate PRIVATE KEY
openssl genrsa -out private.pem 2048
# Generate PUBLIC KEY
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
- .env configuration
If you use sqlite for your database, just commit mysql config.
# dev/prod/stage/test
MODE=dev
# MYSQL CONFIG
DB_DRIVER=mysql
DB_NAME={DB}
DB_HOST=mysql
DB_USER={user}
DB_PASS={user_password}
DB_CHARSET=utf8mb4
# SQLITE CONFIG
# DB_DRIVER=sqlite
# DB_NAME={./path/Example.db}
# SETTINGS FOR DEBUG (0/1)
# please don't display error details in production environment.
DISPLAY_ERROR_DETAILS=1
LOG_ERROR_DETAILS=1
LOG_ERRORS=1
# JWT SETTINGS
JWT_ISSUER=SLIM_4
JWT_LIFETIME=86400
JWT_PRIVATE_KEY="{PRIVATE KEY}"
JWT_PUBLIC_KEY="{PUBLIC KEY}"
composer install
composer run start
composer install --no-dev --optimize-autoloader
composer run start
<!-- Before you test, please check out your vendor which was instlled. -->
composer run test