GithubHelp home page GithubHelp logo

turnkey-website-php-laravel-postgresql's Introduction

PHP+nginx+PostgreSQL+pgAdmin on Docker in 2019

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: Build Status. 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.

What's in the box

  • 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 Makefile commands (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)

How to use

  • Clone this repo
  • make serve to build and serve
  • make composer-update on the first run
  • make test to run unit and integration tests

Pain points solved

  • 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 for artisan (solution: appropriate alias)
  • Running composer install in the Dockerfile was shadowed by the volume mapping the source to the host (solution: separate command in Makefile, required once only)
  • Simultaneously running make serve and make test on 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.internal on Linux)

*(lacks CI) **(lacks DB)

Remarks

  • Host should run VSCode (XDEBUG config is given), have PHP set for linting

  • Laravel uses artisan to 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 9001 on host (to be run in VSCode, and started before loading the page)

  • website/data/storage should allow "others" to write

  • php artisan key:generate regenerates secret keys for app-level crypto

  • php artisan config:cache flushes 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

turnkey-website-php-laravel-postgresql's People

Contributors

danhaji3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.