A super light docker web server with nginx and php-fpm on top of Alpine Linux for development purposes
- nginx 1.18.0 with SSL
- php-fpm 7.4.12
- Xdebug debugging from host
- Xdebug profiler
- composer
- zsh
The docker image size is 43 MB.
- nginx and php configuration files are exposed on the host.
- Just works with any domain name.
- https is configured out of the box.
- All changes to the config files are automatically applied (hot reload).
- Xdebug is configured for remote debugging (no headaches).
Starting the container with docker-compose
offer all container functionalities.
docker-compose up
CTRL-Z to detach
docker-compose stop
Alternatively the container can also be started with docker run
.
docker run -p 80:80 --name web 8ct8pus/nginx-php-fpm-alpine:latest
CTRL-Z to detach
docker stop container
http://localhost/
https://localhost/
The source code is located inside the html
directory.
To set the domain name to www.test.com, edit the environment variable in the docker-compose file
environment:
- DOMAIN=www.test.com
Add this line to the system host file. Editing the file requires administrator privileges.
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 test.net www.test.net
To remove "Your connection is not private" nag screens, import the certificate authority file under ssl/certificate_authority.pem in the browser's certificates under Trusted Root Certification Authorities.
This github repository is configured to debug php code in Visual Studio Code.
To start debugging, open the VSCode workspace then select Run > Start debugging
then open the site in the browser.
For other IDEs, set the Xdebug debugging port to 9001.
The docker image is configured to profile php code.
To start profiling, add the XDEBUG_PROFILE
variable to the request as a GET, POST or COOKIE.
http://localhost/?XDEBUG_PROFILE
Profiles are stored in the log directory.
docker exec -it web zsh
docker build -t nginx-php-fpm-alpine:dev .
In this example, we add the php-curl extension.
docker-compose up --detach
docker exec -it web zsh
apk add php-curl
exit
docker-compose stop
docker commit web nginx-php-fpm-alpine-curl:dev
To use the new image, update the image link in the docker-compose file.
https://php-fpm.org/about/
In Windows hot reload doesn't work with WSL 2, you need to use the legacy Hyper-V.