Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Sandbox based on Docker Compose and official nginx, mysql and php #802

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/vendor/
/bin/
/composer.phar
.mysql
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This directory required to survive container restart and keep all data in MySQL.

31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
phpfpm:
command: php-fpm --allow-to-run-as-root
image: php:5.6.8-fpm
volumes:
- fpm.conf:/usr/local/etc/php-fpm.conf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexanderilyin I got file exists at /mnt/sda1/var/lib/docker/aufs/mnt/eb13125c1167ab4a391994d402ac8181b13901875d2c1350793452242ca275b2/usr/local/etc/php-fpm.conf, can't create volume there error when docker-compose up. Same to other NGINX config below.

I am using boot2docker, am I missing anything?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexanderilyin FYI if I mount a directory, instead of a file, then it does build.

See docker/compose#424

- .:/var/www/symfony2
links:
- mysql
mysql:
command: mysqld --user=root --verbose
image: mysql
volumes:
- .mysql:/var/lib/mysql
- mysql.cnf:/etc/mysql/my.cnf
environment:
MYSQL_DATABASE: symfony
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
MYSQL_ALLOW_EMPTY_PASSWORD: yes
nginx:
image: nginx:1.9.0
volumes:
- nginx.conf:/etc/nginx/conf.d/default.conf
- .:/var/www/symfony2
- server.crt:/etc/ssl/certs/server.crt
- server.key:/etc/ssl/private/server.key
ports:
- "80:80"
- "443:443"
links:
- phpfpm
20 changes: 20 additions & 0 deletions fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[global]
error_log = /proc/self/fd/2
daemonize = no

[www]
# BOOT2DOCKER LIMITATIONS
user = root
group = root

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root user required only if we want use official images under boot2docker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think these notes should be embedded in these files

# SYMFONY 2 REQUIREMENTS
php_admin_value[date.timezone] = 'America/Los_Angeles'
php_admin_flag[short_open_tag] = off

access.log = /proc/self/fd/2
listen = [::]:9000
pm = dynamic
pm.max_children = 100
pm.start_servers = 30
pm.min_spare_servers = 10
pm.max_spare_servers = 50
36 changes: 36 additions & 0 deletions mysql.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
user = root
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root user required only if we want use official images under boot2docker.

pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1

#log-error = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
71 changes: 71 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# http://wiki.nginx.org/Symfony
# http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html

upstream phpfcgi {
server phpfpm:9000;
# server unix:/var/run/php5-fpm.sock; #for PHP-FPM running on UNIX socket
}

server {
listen 80;

server_name localhost;
root /var/www/symfony2/web;

# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;

location / {
index app.php;
try_files $uri @rewriteapp;
}

location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}

# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass phpfcgi;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
# Allow access to /app_dev.php & /config.php
fastcgi_param REMOTE_ADDR 127.0.0.1;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fastcgi_param REMOTE_ADDR 127.0.0.1; is only to allow access to /config.php & /app_dev.php without changes in Symfony sources.

}
}

server {
listen 443;

server_name localhost;
root /var/www/symfony2/web;

ssl on;
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/private/server.key;

# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;

location / {
index app.php;
try_files $uri @rewriteapp;
}

location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}

# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass phpfcgi;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
# Allow access to /app_dev.php & /config.php
fastcgi_param REMOTE_ADDR 127.0.0.1;
}
}
20 changes: 20 additions & 0 deletions server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CER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9OtxLSe4yvogbn6mFGTumpBSwySP1VVQ9HEVDKt+3xZleqz
TDI=
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA0bFd60RlC/TmzshC2DCfT2Rr78CNQ6sht7vcdM10tXRaDZUz
v8jfTQaMgvyLsYJlLtYg8zYFK/rCqsBl5SdbCVIVIphIdTv652F0pijxjq0412+z
VPR1By27FPB/R1krf/UKWLCDoeJPdJYRCPmT5Uhuz5YY56iGN14m09iVEO4NWd26
dLyICK5wdvwsQKQChLJWae6jLOasVCCIFDLJCCLLhbk+iUsGvCmFYpDxX1NSMRY9
WQ+mIPVl0URgqH+qA6YZ3l4xCs4CHUkrNoPAzvR/xQwbq6PfoAUPbO/f9wr8ftUE
yOh5Ln1ra23/3SiaD0VXiI8Uwhso3aqzZp82owIDAQABAoIBAQCBGrD2jy+fgvMw
UUBGlvkfCnciL+1Jwm2KEBIVoAHBTpe7USeBZw2FAQk2BIOFkQD3K0MyOwpIH6YH
N1oFEowMWwtEN3o1I+7A0tHdE8xVyfT7P3ysS65Z8yACLmhO52nO6HGsVVFWNF4z
K8nlOrSCMGx5RrKivrGUGVXSjMCKoMjqizxEPyV8m/8Wsah1We7mDkF6Z7HD/1xv
d/07PZVxrzh7Ab0irxGFdwgZ9uVQTFbHLcp0aKZUvD6OIUa9REq5o3tu/mMNimjx
knBelY6o8dmzaPrzBy+F7iRuRrs7LzQiwUZlQ3tt83wDBZ32GiedrkuaWtf0O3cS
MTMeGnxhAoGBAPHg/aBX8TadrieuzbKsYUMlhoE2wDIvM3bYs5QeQcU2ZrSXFWFM
JuENK2HXnhbRsrIXiVcz15Cdj/mwxt3OWJxrBeHKIX+KKl7qPTrZzbqnH2WycRUz
fU11oNFKOzph/cW9CpGwLg2cBWejfqsF7ZxtjKd6/tzzrYF6Ig/a7vWLAoGBAN3v
VrNfh3wHclwt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