-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework PHP Dockerfile with only FPM for both CLI and web (#11)
- Loading branch information
Showing
7 changed files
with
165 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,67 @@ | ||
FROM jmleroux/php:8.0 | ||
FROM debian:buster-slim | ||
MAINTAINER JM Leroux <[email protected]> | ||
|
||
# Define "root" as current user | ||
USER root | ||
ENV DEBIAN_FRONTEND=noninteractive \ | ||
PHP_CONF_DATE_TIMEZONE=UTC \ | ||
PHP_CONF_MAX_EXECUTION_TIME=60 \ | ||
PHP_CONF_MEMORY_LIMIT=512M \ | ||
PHP_CONF_OPCACHE_VALIDATE_TIMESTAMP=0 \ | ||
PHP_CONF_MAX_INPUT_VARS=1000 \ | ||
PHP_CONF_UPLOAD_LIMIT=40M \ | ||
PHP_CONF_MAX_POST_SIZE=40M \ | ||
PHP_CONF_DISPLAY_ERRORS=0 \ | ||
PHP_CONF_DISPLAY_STARTUP_ERRORS=0 | ||
|
||
# Install PHP FPM | ||
RUN apt-get update && \ | ||
apt-get --no-install-recommends --no-install-suggests --yes --quiet install php7.4-fpm && \ | ||
RUN echo 'APT::Install-Recommends "0" ; APT::Install-Suggests "0" ;' > /etc/apt/apt.conf.d/01-no-recommended && \ | ||
echo 'path-exclude=/usr/share/man/*' > /etc/dpkg/dpkg.cfg.d/path_exclusions && \ | ||
echo 'path-exclude=/usr/share/doc/*' >> /etc/dpkg/dpkg.cfg.d/path_exclusions && \ | ||
apt-get update && \ | ||
apt-get --no-install-recommends --no-install-suggests --yes --quiet install \ | ||
apt-transport-https \ | ||
bash-completion \ | ||
ca-certificates \ | ||
curl \ | ||
git \ | ||
gnupg \ | ||
less \ | ||
perceptualdiff \ | ||
procps \ | ||
ssh-client \ | ||
sudo \ | ||
unzip \ | ||
vim \ | ||
wget && \ | ||
wget -O sury.gpg https://packages.sury.org/php/apt.gpg && apt-key add sury.gpg && rm sury.gpg && \ | ||
echo "deb https://packages.sury.org/php/ buster main" > /etc/apt/sources.list.d/sury.list && \ | ||
apt-get update && \ | ||
apt-get --no-install-recommends --no-install-suggests --yes --quiet install \ | ||
php8.0-apcu \ | ||
php8.0-bcmath \ | ||
php8.0-cli \ | ||
php8.0-curl \ | ||
php8.0-fpm \ | ||
php8.0-gd \ | ||
php8.0-imagick \ | ||
php8.0-intl \ | ||
php8.0-mbstring \ | ||
php8.0-mysql \ | ||
php8.0-soap \ | ||
php8.0-sqlite3 \ | ||
php8.0-xdebug \ | ||
php8.0-xml \ | ||
php8.0-zip && \ | ||
apt-get clean && apt-get --yes --quiet autoremove --purge && \ | ||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | ||
/usr/share/doc/* /usr/share/groff/* /usr/share/info/* /usr/share/linda/* \ | ||
/usr/share/lintian/* /usr/share/locale/* /usr/share/man/* | ||
rm -rf /var/lib/apt/lists/* && \ | ||
ln -s /usr/sbin/php-fpm8.0 /usr/local/sbin/php-fpm && \ | ||
usermod --uid 1000 www-data && groupmod --gid 1000 www-data && \ | ||
mkdir /srv/app && \ | ||
usermod -d /srv/app www-data && \ | ||
mkdir -p /run/php | ||
|
||
# Configure PHP FPM | ||
RUN sed -i "s/;date.timezone =/date.timezone = Etc\/UTC/" /etc/php/7.4/fpm/php.ini | ||
COPY jmleroux-php.ini /etc/php/8.0/mods-available/jmleroux.ini | ||
COPY jmleroux-fpm.conf /etc/php/8.0/fpm/pool.d/zzz-jmleroux.conf | ||
RUN phpenmod jmleroux | ||
|
||
RUN sed -i "s/user = www-data/user = docker/" /etc/php/7.4/fpm/pool.d/www.conf && \ | ||
sed -i "s/group = www-data/group = docker/" /etc/php/7.4/fpm/pool.d/www.conf && \ | ||
sed -i "s/listen.owner = www-data/listen.owner = docker/" /etc/php/7.4/fpm/pool.d/www.conf && \ | ||
sed -i "s/listen.group = www-data/listen.group = docker/" /etc/php/7.4/fpm/pool.d/www.conf | ||
|
||
RUN mkdir -p /run/php && sed -i "s/listen = .*/listen = 9001/" /etc/php/7.4/fpm/pool.d/www.conf | ||
|
||
# Define "docker" as current user | ||
USER docker | ||
|
||
# Run FPM in foreground | ||
CMD ["sudo", "php-fpm8.0", "-F"] | ||
COPY --from=composer:2.0 /usr/bin/composer /usr/local/bin/composer | ||
RUN chmod +x /usr/local/bin/composer | ||
RUN mkdir -p /var/www/.composer && chown www-data:www-data /var/www/.composer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
## How to use this Docker file with Compose | ||
|
||
```yaml | ||
version: '3' | ||
|
||
services: | ||
nginx: | ||
image: 'nginx:alpine' | ||
networks: | ||
- jmleroux | ||
|
||
fpm: | ||
image: 'jmleroux/fpm:8.0' | ||
environment: | ||
COMPOSER_HOME: '/var/www/.composer' | ||
PHP_IDE_CONFIG: 'serverName=jmleroux-web' | ||
XDEBUG_CONFIG: 'client_host=172.17.0.1' | ||
XDEBUG_MODE: '${XDEBUG_MODE:-off}' | ||
XDEBUG_SESSION: 'jmleroux-cli' | ||
volumes: | ||
- ./:/srv/app | ||
- ~/.composer:/var/www/.composer | ||
working_dir: /srv/app | ||
command: 'php-fpm8.0 -F' | ||
networks: | ||
- jmleroux | ||
|
||
mysql: | ||
image: mysql:8.0 | ||
command: '--default-authentication-plugin=mysql_native_password' | ||
environment: | ||
MYSQL_ROOT_PASSWORD: 'root' | ||
MYSQL_USER: '${APP_DATABASE_USER}' | ||
MYSQL_PASSWORD: '${APP_DATABASE_PASSWORD}' | ||
MYSQL_DATABASE: '${APP_DATABASE_NAME}' | ||
networks: | ||
- jmleroux | ||
|
||
networks: | ||
jmleroux: | ||
``` | ||
**You will then be able to use the command line:** | ||
To get php info: | ||
```bash | ||
docker-compose run -u www-data --rm fpm php -i | ||
``` | ||
|
||
Execute a Symfony command: | ||
|
||
```bash | ||
docker-compose run -u www-data --rm fpm bin/console | ||
``` | ||
|
||
etc. | ||
|
||
To active Xdebug debugging in CLI: | ||
|
||
```bash | ||
XDEBUG_MODE=debug docker-compose run -u www-data --rm fpm php -i | grep Step | ||
``` | ||
|
||
To start FPM with debugging: | ||
|
||
```bash | ||
XDEBUG_MODE=debug docker-compose up -d fpm | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[global] | ||
daemonize = no | ||
|
||
[www] | ||
user = www-data | ||
group = www-data | ||
|
||
access.format = '{ "fpm.fpm_time":"%t","fpm.remoteip":"%R","fpm.x-forwarded-for":"%{HTTP_X_FORWARDED_FOR}e","fpm.status":"%s","fpm.method":"%m","fpm.uri":"%r","fpm.queri":"%q","fpm.duration":"%{micro}d","fpm.reqlength":"%l","fpm.cpu":"%C","fpm.mem":"%M" }' | ||
access.log = /proc/self/fd/2 | ||
catch_workers_output = yes | ||
clear_env = no | ||
decorate_workers_output = no | ||
listen = [::]:9001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
display_errors = On | ||
error_reporting = E_ALL | ||
apc.enable_cli=1 | ||
date.timezone=${PHP_CONF_DATE_TIMEZONE} | ||
error_prepend_string="PhpErr:" | ||
expose_php=Off | ||
html_errors=Off | ||
log_errors_max_len=8192 | ||
max_execution_time=${PHP_CONF_MAX_EXECUTION_TIME} | ||
memory_limit=${PHP_CONF_MEMORY_LIMIT} | ||
max_input_vars = ${PHP_CONF_MAX_INPUT_VARS} | ||
upload_max_filesize = ${PHP_CONF_UPLOAD_LIMIT} | ||
post_max_size = ${PHP_CONF_MAX_POST_SIZE} | ||
opcache.enable=1 | ||
opcache.validate_timestamps=${PHP_CONF_OPCACHE_VALIDATE_TIMESTAMP} | ||
opcache.max_accelerated_files=16229 | ||
opcache.memory_consumption=128 | ||
variables_order="EGPCS" | ||
|
||
xdebug.discover_client_host = 1 | ||
|
||
; priority=99 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.