Introduction
php-sync-tool is a PHP CLI tool for synchronizing MySQL, MariaDB or PostgreSQL databases — and optionally files — between systems over SSH. It automatically extracts database credentials from popular PHP frameworks and supports a range of sync modes for different use cases.
It is a PHP port of the Python db-sync-tool, designed to run wherever PHP already runs, without an additional Python runtime.
Features
- Database sync from and to remote systems
- MySQL (>= 5.5)
- MariaDB (>= 10.0)
- PostgreSQL
- Proxy mode between two remote systems (two-hop transfer)
- Nine synchronization modes selected automatically from your config
- Automatic database credential detection for supported frameworks:
- File synchronization alongside or instead of the database
- Dump creation (database backup) with optional retention/cleanup
- Lifecycle scripts (before / after / error) and post-import SQL
- Structured logging (plain or JSON) for CI and log aggregation
- Many more configuration options
Requirements
- PHP 8.2 or higher (
~8.2 || ~8.3 || ~8.4 || ~8.5) mysql/mysqldump(orpsql/pg_dumpfor PostgreSQL) andgzip/gunzipon the executing host(s)rsyncfor the default transfer method (SFTP is used automatically as a fallback)- Optionally
sshpassfor password-based rsync - SSH access to remote systems (for remote syncs)
How It Works
- Resolve configuration — origin and target are read from a config file, host definitions, or CLI arguments.
- Detect credentials — for a supported framework, database credentials are parsed from its config file (locally or over SSH).
- Export — a gzip-compressed
mysqldump(orpg_dumpfor PostgreSQL) is created on the origin system. - Transfer — the dump is moved via rsync (or SFTP fallback, or a local proxy).
- Import — the dump is imported on the target system.
- Finalize — post-import SQL runs, lifecycle scripts fire, and temporary files and credential files are cleaned up.
Next Steps
- Installation — get php-sync-tool installed
- Quick Start — your first database sync
- Framework Guides — framework-specific setup