This code is a template for a PHP website (Laravel served via nginx and php-fpm) along with its database (PostgreSQL+pgAdmin).
It just works: . Clone and get started.
Why? Because this has been surprisingly time-consuming to setup (see the "pain points" below), and it really shouldn't be.
- Minimal website with Laravel, served via nginx and php-fpm, all wired up through docker-compose
- PostgreSQL+pgAdmin
- Source code + DB files mapped to host through Docker volumes
- Simplified dev cycle through
Makefilecommands (make serve,serve-dev,test-unit,test-integration, etc) - Composer to manage PHP libraries
- Working CI setup with Travis for unit tests, plus...
- Dusk/Selenium for integration-tests, which runs on Travis and uploads failing screenshots to imgur
- Working XDEBUG setup for VS Studio Code/PHPStorm (so you can debug with breakpoints)
- Clone this repo
make serveto build and servemake composer-updateon the first runmake testto run unit and integration tests
- No turnkey setup available: either partial* solutions**, or many blog posts which I had to painfully combine to get this setup
- PostgreSQL creates files as root, which conflicts with docker build (solution: appropriate
.dockerbuild). Similar problem forartisan(solution: appropriate alias) - Running
composer installin theDockerfilewas shadowed by the volume mapping the source to the host (solution: separate command inMakefile, required once only) - Simultaneously running
make serveandmake teston Travis (solution: script to busy-wait on container) - Getting Dusk/Selenium's output on failures on Travis (solution: a script to copy to stdout and upload screenshots to imgur)
- Getting the PHP container to connect to XDEBUG on host (solution: a hack to fix
host.docker.internalon Linux)
*(lacks CI) **(lacks DB)
-
Host should run VSCode (XDEBUG config is given), have PHP set for linting
-
Laravel uses
artisanto build things. This should be called inside the docker -
Website runs on port
8080 -
PGAgmin runs on port
8081 -
PHP-Fpm runs on port
9000 -
XDebug should run on
9001on host (to be run in VSCode, and started before loading the page) -
website/data/storageshould allow "others" to write -
php artisan key:generateregenerates secret keys for app-level crypto -
php artisan config:cacheflushes and rebuilds the config cache
// Magic php cache rebuid thing composer dump-autoload
// Create a model with migration
// Rebuild db php artisan migrate:refresh (eventuellement --seed)
// Create a seed php artisan make:seeder SectionsTableSeeder
// Create a test in the Feature directory... php artisan make:test UserTest
// Create a test in the Unit directory... php artisan make:test UserTest --unit