Skip to content

Instantly share code, notes, and snippets.

@ozanmuyes
Last active January 18, 2023 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozanmuyes/6df51ea95cfa92a700126022640cb2a2 to your computer and use it in GitHub Desktop.
Save ozanmuyes/6df51ea95cfa92a700126022640cb2a2 to your computer and use it in GitHub Desktop.
CakePHP via Docker
docker run -it --rm \
--name php74_composer \
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp \
php:7.4.33-cli sh -c "pwd; apt-get update && apt-get install -y unzip; \
curl https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php; \
php composer.phar create-project --no-install --no-interaction --no-scripts --prefer-dist cakephp/app:\"3.6.5\" my_app_name; \
cd my_app_name; \
php ../composer.phar config --no-plugins allow-plugins.cakephp/plugin-installer true; \
php ../composer.phar install --ignore-platform-reqs; \
php ../composer.phar run --no-interaction post-install-cmd; \
cd ../ && rm composer.phar; \
exit"
# In the "my_app_name" directory
mkdir docker && cd docker
echo "FROM php:7.4.33-fpm
RUN apt-get update && apt-get install -y \\
libicu-dev \\
git \\
curl \\
zip \\
unzip
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl
RUN docker-php-ext-enable intl
RUN docker-php-ext-configure pdo_mysql
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-enable pdo_mysql
RUN pecl install xdebug-3.1.6 \\
&& docker-php-ext-enable xdebug
RUN curl https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php \\
&& mv composer.phar /usr/local/bin/composer
WORKDIR /var/www" > Dockerfile
echo "version: '3.8'
services:
app:
build:
context: ./
dockerfile: Dockerfile
container_name: johndoes-app
restart: always
working_dir: /var/www
volumes:
- ../:/var/www
- ./99-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
nginx:
image: nginx:1.23-alpine
container_name: johndoes-nginx
restart: always
ports:
- 8000:80
volumes:
- ../:/var/www
- ./nginx:/etc/nginx/conf.d
" > docker-compose.yml
mkdir nginx && cd nginx
echo "server {
listen 80;
index index.php;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
error_page 404 /index.php;
root /var/www/webroot;
location ~ \.php {
try_files \$uri =404;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
}
" > nginx.conf
cd ..
echo "zend_extension = xdebug
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal" > 99-xdebug.ini
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www": "${workspaceFolder}"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment