Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Last active February 21, 2020 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joseluisq/1ed682cf8b142620c18d739b0dd46c58 to your computer and use it in GitHub Desktop.
Save joseluisq/1ed682cf8b142620c18d739b0dd46c58 to your computer and use it in GitHub Desktop.
PHP Makefile for PSR2 standard code formatting
Options All -Indexes
IndexIgnore *
# Deny all php files by default
<Files ~ "\.(php)$">
Order deny,allow
Deny from all
</Files>
# Allow specific php files
<Files ~ "(get|put)\.php">
Allow from all
</Files>
# Allow specific HTTP methods
<Limit POST>
Order deny,allow
Allow from all
</Limit>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# [POST] myapp/get
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^myapp/get$ "/src/get.php" [L,QSA]
# [POST] synchronize/put
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^myapp/put$ "/src/put.php" [L,QSA]
# Allow specific HTTP methods (dynamic)
# RewriteRule ^myapp/(post)$ /src/$1\.php [L,QSA]
</IfModule>
version: '2'
services:
my-php-app:
env_file: .env
build:
context: .
dockerfile: ./dev.dockerfile
container_name: my-php-app
networks:
- dev-network
ports:
- '7777:80'
volumes:
- ./src/:/var/www/html/
networks:
dev-network:
driver: bridge
FROM php:7.2-apache
ENV ENVIRONMENT=development
# install the PHP extensions we need
RUN set -ex; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
libjpeg-dev \
libpng-dev \
; \
\
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
docker-php-ext-configure pdo_mysql; \
docker-php-ext-install gd pdo_mysql mysqli opcache; \
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*
RUN a2enmod rewrite
# custom php.ini settings
RUN { \
echo 'short_open_tag=0'; \
} > /usr/local/etc/php/conf.d/app.ini
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
# ENV COMPOSER_ALLOW_SUPERUSER=1
# RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer
# WORKDIR /var/www/html/
# RUN php /bin/composer install
# COPY ./etc/sites-available/* /etc/apache2/sites-enabled/
EXPOSE 80
help:
@echo "dependencies: install dependencies"
@echo
@echo "format: check and format the source files using PSR2 standard"
@echo
@echo "start: build the image (if is not created) and run the container for development"
@echo
@echo "prod: build the production image (if is not created) and run the container"
@echo
.PHONY: help
dependencies:
-composer global require \
"squizlabs/php_codesniffer=*"
.PHONY: dependencies
format:
-phpcs ./src --standard=PSR2
-phpcbf ./src --standard=PSR2
.PHONY: format
start:
-docker-compose \
--file dev.docker-compose.yml \
up --build
.PHONY: start
prod:
-docker-compose \
--file prod.docker-compose.yml \
up --build
.PHONY: prod
FROM php:7.2-apache
ENV ENVIRONMENT=production
# install the PHP extensions we need
RUN set -ex; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
libjpeg-dev \
libpng-dev \
; \
\
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
docker-php-ext-configure pdo_mysql; \
docker-php-ext-install gd pdo_mysql mysqli opcache; \
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*
RUN a2enmod rewrite
# custom php.ini settings
RUN { \
echo 'short_open_tag=0'; \
} > /usr/local/etc/php/conf.d/app.ini
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
ENV COMPOSER_ALLOW_SUPERUSER=1
COPY ./src /var/www/html/
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer
RUN \
cd /var/www/html; \
php /bin/composer install --no-dev --optimize-autoloader;
EXPOSE 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment