PHP-CRUD-API is an “automatic” API: software that turns your database into a REST API. This is possible thanks to database reflection (asking the database which tables and fields it has). Support for Docker and Docker Compose has been added and the Docker image is registered on Docker Hub.

Test using Docker

To do proper testing you may have to test the full matrix of all dependencies (PHP, MySQL, MariaDB, PostgreSQL, SQLite and SQL Server) and there corresponding versions. For PHP there are already 5 supported versions (7.0, 7.1, 7.2, 7.3 and 7.4), for MySQL there are 3 supported versions (5.6 5.7 and 8.0) and for PostgreSQL there are 9 supported versions (9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 10, 11 and 12). Only these combinations of these major versions would lead to 5 x 3 + 5 x 9 = 50 test runs.

In reality there are minor versions and many other dependencies (such as PostGIS). This makes that the number of combinations is growing rapidly and testing them all is unfeasible. Instead we would like to test only the most common combinations of versions. We find them by using the repository contents of certain versions of Linux distributions. Below you find the distributions with their repository versions:

  • Ubuntu 16.04 with PHP 7.0, MariaDB 10.0, PostgreSQL 9.5 (PostGIS 2.2) and SQL Server 2017
  • Debian 9 with PHP 7.0, MariaDB 10.1, PostgreSQL 9.6 (PostGIS 2.3) and SQLite 3.16
  • Ubuntu 18.04 with PHP 7.2, MySQL 5.7, PostgreSQL 10.4 (PostGIS 2.4) and SQLite 3.22
  • Debian 10 with PHP 7.3, MariaDB 10.3, PostgreSQL 11.4 (PostGIS 2.5) and SQLite 3.27
  • Ubuntu 20.04 with PHP 7.4, MySQL 8.0, PostgreSQL 12.2 (PostGIS 3.0) and SQLite 3.31
  • CentOS 8 with PHP 7.4, MariaDB 10.4, PostgreSQL 12.2 (PostGIS 3.0) and SQLite 3.26

These can be tested in only 6 x 3 = 18 test runs and the number is not growing at all! This also means that (for instance) PHP 7.1 is not tested, nor is PostgreSQL 9.4.

Install Docker on Ubuntu

Install docker using the following commands:

sudo apt install docker.io
sudo usermod -aG docker ${USER}

Note that you need to logout and login for the changes to take effect.

Official Docker image

There is a “Dockerfile” in the repository that is used to build an image at:

https://hub.docker.com/r/mevdschee/php-crud-api

It will be automatically build on every release. The “latest” tag points to the last release.

Run with Docker Compose

This repository also contains a “docker-compose.yml” file that you can install/build/run using:

sudo apt install docker-compose
docker-compose build
docker-compose up

This will setup a database (MySQL) and a webserver (Apache) and runs the application using the blog example data used in the tests.

Test the script (running in the container) by opening the following URL:

http://localhost:8080/records/posts/1

Enjoy!