Apache and php-fpm on top of Alpine Linux for development
10K+
A super light docker web server with Apache and php-fpm on top of Alpine Linux for php developers.
docker-compose.yml8.4 is the default flavor, to use php 8.3, 8.2, 8.1, 8.0 or 7.4, select the image in docker-compose.ymlDocker Desktop and run docker-compose uphttp://localhost/sites/localhost/html/public/Note: On Windows file changes notification to the container doesn't work with the WSL 2 engine, you need to use the Hyper-V engine. Uncheck Use WSL 2 based engine. What this means, is that files you update on Windows are not updated inside the container unless you use Hyper-V.
Note: If you need a fully-fledged development environment, checkout the php sandbox project.
Starting the container with docker-compose offers all functionalities.
# start container in detached mode on Windows in cmd
start /B docker-compose up
# start container in detached mode on linux, mac and mintty
docker-compose up &
# view logs
docker-compose logs -f
# stop container
docker-compose stop
# delete container
docker-compose down
Alternatively the container can also be started with docker run.
# php 8.4
docker run -p 80:80 -p 443:443 --name web 8ct8pus/apache-php-fpm-alpine:2.4.1
# php 8.3
docker run -p 80:80 -p 443:443 --name web 8ct8pus/apache-php-fpm-alpine:2.3.3
# php 8.2
docker run -p 80:80 -p 443:443 --name web 8ct8pus/apache-php-fpm-alpine:2.1.3
CTRL-C to stop
There are 2 sites you can access from your browser
http(s)://localhost/
http(s)://(www.)test.com/
The source code is located inside the sites/*/html/public/ directories.
Setting a domain name is done by using virtual hosts. The virtual hosts configuration files are located in sites/config/vhosts/. By default, localhost and test.com are already defined as virtual hosts.
For your browser to resolve test.com, add this line to your system's host file. Editing the file requires administrator privileges.
On Windows: C:\Windows\System32\drivers\etc\hosts
Linux and Mac: /etc/hosts
127.0.0.1 test.com www.test.com
A self-signed https certificate is already configured for localhost and test.com.
To remove "Your connection is not private" nag screens, import the certificate authority file sites/config/ssl/certificate_authority.pem to your computer's Trusted Root Certification Authorities then restart your browser.
In Windows, open certmgr.msc > click Trusted Root Certification Authorities, then right click on that folder and select Import... under All Tasks.
On Linux and Mac: [fill blank]
For newly created domains, you will need to create the SSL certificate:
docker-exec -it web zsh
selfsign certificate /sites/domain/ssl domain.com,www.domain.com,api.domain.com /sites/config/ssl
Note: Importing the certificate authority creates a security risk since all certificates issued by this new authority are shown as perfectly valid in your browsers.
This 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.
The default config is to stop on entry which stops at the first line in the file. To only stop on breakpoints, set stopOnEntry to false in .vscode/launch.json.
For other IDEs, set the Xdebug debugging port to 9001.
To troubleshoot debugger issues, check the sites/localhost/logs/xdebug.log file.
If host.docker.internal does not resolve within the container, update the xdebug client host within docker/etc/php/conf.d/xdebug.ini to the docker host ip address.
xdebug.client_host = 192.168.65.2
Code profiling comes in 2 variants.
Note: Disable Xdebug debugger xdebug.remote_enable for accurate measurements.
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 and can be analyzed with tools such as webgrind.
Whether to enable SPX profiler for your current browser session. No performance impact for other clients.docker exec -it web zsh
docker exec -it web zsh
apk add php82-<extension>
Let's extend this docker image by adding the php-curl extension.
docker-compose up --detach
docker exec -it web zsh
apk add php-curl
exit
docker-compose stop
docker commit web apache-php-fpm-alpine-curl:dev
To use newly created image, update the image reference in docker-compose.yml.
When you update the docker image version in docker-compose.yml, it's important to know that the existing configuration in the docker dir may cause problems.
To solve all problems, backup the existing dir then delete it.
docker build -t apache-php-fpm-alpine:dev .
docker-compose.yml and uncomment the development imageservices:
web:
# development image
image: apache-php-fpm-alpine:dev
https://php-fpm.org/about/
Note: This is only for the maintainer of this project.
# build php spx module
./php-spx/build.sh
# bump version
# build local image
docker build --no-cache -t 8ct8pus/apache-php-fpm-alpine:2.4.1 .
# test local image
# push image to docker hub
docker push 8ct8pus/apache-php-fpm-alpine:2.4.1
Content type
Image
Digest
sha256:8cbf69270…
Size
58.3 MB
Last updated
10 months ago
docker pull 8ct8pus/apache-php-fpm-alpine:2.6.0