Skip to content

Instantly share code, notes, and snippets.

@Pandry
Last active March 20, 2020 22:30
Show Gist options
  • Save Pandry/0db9fdb4e5fd73edc78937cbc2e6b14d to your computer and use it in GitHub Desktop.
Save Pandry/0db9fdb4e5fd73edc78937cbc2e6b14d to your computer and use it in GitHub Desktop.
A script to paste to execute a php webapp quickly (used to play CTF atm)
cat << EOF > docker-compose.yml
version: '3'
services:
php:
build:
context: ./php
# ports:
# - 9000:9000
volumes:
- ./app:/app
- ./php/www.conf:/usr/local/etc/php-fpm.d/www.conf
networks:
- php
nginx:
image: nginx
ports:
- 80:80
volumes:
- ./app:/app
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
networks:
- php
mysql:
image: mariadb
# ports:
# - 3306:3306
depends_on:
- php
environment:
MYSQL_ROOT_PASSWORD: rootpwd
MYSQL_DATABASE: db
MYSQL_USER: dbusr
MYSQL_PASSWORD: dbpwd
networks:
- php
networks:
php:
EOF
mkdir php
cat <<EOF > php/Dockerfile
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libonig-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd mbstring mysqli pdo pdo_mysql shmop
EOF
cat <<EOF > php/www.conf
[www]
user = www-data
group = www-data
listen = nginx:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOF
mkdir nginx
cat << EOF > nginx/default.conf
server {
listen 80 default_server;
server_name _;
root /app;
index index.php index.html index.html;
location ~ \.php\$ {
try_files \$uri \$uri/ index.php?url=\$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param PATH_INFO \$fastcgi_path_info;
fastcgi_param QUERY_STRING \$query_string;
fastcgi_param REQUEST_METHOD \$request_method;
fastcgi_param CONTENT_TYPE \$content_type;
fastcgi_param CONTENT_LENGTH \$content_length;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
fastcgi_param PATH_INFO \$fastcgi_path_info;
fastcgi_param PATH_TRANSLATED \$document_root\$fastcgi_path_info;
fastcgi_param REQUEST_URI \$request_uri;
fastcgi_param DOCUMENT_URI \$document_uri;
fastcgi_param DOCUMENT_ROOT \$document_root;
fastcgi_param SERVER_PROTOCOL \$server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/\$nginx_version;
fastcgi_param REMOTE_ADDR \$remote_addr;
fastcgi_param REMOTE_PORT \$remote_port;
fastcgi_param SERVER_ADDR \$server_addr;
fastcgi_param SERVER_PORT \$server_port;
fastcgi_param SERVER_NAME \$server_name;
fastcgi_param HTTPS \$https;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
}
error_log /var/log/nginx/api_error.log;
access_log /var/log/nginx/api_access.log;
}
EOF
mkdir app
docker-compose up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment