Skip to content

Simple docker compose orchestration for local PHP development

License

Notifications You must be signed in to change notification settings

mccheesy/php-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-docker

php-docker is a simple docker-compose orchestration that sets up a three- container network for local PHP development (Laravel, Symfony, Slim, etc). With this repo, you get:

  • PHP container
    • Builds custom from php:7.4-fpm-alpine
    • Adds a bunch* of PHP extensions
    • Installs curl, vim, and composer for convenience
    • Maps ./src to /var/www
    • Uses PHP-FPM running on :9000
  • Nginx container
    • Uses nginx:latest
    • Supports use of mkcert for local SSL (see SSL below)
    • Listens on port 80 (for convenience)
  • Mariadb container
    • Uses mariadb:latest
    • Stores data in ./mariadb/
    • Inits from vars in docker-compose.yml

* see Dockerfile

Usage

  1. Install Docker CE

  2. Install Docker Compose

  3. Clone this repository

git clone https://github.com/mccheesy/php-docker.git`
  1. Either copy your existing PHP application source to the src directory or create a new project. Since you have Docker installed, you can create a new Laravel project using the Composer container thus:
docker run --rm --it \
    --volume $PWD:/app \
    --user $(id -u):$(id -g) \
    composer create-project --prefer-dist laravel/laravel src
  1. Build and run the containers (in detached mode)
docker-compose up -d

For SSL [Optional]

  1. Install mkcert

  2. Create cert files for https://app.test. For example:

mkcert -install
mkcert app.test "*.app.test"
mv *.pem ./nginx/ssl/
  1. Edit line 50 of docker-compose.yml: change server.conf to server-ssl.conf

  2. Rebuild the Nginx container

docker-compose up -d --build nginx

Hosts

If you are used to something like Valet, this can be a little tedious. I just use the same test domain (app.test) for all my sites and keep only one of these container networks running at a time.

If you have a need to add multiple subdomains or domains, you will just need to adjust your hosts file and the Nginx/docker-compose files and rebuild the containers.

Contact

I do not claim to be an expert on Docker, Docker Compose, or container orchestration, but if you have any questions or run into any issues, I'm happy to offer whatever help I can supply. I can be reached via email at jmccleese@gmail.com.

About

Simple docker compose orchestration for local PHP development

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published