/php-api

A simple PHP Api boilerplate

Primary LanguagePHP

PHP API boilerplate

A PHP boilerplate for create simple API without the needing of extra bloat

Overview

  • No framework but only needed
  • PHP as an Apache module
  • MariaDb/MySql database integration
  • Propel ORM for model creation
  • Api-Key authentication
  • Docker Swarm ready with secrets *_FILE env variables

Setup

  1. Install Docker
  2. Build development environment
# Setup your environment stuff in docker-compose.yml file than
docker-compose build
sh scripts/composer.sh install
docker-compose up
  1. Start coding

Tools

Composer

sh scripts/composer.sh COMPOSER_COMMAND

Database

I use Propel ORM, it's fairly simple to use once you setup it (hopefully this template get the job done).

How to (starting from scratch)

# Start environment
docker-compose up

# Define your database structure (MySql or MariaDb) in `schema.xml`

# Create the db import structure
mkdir sql && sh scripts/propel.sh sql:build

# Insert the new structure to the actual database
sh scripts/propel.sh sql:insert

# Build PHP model upon structure
sh scripts/propel.sh build

How to (after machine change or for new dev)

# Start environment
docker-compose up

sh scripts/propel.sh sql:insert
sh scripts/propel.sh migrate

How to (build updates)

# Start environment
docker-compose up

# Change your schema accordingly than
# Create a migration file for updating production stuff
sh scripts/propel.sh diff

# Build updated models
sh scripts/propel.sh build

# Update db structure
sh scripts/propel.sh migrate

# If something goes wrong after migration or you unsatistied with it
sh scripts/propel.sh migration:down # As many time as you want

Official Propel website

TODO

  • Write production stuff readme
  • APCU stuff for production environment
  • Make possible to use a db connection string for remote connections