commit 0f140da34e12d0bfac53170feb8b0f1bc57a1e0d Author: Jonas Kaninda Date: Fri Jul 1 18:21:34 2022 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94d3c9c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.history +laravel +docker-compose.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fbcd22a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,97 @@ +FROM php:8.1-fpm +ENV WORKDIR=/var/www/html +ENV STORAGE_DIR=${WORKDIR}/storage +ENV DOCUMENT_ROOT=${WORKDIR} +ENV LARAVEL_PROCS_NUMBER=2 +ENV DOMAIN=_ +ENV CLIENT_MAX_BODY_SIZE=15M +# Install system dependencies +RUN apt-get update && apt-get install -y \ + git \ + curl \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libmemcached-dev \ + libzip-dev \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + librdkafka-dev \ + libpq-dev \ + openssh-server \ + zip \ + unzip \ + supervisor \ + sqlite3 \ + nano \ + cron +# Install nginx +RUN apt-get update && apt-get install -y nginx + +# Clear cache +RUN apt-get clean && rm -rf /var/lib/apt/lists/* + +# Install Kafka +RUN git clone https://github.com/arnaud-lb/php-rdkafka.git\ + && cd php-rdkafka \ + && phpize \ + && ./configure \ + && make all -j 5 \ + && make install + +# Install Rdkafka and enable it +RUN docker-php-ext-enable rdkafka \ + && cd .. \ + && rm -rf /php-rdkafka + +# Install PHP extensions zip, mbstring, exif, bcmath, intl +RUN docker-php-ext-configure gd --with-freetype --with-jpeg +RUN docker-php-ext-install zip mbstring exif pcntl bcmath -j$(nproc) gd intl + +# Install Redis and enable it +RUN pecl install redis && docker-php-ext-enable redis + + + +# Install the php memcached extension +RUN pecl install memcached && docker-php-ext-enable memcached + +# Install the PHP pdo_mysql extention +RUN docker-php-ext-install pdo_mysql + +# Install the PHP pdo_pgsql extention +RUN docker-php-ext-install pdo_pgsql + + +# Get latest Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Install Laravel Envoy +RUN composer global require "laravel/envoy=~1.0" + +# Set working directory +WORKDIR $WORKDIR + +# nginx site conf +RUN rm -Rf /var/www/* && \ +mkdir /var/www/html/ + +ADD src/index.php $WORKDIR/index.php +ADD src/conf/nginx/default.conf /etc/nginx/sites-available/default +ADD src/php.ini $PHP_INI_DIR/conf.d/ + +COPY ./entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/entrypoint.sh +RUN ln -s /usr/local/bin/entrypoint.sh / + +ENTRYPOINT ["entrypoint.sh"] + + + +RUN usermod -u 1000 www-data +RUN groupmod -g 1000 www-data + +RUN chmod -R 755 $WORKDIR +RUN chown -R www-data:www-data $WORKDIR +EXPOSE 9000 +CMD [ "entrypoint" ] diff --git a/README.md b/README.md new file mode 100644 index 0000000..635bd8a --- /dev/null +++ b/README.md @@ -0,0 +1,105 @@ +![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/jkaninda/nginx-php-fpm?style=flat-square) +![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/jkaninda/nginx-php-fpm?style=flat-square) +![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/jkaninda/nginx-php-fpm?style=flat-square) +![Docker Pulls](https://img.shields.io/docker/pulls/jkaninda/nginx-php-fpm?style=flat-square) + +# Nginx PHP-FPM Docker image + +> 🐳 Docker image for Nginx PHP-FPM container crafted to run Laravel or any php based applications. + +- [Docker Hub](https://hub.docker.com/r/jkaninda/nginx-php-fpm) + +## Specifications: + +* PHP 8.1 / 8.0 / 7.4 / 7.2 +* Composer +* OpenSSL PHP Extension +* XML PHP Extension +* PDO PHP Extension +* Rdkafka PHP Extension +* Redis PHP Extension +* Mbstring PHP Extension +* PCNTL PHP Extension +* ZIP PHP Extension +* GD PHP Extension +* BCMath PHP Extension +* Memcached +* Laravel Cron Job +* Laravel Schedule +* Laravel Envoy +* Supervisord + +## Simple docker-compose usage: + +```yml +version: '3' +services: + php-fpm: + image: jkaninda/nginx-php-fpm:latest + container_name: php-fpm + restart: unless-stopped + volumes: + #Project root + - ./:/var/www/html + ports: + - "80:80" + networks: + - default #if you're using networks between containers + +``` +## Laravel `artisan` command usage: +### Open php-fpm +```sh +docker-compose exec php-fpm /bin/bash + +``` + +### Laravel migration +```sh +php atisan migrate + +``` + +## Advanced Nignx-php-fpm: +### docker-compose.yml +```yml +version: '3' +services: + php-fpm: + image: jkaninda/nginx-php-fpm + container_name: php-fpm + working_dir: /var/www/html #Optional, If you want to use a custom directory + restart: unless-stopped + ports: + - "80:80" + volumes: + #Project root + - ./:/var/www/html + - ~/.ssh:/root/.ssh # If you use private CVS + - ./supervisord:/etc/supervisor/conf.d/ # Supervisor directory, if you want to add more supervisor process config file + - ./php.ini:/usr/local/etc/php/conf.d/php.ini # Optional, your custom php init file + - storage-data:/var/www/html/storage/app #Optional, your custom storage data + environment: + - APP_ENV=development # Optional, or production + - WORKDIR=/var/www/html #Optional, If you want to use a custom directory + - LARAVEL_PROCS_NUMBER=3 # Optional, Laravel queue:work process number + - CLIENT_MAX_BODY_SIZE=20M + - DOMAIN=example.com +volumes: + storage-data: +``` + +## Docker run +```sh + docker-compose up -d + +``` +## Nginx custom config: +### Enable custom nginx config files if they exist +> /var/www/html/conf/nginx/nginx.conf +> /var/www/html/conf/nginx/nginx-site.conf + + +> P.S. please give a star if you like it :wink: + + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7ee3017 --- /dev/null +++ b/build.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +if [ $# -eq 0 ] + then + tag='latest' + else + tag=$1 +fi + +docker build -t jkaninda/nginx-php-fpm:$tag . diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..6fbdaec --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,160 @@ +#!/bin/sh +Red='\033[0;31m' # Red +Green='\033[0;32m' # Green +echo "" +echo "***********************************************************" +echo " Starting LARAVEL NGINX PHP-FPM Docker Container " +echo "***********************************************************" + +set -e + +## Create PHP-FPM worker process +TASK=/etc/supervisor/conf.d/php-fpm.conf +touch $TASK +cat > "$TASK" < "$TASK" < "$TASK" < "$TASK" < \ No newline at end of file diff --git a/src/php.ini b/src/php.ini new file mode 100644 index 0000000..21ff610 --- /dev/null +++ b/src/php.ini @@ -0,0 +1,6 @@ +date.timezone=UTC +display_errors=Off +log_errors=On +upload_max_filesize= 80M +post_max_size= 80M +memory_limit = 256M