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
-
Clone this repository
git clone https://github.com/mccheesy/php-docker.git`
- 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
- Build and run the containers (in detached mode)
docker-compose up -d
-
Create cert files for https://app.test. For example:
mkcert -install
mkcert app.test "*.app.test"
mv *.pem ./nginx/ssl/
-
Edit line 50 of docker-compose.yml: change server.conf to server-ssl.conf
-
Rebuild the Nginx container
docker-compose up -d --build nginx
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.
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 [email protected].