php - 502 Bad Gateway on Docker, NPM, PHPFPM and Symfony -


due fact live in germany can "good morning" now. 04:18:15 , need sleep now. maybe can me this.

these first steps docker , cant reach local symfony via webbrowser (calling http://myproject.dev:8080/).

i 502 bad gateway message in browser

here have

i have 3 images. placed in

 /home/chucky/dockerimages/  - nginx/    - dockerfile    - myproject.nginx.conf - fpmimage/    - dockerfile    - symfony.pool.conf - symfony/    - dockerfile 

my symfony installation (default symfony fetched symfony installer) can found under /var/www/symfony

inside folder lies file: docker-compose.yml

now come file contents:

nginx/dockerfile

from debian:jessie run apt-get update && apt-get install -y nginx add myproject.nginx.conf /etc/nginx/sites-available/myproject run ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled/myproject run rm /etc/nginx/sites-enabled/default run echo "upstream php-upstream { server phpfpm:9000; }" > /etc/nginx/conf.d/upstream.conf run usermod -u 1000 www-data cmd ["nginx", "-g", "daemon off;"] run ln -sf /dev/stdout /var/log/nginx/access.log run ln -sf /dev/stderr /var/log/nginx/error.log expose 80 expose 443 

nginx/myproject.nginx.conf

server {     server_name myproject.dev www.myproject.dev;     root /var/www/myproject;      error_log /var/log/nginx/project_error.log;     access_log /var/log/nginx/project_access.log;       location / {         # try serve file directly, fallback app.php         try_files $uri /app.php$is_args$args;     }     # dev     # rule should placed on development environment     # in production, don't include , don't deploy app_dev.php or config.php     location ~ ^/(app_dev|config)\.php(/|$) {         #fastcgi_pass unix:/var/run/php5-fpm.sock;         fastcgi_pass phpfpm:9000;         #fastcgi_pass php-upstream;         fastcgi_split_path_info ^(.+\.php)(/.*)$;         include fastcgi_params;         # when using symlinks link document root         # current version of application, should pass real         # application path instead of path symlink php         # fpm.         # otherwise, php's opcache may not detect changes         # php files (see https://github.com/zendtech/zendoptimizerplus/issues/126         # more information).         #fastcgi_param script_filename $realpath_root$fastcgi_script_name;         fastcgi_param script_filename $document_root$fastcgi_script_name;         fastcgi_param document_root $realpath_root;     }      # prod     location ~ ^/app\.php(/|$) {     #fastcgi_pass unix:/var/run/php5-fpm.sock;     fastcgi_pass phpfpm:9000;     fastcgi_split_path_info ^(.+\.php)(/.*)$;     include fastcgi_params;        # when using symlinks link document root        # current version of application, should pass real        # application path instead of path symlink php        # fpm.        # otherwise, php's opcache may not detect changes        # php files (see https://github.com/zendtech/zendoptimizerplus/issues/126        # more information).        fastcgi_param script_filename $realpath_root$fastcgi_script_name;        fastcgi_param document_root $realpath_root;        # prevents uris include front controller. 404:        # http://domain.tld/app.php/some-path        # remove internal directive allow uris        internal;    }     # return 404 other php files not matching front controller    # prevents access other php files don't want accessible.    location ~ \.php$ {      return 404;    }  } 

fpmimage/dockerfile

from debian:jessie run apt-get update && apt-get install -y php5-common php5-cli php5-fpm php5-mcrypt php5-mysql php5-apcu php5-gd php5-imagick php5-curl php5-intl run usermod -u 1000 www-data cmd ["php5-fpm", "-f"] expose 9000 

fpmimage/symfony.pool.conf

listen = 127.0.0.1:9000 

symfony/dockerfile

from debian:jessie volume /var/www/myproject 

docker-compose.yml

version: '2'  services:    symfony:       build: /home/chucky/dockerimages/symfony       tty: true     phpfpm:       build: /home/chucky/dockerimages/fpmimage       tty: true       volumes_from:          - symfony       ports:          - "9000:9000"       depends_on:          - symfony     nginx:       build: /home/chucky/dockerimages/nginx       volumes_from:          - symfony       volumes:          - /var/log/nginx:/var/log/nginx       ports:          - "8080:80"       depends_on:          - phpfpm          - symfony 

and access http://127.0.0.1:8080/ or http://myproject.dev:8080/ new log entries on local machine in /var/log/nginx/project_error.log saying

2016/11/13 10:08:43 [error] 6#0: *1 connect() failed (111: connection refused) while connecting upstream, client: 172.18.0.1, server: myproject.dev, request: "get / http/1.1", upstream: "fastcgi://172.18.0.3:9000", host: "127.0.0.1:8080"  2016/11/13 10:08:43 [error] 6#0: *1 connect() failed (111: connection refused) while connecting upstream, client: 172.18.0.1, server: myproject.dev, request: "get /favicon.ico http/1.1", upstream: "fastcgi://172.18.0.3:9000", host: "127.0.0.1:8080", referrer: "http://127.0.0.1:8080/" 

it might helpful show output after execute

docker-compose --build

building symfony step 1 : debian:jessie  ---> 73e72bf822ca step 2 : volume /var/www/myproject  ---> using cache  ---> 0f508ee968e9 built 0f508ee968e9 building phpfpm step 1 : debian:jessie  ---> 73e72bf822ca step 2 : run apt-get update && apt-get install -y php5-common php5-cli php5-fpm php5-mcrypt php5-mysql php5-apcu php5-gd php5-imagick php5-curl php5-intl  ---> using cache  ---> aa5990f0e852 step 3 : run usermod -u 1000 www-data  ---> using cache  ---> daf793938034 step 4 : cmd php5-fpm -f  ---> using cache  ---> 370c65c14d29 step 5 : expose 9000  ---> using cache  ---> 8d18bd852576 built 8d18bd852576 building nginx step 1 : debian:jessie  ---> 73e72bf822ca step 2 : run apt-get update && apt-get install -y nginx  ---> using cache  ---> 6efdb80d580f step 3 : add myproject.nginx.conf /etc/nginx/sites-available/myproject  ---> using cache  ---> 166da8351d0f step 4 : run ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled/myproject  ---> using cache  ---> f9664f6d4dc7 step 5 : run rm /etc/nginx/sites-enabled/default  ---> using cache  ---> 18de9d72a2f5 step 6 : run echo "upstream php { server phpfpm:9001; }" > /etc/nginx/conf.d/upstream.conf  ---> running in 657abb36b3bb  ---> b8dfcf6f5668 removing intermediate container 657abb36b3bb step 7 : run usermod -u 1000 www-data  ---> running in 55a8dce2f492  ---> bca558fcf413 removing intermediate container 55a8dce2f492 step 8 : cmd nginx -g daemon off;  ---> running in 400b5f76a3bb  ---> 6751644b3548 removing intermediate container 400b5f76a3bb step 9 : run ln -sf /dev/stdout /var/log/nginx/access.log  ---> running in 796f023c797e  ---> 72bc07b1330e removing intermediate container 796f023c797e step 10 : run ln -sf /dev/stderr /var/log/nginx/error.log  ---> running in 269b0fec15aa  ---> 62d1674d9b5a removing intermediate container 269b0fec15aa step 11 : expose 80  ---> running in 348d5e2e6061  ---> 5373fddc7ce6 removing intermediate container 348d5e2e6061 step 12 : expose 443  ---> running in b6bbf8623b4b  ---> fa6b92ad1d09 removing intermediate container b6bbf8623b4b built fa6b92ad1d09 starting myproject_symfony_1 starting myproject_phpfpm_1 recreating myproject_nginx_1 attaching myproject_symfony_1, myproject_phpfpm_1, myproject_nginx_1 phpfpm_1   | 2016 03:16:45] notice: fpm running, pid 1 phpfpm_1   | [13-nov-2016 03:16:45] notice: ready handle connections phpfpm_1   | [13-nov-2016 03:16:45] notice: systemd monitor interval set 10000ms 

meanwhile, after many times of debugging got running.

so these files

fpmimage/dockerfile

from debian:jessie  run apt-get update && apt-get install -y php5-common php5-cli php5-fpm php5-mcrypt php5-mysql php5-apcu php5-gd php5-imagick php5-curl php5-intl  run sed -i 's/listen = \/var\/run\/php5-fpm.sock/listen = 0.0.0.0:9000/g' /etc/php5/fpm/pool.d/www.conf  run usermod -u 1000 www-data  cmd ["php5-fpm", "-f"]  expose 9000 

fpmimage/symfony.pool.conf

listen = 127.0.0.1:9000 

nginx/dockerfile

from debian:jessie  run apt-get update && apt-get install -y nginx  add myproject.nginx.conf /etc/nginx/sites-available/myproject  run ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled/myproject run rm /etc/nginx/sites-enabled/default  run echo "upstream php { server phpfpm:9000; }" > /etc/nginx/conf.d/upstream.conf  run usermod -u 1000 www-data  cmd ["nginx", "-g", "daemon off;"]  run ln -sf /dev/stdout /var/log/nginx/access.log run ln -sf /dev/stderr /var/log/nginx/error.log  expose 80 expose 443 

nginx/myproject.nginx.conf

server {     server_name myproject.dev www.myproject.dev;     root /var/www/myproject/web;      error_log /var/log/nginx/project_error.log;     access_log /var/log/nginx/project_access.log;       location / {         # try serve file directly, fallback app.php         try_files $uri /app.php$is_args$args;     }     # dev     # rule should placed on development environment     # in production, don't include , don't deploy app_dev.php or config.php     location ~ ^/(app_dev|config)\.php(/|$) {         #fastcgi_pass unix:/var/run/php5-fpm.sock;         fastcgi_pass phpfpm:9000;         #fastcgi_pass php-upstream;         fastcgi_split_path_info ^(.+\.php)(/.*)$;         include fastcgi_params;         # when using symlinks link document root         # current version of application, should pass real         # application path instead of path symlink php         # fpm.         # otherwise, php's opcache may not detect changes         # php files (see https://github.com/zendtech/zendoptimizerplus/issues/126         # more information).         #fastcgi_param script_filename $realpath_root$fastcgi_script_name;         fastcgi_param script_filename $document_root$fastcgi_script_name;         #fastcgi_param document_root $realpath_root;     }     # prod     location ~ ^/app\.php(/|$) {         #fastcgi_pass unix:/var/run/php5-fpm.sock;         fastcgi_pass phpfpm:9000;         fastcgi_split_path_info ^(.+\.php)(/.*)$;         include fastcgi_params;        # when using symlinks link document root        # current version of application, should pass real        # application path instead of path symlink php        # fpm.        # otherwise, php's opcache may not detect changes        # php files (see https://github.com/zendtech/zendoptimizerplus/issues/126        # more information).        fastcgi_param script_filename $realpath_root$fastcgi_script_name;        fastcgi_param document_root $realpath_root;        # prevents uris include front controller. 404:        # http://domain.tld/app.php/some-path        # remove internal directive allow uris        internal;    }     # return 404 other php files not matching front controller    # prevents access other php files don't want accessible.    location ~ \.php$ {      return 404;    }  } 

symfony/dockerfile

from debian:jessie  volume /var/www/myproject/app/cache volume /var/www/myproject/var/sessions  run chown www-data:www-data /var/www/myproject/app/cache run chown www-data:www-data /var/www/myproject/var/sessions 

/var/www/myproject/docker-compose.yml

version: '2'  services:    symfony:       build: /home/chucky/dockerimages/symfony       tty: true       volumes:          - /var/www/myproject:/var/www/myproject          - /var/www/myproject/app/cache:/var/www/myproject/app/cache          - /var/www/myproject/var/sessions:/var/www/myproject/var/sessions     phpfpm:       build: /home/chucky/dockerimages/fpmimage       tty: true       volumes_from:          - symfony       ports:          - "9000:9000"       depends_on:          - symfony     nginx:       build: /home/chucky/dockerimages/nginx       volumes_from:          - symfony       volumes:          - /var/log/nginx:/var/log/nginx       ports:          - "8080:80"       depends_on:          - phpfpm          - symfony 

i think necessary files. had more adjustments symfony project running. ran problems "session storage not able create directory". tried modify path "framework.session.save_path" else in /app/config.yml. solution more simple that. had take care defined folder framework.session.save_path existed.

in symfony default "%kernel.root_dir%/../var/sessions/%kernel.environment%". did chmod , chown folder. (and cache , logs folders)

  1. created folder /var/www/myproject/var/sessions
  2. chown www-data:www-data /var/www/myproject/var/sessions
  3. chown www-data:www-data /var/www/myproject/var/cache
  4. chown www-data:www-data /var/www/myproject/var/logs
  5. chmod 775 /var/www/myproject/var/sessions
  6. chmod 775 /var/www/myproject/var/cache
  7. chmod 775 /var/www/myproject/var/logs

since played around configurations in config.yml , nothing worked after this, forgot clear out cache folder. after cleared /var/www/myproject/app/cache folder worked , freaked hell out.

i hope helped , did not forgot step took, system running. know if there improvements see in configuration. expect there many other ways system running.


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -