A lightweight PHP server for storing and serving IIIF manifests, built for the Bibliotheca Hertziana. Manifests are linked to research publications managed in OJS. Public read access is open; write and delete operations require authentication. All manifests are validated against the IIIF Presentation Validator before storage.
This repository is a sanitized public release derived from the institution's internal development history. Commit history was reset to remove internal artifacts; it does not reflect the full development record of the original project.
- Architecture
- Project Structure
- Configuration
- Installation
- Server Management
- Authentication
- API Reference
- Testing
- PHP cURL Examples
- Credits
- Funding
- License
The system runs in a 4-container Docker environment:
| Container | Role |
|---|---|
| web (nginx) | Frontend — serves static files, rewrites API URLs |
| php-fpm | PHP 8.3 application engine |
| mysql | Stores API keys and manifest metadata |
| validator | Python IIIF Presentation Validator service |
API endpoints are exposed as clean REST URLs via Nginx URL rewriting. Requests to /api/v1/{endpoint} are internally routed to /api/v1/rest.php?resource={endpoint}.
Manifests are stored on disk under docker/iiif_manifests/{series}/{volume}/{manifest_name} and served directly by nginx.
PubLinkSMS/
├── docker/
│ ├── init.sh # First-time setup wizard (Linux/Mac)
│ ├── init.bat # First-time setup wizard (Windows)
│ ├── init.cfg # Saved defaults for the setup wizard
│ ├── .env # Generated by init — read by Docker Compose (not committed)
│ ├── deploy.sh / deploy.bat # Rebuild containers, preserving the database volume
│ ├── start.sh / start.bat # Rebuild and start containers, restoring DB backup
│ ├── stop.sh / stop.bat # Back up database, then stop and tear down containers
│ ├── restart.sh / restart.bat # Equivalent to stop then start
│ ├── db_backup/manifest_server.sql # Database backup (created by stop/start/restart)
│ ├── docker-compose.yml
│ ├── composer.json # PHP dependencies — autoloads docker/src/
│ ├── nginx/nginx.conf # URL rewriting rules
│ ├── php/
│ │ ├── php-fpm-entrypoint.sh # Generates config.ini from env vars at startup
│ │ ├── php.ini
│ │ └── www.conf
│ ├── src/ # Application source (installed inside the php-fpm image)
│ │ ├── api/
│ │ │ ├── BaseController.php # Base class with shared API methods
│ │ │ ├── ApiController.php # Implements putManifest and removeManifest
│ │ │ ├── ApiUser.php # Utility class for calling the API programmatically
│ │ │ └── IIIFValidator.php # Wraps the IIIF validator service
│ │ ├── om/
│ │ │ ├── ApiKey.php # API key model (validate, create, revoke)
│ │ │ ├── ApiEndpoint.php # API endpoint model
│ │ │ └── ManifestServerObject.php
│ │ ├── pages/
│ │ │ ├── htmlPage.php # Static methods for rendering web components
│ │ │ ├── Manifest_Server_Page.php # Web page template used by the UI
│ │ │ ├── Modal_Alert.php # Alert modal component
│ │ │ └── Modal_Confirm.php # Confirmation modal component
│ │ ├── test/
│ │ │ ├── UnitTest.php # PHPUnit tests (upload / read / delete)
│ │ │ └── manifest.txt # Sample manifest for testing
│ │ ├── utilities/
│ │ │ └── PDODatabase.php # PDO database wrapper
│ │ ├── Config.php # Global settings (reads config.ini)
│ │ └── config.ini # Auto-generated at container startup — do not edit
│ ├── html/
│ │ ├── index.html # Homepage
│ │ ├── upload.html # Web form (upload / delete manifests)
│ │ ├── api_keys.html # API key management interface
│ │ ├── viewer.html # IIIF manifest viewer
│ │ ├── api/v1/rest.php # API entry point
│ │ └── api/docs/ # OpenAPI documentation (Swagger UI)
│ └── validator/ # IIIF validator source and requirements
└── api_test/
├── postData.php # cURL script to test manifest upload
└── removeManifest.php # cURL script to test manifest deletion
Note: There is no functional bare-metal deployment path — everything runs through the
docker/tree above. (An earlier version of this repo also had a root-levelcomposer.json/composer.lockreferencing asrc/directory that no longer exists anywhere in the project; those were unused leftovers from before this was dockerized.)
Configuration is managed through three files:
Edit this file to pre-fill values the next time you run init.sh or init.bat. The database password is never stored here — it is always freshly generated by init.
FILE_STORE_URL=https://your-server.example.org/iiif_manifests
API_USERNAME=manifest_api_user
API_PASSWORD=your_password
VALID_SERIES=HSAH,MRAS,ARTB,JMHIS,annotations
FLEXIBLE_SERIES=
Created automatically by init.sh / init.bat. Docker Compose reads this file and passes the values to the containers as environment variables. Do not commit this file to version control.
Written by php/php-fpm-entrypoint.sh from the environment variables every time the php-fpm container starts. Do not edit this file — any changes will be overwritten on the next restart. To change a setting, update init.cfg, re-run init, and rebuild.
- Docker Engine with the Compose plugin (the setup scripts run
docker compose ..., not the standalonedocker-composev1 binary)
-
Clone the repository:
git clone <repo-url> cd PubLinkSMS/docker
-
Edit
init.cfgto set your defaults (series names, external URL, etc.). -
Run the setup wizard:
# Linux / Mac bash init.sh # Windows init.bat
The wizard prompts for any missing values, generates a random database password, writes
.env, and starts the containers. -
The server will be available at the URL you configured (default:
http://localhost).
Reconfiguring: Re-run
init.sh/init.batto change settings and rebuild. Runinit.shafter pulling code updates to apply them. Your stored manifests are preserved indocker/iiif_manifests/. The database (API keys) is wiped and must be restored — userestart.shinstead if you only need to rebuild without changing settings.
After the initial install, use these scripts from the docker/ directory instead of running init again. They preserve the API key database across rebuilds.
| Script | What it does |
|---|---|
deploy.sh / deploy.bat |
Rebuild all containers without wiping the database volume — use for code updates |
stop.sh / stop.bat |
Dump the database to db_backup/manifest_server.sql, then tear down all containers and volumes |
start.sh / start.bat |
Tear down, rebuild all containers, then restore the database from backup |
restart.sh / restart.bat |
Equivalent to running stop then start (full teardown with DB backup/restore) |
# Linux / Mac
bash deploy.sh # deploy code changes (database preserved in volume)
bash stop.sh # safe shutdown with DB backup
bash start.sh # rebuild and restore from backup
bash restart.sh # stop + start in one step
# Windows
deploy.bat
stop.bat
start.bat
restart.batDatabase backup is written to db_backup/manifest_server.sql on every stop/start/restart. A single file is kept (the most recent run overwrites the previous). The manifest JSON files in iiif_manifests/ are never touched by these scripts.
If MySQL is not running when a script starts (e.g. after
stop.sh), the backup step is skipped and restore proceeds from the last saved file.
The API supports two authentication methods. API keys are preferred.
API keys are managed through the web interface at /api_keys.html. Each key can be scoped to specific endpoints (putManifest, removeManifest). Keys are bcrypt-hashed in the database — the raw value is only shown once at creation.
Send the key in the X-API-Key request header:
X-API-Key: your-api-key-here
Username and password set via API_USERNAME / API_PASSWORD in init.cfg. Accepted if no X-API-Key header is present. Set API_PASSWORD in init.cfg and re-run init to change it.
POST /api/v1/putManifest
| Field | Type | Description |
|---|---|---|
series |
string | Series name — must match an entry in VALID_SERIES |
volume |
string | Two-digit volume number e.g. "01", or any alphanumeric string for flexible series |
manifest_name |
string | Filename for the stored manifest e.g. "manifest.json" |
manifest |
string | The full IIIF manifest JSON |
ignore_mismatch |
bool | Ignore @id vs validator address mismatches — set true in Docker environments |
ignore_overwrite |
bool | If true, overwrite an existing manifest with the same name |
Standard series accept a two-digit volume ("01", "02", …).
Flexible series (configured in FLEXIBLE_SERIES) accept any lowercase alphanumeric string with hyphens or underscores e.g. "philosophy", "category-x".
The manifest is validated by the IIIF Presentation Validator before being written to disk.
POST /api/v1/removeManifest
| Field | Type | Description |
|---|---|---|
url |
string | Full URL of the manifest to delete |
Browse and test the API interactively at http://localhost/api/docs/index.html.
Upload and delete manifests via the browser at http://localhost/upload.html.
The scripts in api_test/ read their settings from src/config.ini. Set api_key in that file, then run from the project root:
php api_test/postData.php
php api_test/removeManifest.phpEdit $payload in each script to set the series, volume, and manifest name.
Run inside the php-fpm container:
docker exec php-fpm /var/www/vendor/bin/phpunit /var/www/src/test/UnitTest.phpThe three tests:
- Upload a known manifest
- Read it back and verify its contents
- Delete it
Tests use the first entry in VALID_SERIES, volume 99, and filename manifest.json.
$payload = json_encode([
'series' => 'annotations',
'volume' => '01',
'manifest_name' => 'manifest.json',
'manifest' => $manifestJson,
'ignore_mismatch' => true,
'ignore_overwrite' => true,
]);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://your-server.example.org/api/v1/putManifest');
curl_setopt($curl, CURLOPT_HTTPHEADER, ['X-API-Key: your-api-key-here']);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(['data' => $payload]));
curl_setopt($curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
$output = curl_exec($curl);
curl_close($curl);$payload = json_encode([
'url' => 'https://your-server.example.org/iiif_manifests/annotations/01/manifest.json',
]);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://your-server.example.org/api/v1/removeManifest');
curl_setopt($curl, CURLOPT_HTTPHEADER, ['X-API-Key: your-api-key-here']);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(['data' => $payload]));
curl_setopt($curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
$output = curl_exec($curl);
curl_close($curl);Nginx body size: The nginx config sets
client_max_body_size 50Mto allow large manifests (default is 1 MB). Adjust indocker/nginx/nginx.confif needed.
Originally developed by Chris Tomlinson (@hawkenbury), with contributions from Carlo Teo Pedretti (@friendlynihilist).
The development of the PubLink platform was made possible by a grant from the Deutsche Forschungsgemeinschaft (DFG) — Project number 501142032.
MIT — see LICENSE.