From 66c4e8dc8b4f2658bf95e420515a26b637bc1ae2 Mon Sep 17 00:00:00 2001 From: assada Date: Thu, 13 Jul 2023 17:54:22 +0300 Subject: [PATCH] Initial commit --- Makefile | 2 ++ README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ composer.fish | 1 + php.fish | 1 + php/.bashrc | 9 +++++++++ php/Dockerfile | 33 +++++++++++++++++++++++++++++++++ php/custom.ini | 7 +++++++ 7 files changed, 96 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 composer.fish create mode 100644 php.fish create mode 100644 php/.bashrc create mode 100644 php/Dockerfile create mode 100644 php/custom.ini diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d15cb84 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +build: + docker build -t assada/php:8.2-cli-alpine ./php \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..81241da --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Docker based PHP and composer CLI + +Php cli and composer in docker container for cli usage. With XDebug, git, strace, pdo and redis extensions inside. + +Now you don't have to install php and composer on your local machine(e.g `sudo apt install php`). Just use docker container instead! + +With this you can run smth like `composer install && php artisan serve` and debug your application with XDebug in your IDE. + +## How to setup + +1. `make build` +2. `nano php` +3. paste and save php string +4. `nano composer` +5. paste and save composer string +6. `chmod a+x ./php` +7. `chomd a+x ./composer` +8. `sudo mv ./php /usr/bin/php` (`/usr/local/bin/php` ?) +9. `sudo mv ./composer /usr/bin/composer` (`/usr/local/bin/composer` ?) + +## PHP String (for debian based distros) + +```bash +docker run -e PHP_IDE_CONFIG="serverName=host.docker.internal" --add-host=host.docker.internal:host-gateway --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --net=host -it --rm -v "$PWD":/var/www -w /var/www assada/php:8.2-cli-alpine php +``` + +## Composer String (for debian based distros) + +```bash +docker run --interactive --tty --add-host=host.docker.internal:host-gateway --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --net=host -it --rm -v ~/.ssh:/root/.ssh -v composertmp:/tmp -v "$PWD":/var/www -w /var/www assada/php:8.2-cli-alpine composer +``` + +**OR!** You can create just simple alias for your shell instead fake binary creation + +**Fish shell example:** +```fish +cat ~/.config/fish/functions/composer.fish +alias composer="docker run --interactive --tty --add-host=host.docker.internal:host-gateway --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --net=host -it --rm -v ~/.ssh:/root/.ssh -v composertmp:/tmp -v "$PWD":/var/www -w /var/www assada/php:8.2-cli-alpine composer" +``` + +**BE AWARE!** composer docker image uses the latest(8.2) php version. So, if u want to use older php you must create personal image with preferred php version (e.g 7.4). Or... just ignore platform reqs (e.g `composer install --ignore-platform-reqs`) + + diff --git a/composer.fish b/composer.fish new file mode 100644 index 0000000..468ed4f --- /dev/null +++ b/composer.fish @@ -0,0 +1 @@ +alias composer="docker run --interactive --tty --add-host=host.docker.internal:host-gateway --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --net=host -it --rm -v ~/.ssh:/root/.ssh -v composertmp:/tmp -v "$PWD":/var/www -w /var/www assada/php:8.1-cli-alpine composer" \ No newline at end of file diff --git a/php.fish b/php.fish new file mode 100644 index 0000000..deeb660 --- /dev/null +++ b/php.fish @@ -0,0 +1 @@ +alias php="docker run --add-host=host.docker.internal:host-gateway --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --net=host -it --rm -v "$PWD":/var/www -w /var/www assada/php:8.1-cli-alpine php" \ No newline at end of file diff --git a/php/.bashrc b/php/.bashrc new file mode 100644 index 0000000..0640662 --- /dev/null +++ b/php/.bashrc @@ -0,0 +1,9 @@ +export PS1='$(whoami):$(pwd)# ' +alias ll='ls -l' +alias ls='ls --color=auto' + +# see https://stackoverflow.com/questions/4188324/bash-completion-of-makefile-target +# -h to grep to hide filenames +# -s to grep to hide error messages +# include Makefile and .make directory +complete -W "\`grep -shoE '^[a-zA-Z0-9_.-]+:([^=]|$)' ?akefile .make/*.mk | sed 's/[^a-zA-Z0-9_.-]*$//' | grep -v PHONY\`" make \ No newline at end of file diff --git a/php/Dockerfile b/php/Dockerfile new file mode 100644 index 0000000..872de74 --- /dev/null +++ b/php/Dockerfile @@ -0,0 +1,33 @@ +FROM composer AS composer +FROM php:8.2-cli-alpine +COPY --from=composer /usr/bin/composer /usr/bin/composer +RUN apk add --no-cache bash nodejs npm bash +RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} \ + && pecl install redis && docker-php-ext-enable redis \ + && docker-php-ext-install mysqli pdo pdo_mysql \ + && apk del pcre-dev ${PHPIZE_DEPS} + +RUN apk add --update --no-cache \ + strace git make vim curl wget + +RUN sed -e 's;/bin/ash$;/bin/bash;g' -i /etc/passwd + +RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \ + && apk add --no-cache --update linux-headers \ + && pecl install xdebug \ + && docker-php-ext-enable xdebug \ + && apk del -f .build-deps + +RUN echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo "xdebug.log=/var/www/html/xdebug/xdebug.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo "xdebug.discover_client_host=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo "xdebug.client_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini + +COPY ./custom.ini /usr/local/etc/php/conf.d/custom.ini +COPY ./.bashrc /root/.bashrc + +WORKDIR "/var/www" +CMD ["php"] + diff --git a/php/custom.ini b/php/custom.ini new file mode 100644 index 0000000..4025915 --- /dev/null +++ b/php/custom.ini @@ -0,0 +1,7 @@ +memory_limit = -1 +max_execution_time = 600 +upload_max_filesize = 2G +post_max_size = 2G +error_log = /var/log/php_error.log +log_errors = On +disable_functions =