asapdotid/php-nginx

By asapdotid

Updated 8 months ago

Docker image PHP & Nginx (Alpine Linux)

Image
Integration & delivery
Web servers
0

2.4K

asapdotid/php-nginx repository overview

Docker Image PHP and Nginx

  • Base image: webdevops/php
  • OS image: Alpine Linux v3.16 & v3.20

PHP & Nginx (stable) Version:

  • PHP: 8.3 & NGINX: 1.24.0 (Alpine Linux 3.20)
  • PHP: 8.2 & NGINX: 1.24.0 (Alpine Linux 3.20)
  • PHP: 8.1 & NGINX: 1.24.0 (Alpine Linux 3.20)
  • PHP: 7.4 & NGINX: 1.22.1 (Alpine Linux 3.16)

PHP Socket port: 127.0.0.1:9000

Nginx open port: 80 and 443

Custum stuff

  • Add composer entrypoint (composer.json) base of app env development or production
  • Timezone set to Asia/Jakarta

Image Environment

PHP modules

As we build our images containing almost every PHP module and having it activated by default, you might want to deactivate some.

You can specify a comma-separated list of unwanted modules as dynamic env variable PHP_DISMOD, e.g. PHP_DISMOD=ioncube,redis.

PHP.ini variables

You can specify eg. php.memory_limit=256M as dynamic env variable which will set memory_limit = 256M as php setting.

Environment variableDescriptionDefault
php.{setting-key}Sets the {setting-key} as php setting
PHP_DATE_TIMEZONEdate.timezoneUTC
PHP_DISPLAY_ERRORSdisplay_errors0
PHP_MEMORY_LIMITmemory_limit512M
PHP_MAX_EXECUTION_TIMEmax_execution_time300
PHP_POST_MAX_SIZEpost_max_size50M
PHP_UPLOAD_MAX_FILESIZEupload_max_filesize50M
PHP_OPCACHE_MEMORY_CONSUMPTIONopcache.memory_consumption256
PHP_OPCACHE_MAX_ACCELERATED_FILESopcache.max_accelerated_files7963
PHP_OPCACHE_VALIDATE_TIMESTAMPSopcache.validate_timestampsdefault
PHP_OPCACHE_REVALIDATE_FREQopcache.revalidate_freqdefault
PHP_OPCACHE_INTERNED_STRINGS_BUFFERopcache.interned_strings_buffer16
PHP FPM variables

You can specify eg. fpm.pool.pm.max_requests=1000 as dyanmic env variable which will sets pm.max_requests = 1000 as fpm pool setting. The prefix fpm.pool is for pool settings and fpm.global for global master process settings.

Environment variableDescriptionDefault

fpm.global.{setting-key}

fpm.pool.{setting-key}

Sets the {setting-key} as fpm global setting for the master process Sets the {setting-key} as fpm pool setting

FPM_PROCESS_MAXprocess.maxdistribution default
FPM_PM_MAX_CHILDRENpm.max_childrendistribution default
FPM_PM_START_SERVERSpm.start_serversdistribution default
FPM_PM_MIN_SPARE_SERVERSpm.min_spare_serversdistribution default
FPM_PM_MAX_SPARE_SERVERSpm.max_spare_serversdistribution default
FPM_PROCESS_IDLE_TIMEOUTpm.process_idle_timeoutdistribution default
FPM_MAX_REQUESTSpm.max_requestsdistribution default
FPM_REQUEST_TERMINATE_TIMEOUTrequest_terminate_timeoutdistribution default
FPM_RLIMIT_FILESrlimit_filesdistribution default
FPM_RLIMIT_CORErlimit_coredistribution default
Composer

Due to the incompatibilities between composer v1 and v2 we introduce a simple mechanism to switch between composer versions.

Environment variableDescriptionDefault
COMPOSER_VERSIONSpecify the composer version to use2
Additional custom environment
Environment variableDescriptionDefault
APPLICATION_ENVSpecify the application env development or productionproduction
SKIP_COMPOSERInstallation in applicationfalse
TIMEZONETimezoneAsia/Jakarta

Docker Compose setup (Laravel)

# compose.yml
version: "3.7"

services:
    application:
        image: docker.io/asapdotid/php:8.1
        expose:
            - 9000
        networks:
            - application-net
        environment:
            - PHP_POST_MAX_SIZE=100M
            - PHP_UPLOAD_MAX_FILESIZE=100M
        volumes:
            - ./projects/laravel:/app
            - ./conf/supervisor/laravel.conf:/etc/supervisor/conf.d/laravel.conf

networks:
    application-net:
        name: application-net
        driver: bridge
Supervisor Config for Laravel (laravel.conf)

Place config to /etc/supervisor/conf.d/laravel.conf

[group:laravel-worker]
priority=999
programs=laravel-schedule,laravel-notification,laravel-queue

[program:laravel-schedule]
numprocs=1
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/php /app/artisan schedule:run
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:laravel-notification]
numprocs=1
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/php /app/artisan notification:worker
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:laravel-queue]
numprocs=5
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/php /app/artisan queue:work sqs --sleep=3 --tries=3
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
Running Docker Composer
docker composer up -d

License

MIT / BSD

Author Information

This Code was created in 2023 by Asapdotid.

Tag summary

Content type

Image

Digest

sha256:3dd15c311

Size

157.6 MB

Last updated

8 months ago

docker pull asapdotid/php-nginx:8.4-dev