nik2208 / php-crud-api-quick-start

A ready to go, customizable, docker stack for PHP-CRUD-API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP-CRUD-API QUICK START

A customizable, ready-to-go, Docker Compose file featuring

  • PHP-CRUD-API
  • MySQL
  • PHP-FPM
  • NGINX
  • ADMINER
  • SWAGGER (OPENAPI)

INSTALLATION:

Just pull the repo git clone https://github.com/nik2208/php-crud-api-quick-start.git && cd php-crud-api-quick-start, rename the file .env.sample into .env and set the environment values to suite your needs:

#rename to .env
# NGINX EXPOSED PORT: THE PORT WHERE YOU WANT YOUR DOCKER STACK TO LISTEN.
PORT=8080

# API SUBDOMAIN (DNS RECORD A) OR HTTP(S)://IP_ADDRESS:PORT/ IF LOCALLY DEPLOYED
# IF YOU DON'T HAVE AN FQDN (FULLY QUALIFIED DOMAIN NAME) AND YOU USE AN IP ADDRESS
# (WHETHER PUBLIC OR PRIVATE), THE ADDRESS MUST CONTAIN THE STACK-EXPOSED PORT AS
# CONFIGURED IN THE PREVIOUS STEP.
SERVER_NAME=http://127.0.0.1:8080/

###########################################
#DATABASE PARAMETERS
MYSQL_ROOT_PASSWORD=samplepassword
MYSQL_DATABASE=sampledb
MYSQL_USER=sampleuser
MYSQL_PASSWORD=samplepassword

###########################################
#API.PHP PARAMETERS
#DEBUG MODE
PHP_CRUD_API_DEBUG=true

Then run docker compose up -d. Enjoy!🎉🚀 Refer to PHP-CRUD-API for further customizations.

REQUIREMENTS:

In case your running your instance on localhost and your selected port is 8080 Your tests table will be available at http://127.0.0.1:8080/records/tests (no need of explicit api.php)1 Your MYSQL ADMIN instance will be available at http://127.0.0.1:8080/dbadmin/ Your SWAGGER instance will be available at http://127.0.0.1:8080/swagger/

Change ip and port accordingly if host and port differ.

REQUIREMENTS FOR THE INSTANCE TO BE REACHED OVER THE WEB

  • Any host running Docker and Docker Compose.
  • A FQDN (Fully Qualified Domain Name), a public IP, a reverse proxy to forward YOUR A RECORD requests (e.g. api.exemple.com) to your Docker host2.

Your tests table will be available at https://api.example.com/records/tests (no need of explicit api.php)1 Your MYSQL ADMIN instance will be available at https://api.example.com/dbadmin/ Your SWAGGER instance will be available at https://api.example.com/swagger/

PERSISTENCY

After starting the Docker containers using docker-compose up -d, the MySQL database will be created and stored in the mysql folder of the cloned project. This folder is used to persist the database data between container restarts. It is important to regularly back up this folder to avoid data loss.

GITLAB CI/CD

A .gitlab-ci.yml file is provided.3

The CI/CD flow expects to find a cloned repository on the deploying host, and the .env file properly set for that specific host/environment. The provided Gitlab pipeline encompasses three branches, related to three hosts/environments:

  • develop
  • staging
  • prod

Merges into develop will update the development environment, merges into staging will update the staging environment, a commit tag will update the production environment.

Footnotes

  1. After your first deployment the database will be empty. 2

  2. Minimal networking knowledge is required.

  3. Requires Gitlab CI/CD knowledge and Gitlab variables properly set.

About

A ready to go, customizable, docker stack for PHP-CRUD-API


Languages

Language:Dockerfile 100.0%