Initial commit

This commit is contained in:
assada 2023-07-13 17:54:22 +03:00
commit 66c4e8dc8b
Signed by: assada
GPG Key ID: 8905E8CE5CC3000D
7 changed files with 96 additions and 0 deletions

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
build:
docker build -t assada/php:8.2-cli-alpine ./php

43
README.md Normal file
View File

@ -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`)

1
composer.fish Normal file
View File

@ -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"

1
php.fish Normal file
View File

@ -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"

9
php/.bashrc Normal file
View File

@ -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

33
php/Dockerfile Normal file
View File

@ -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"]

7
php/custom.ini Normal file
View File

@ -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 =