This question already has answers here:
How do I get PHP errors to display?
(27 answers)
Closed 10 months ago.
I create Laravel PHP application in Docker. First I setup Laravel app using
laravel new laravelDockerApp
it creates successfully.I verify it's setup by built-in server
php artisan serve
Then setup Local environment with Docker
docker-compose.yml
version: '2'
services:
web:
build:
context: ./
dockerfile: web.docker
volumes:
- ./:/var/www
ports:
- "8080:80"
links:
- app
app:
build:
context: ./
dockerfile: app.docker
volumes:
- ./:/var/www
app.docker
FROM php:7-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
&& docker-php-ext-install mcrypt pdo_mysql
WORKDIR /var/www
web.docker
FROM nginx:1.10
ADD ./vhost.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/www
vhost.conf
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
I run docker-compose up -d command. app & web containers up successfully.When I check app in Browser using
localhost:8080
I got
500(Internal Server Error)
Please, can you help to solve this? Thanks.
I found a solution. I set the permission on my Laravel app using:
sudo chmod -R 777 storage && sudo chmod -R 777 bootstrap/cache
This solution might not apply to you since you are using Nginx, but in my case I am using the php:7.0-apache as source image, so I made the Apache user the owner of my app's files.
In my Dockerfile I have:
...
USER www-data
WORKDIR /var/www/html
COPY --chown=www-data:www-data . .
...
This solved the problem, so it could be worth trying, either modifying your Dockerfile or maybe Docker Compose has some option for user permissions when mounting volumes.
I ran into this today, and the issue for me was that while I'd created my directory structure, I'd failed to copy the .env file from .env.example. Copying this and hitting the webpage gave me a page which had this in the top right corner:
Clicking "Generate App Key" resolved this issue for me, but it's probably worth giving the .env file a once-over to make sure it's not got some other unset variables you'll need!
Related
I have a very simple config in docker-compose with php:7-fpm and nginx that I want to use to host simple php websites.
Can someone please tell me what I did wrong?
Here is docker-compose.prod.yml:
version: '3.8'
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ../nurock/hidden_creste:/code
- ./site.prod.conf:/etc/nginx/conf.d/default.conf
php:
image: php:7-fpm
volumes:
- ../nurock/hidden_creste:/code
Here is the site.prod.conf file:
server {
listen 80;
index index.php index.html;
server_name example.com;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;
location ~ \.php$ {
try_files $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;
}
}
I can compose up and the logs appear to be fine and when I run docker ps:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c268a9cf4716 php:7-fpm "docker-php-entrypoi…" 27 minutes ago Up 16 seconds 9000/tcp example_code-php-1
beaaec39209b nginx:latest "/docker-entrypoint.…" 27 minutes ago Up 16 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp example_code-web-1
Then checking the ports, I think this looks fine:
netstat -tulpn | grep :80
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 204195/docker-proxy
tcp6 0 0 :::8080 :::* LISTEN 204207/docker-proxy
You need to expose TCP port 9000 of the PHP container to made other containers able to use it (see What is the difference between docker-compose ports vs expose):
php:
image: php:7-fpm
expose:
- "9000"
...
Do you really want your sites to be available on TCP port 8080, not the standard port 80? If not, change "8080:80" to "80:80".
Besides the PHP handler, use a default location (although your site should be workable even without it, it is a bad practice to not add it to your nginx config):
location / {
try_files $uri $uri/ =404;
}
You must check the logs to find out the error. https://docs.docker.com/engine/reference/commandline/logs/
These issues can happen :
A php module is missing
user / permission are not correct. Is www-data defined in your nginx and php-fpm config ?
Use HTTPS and port 443 instead of HTTP and port 80. HTTP may be blocked by your browser. You can define a free SSL certificate with Let's Encrypt Docker image.
PHP 7.0 is EOL (end or life) since January 10, 2019. Please use PHP 8.0 or PHP 8.1. https://endoflife.date/php
Do not use use tag nginx:latest on production. You may have serious issues when you update your container, because last version will be downloaded.
Do not mount directory on production. Please use COPY in your Dockerfile.
Check the firewall on your server
Here is Docker Docker best practices : https://docs.docker.com/develop/dev-best-practices/
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
Here, I suggest this docker-compose.prod.yml
version: '3.8'
services:
web:
image: nginx:1.21
depends_on:
- my-php-container-name
container_name: my-nginx-container-name
working_dir: /code
ports:
- '80:80'
- '443:443'
volumes:
- ../nurock/hidden_creste:/code
- ./site.prod.conf:/etc/nginx/conf.d/default.conf
restart: always
php:
build: php-fpm
container_name: my-php-container-name
working_dir: /code
volumes:
- ../nurock/hidden_creste:/code
restart: always
In the same directory as this docker-compose.prod.yml file, create a php-fpm directory: mkdir php-fpm (or directory architecture written under build in docker-compose.prod.yml file.)
In php-fpm directory, please add this Dockerfile called Dockerfile
FROM php:8.1-fpm
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
WORKDIR "/code"
RUN apt-get update && apt-get install -y --no-install-recommends \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libicu-dev
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd pdo_mysql bcmath mysqli intl
Of course, add the PHP extensions that you need for your project. Here you have an example how to install gd, pdo_mysql, bcmatch, mysqli, intl. But there are others extension as curl, xml, xdebug, mcrypt, memcache, etc... https://github.com/mlocati/docker-php-extension-installer
In your nginx configuration, you should define config for HTTPS with port 443. Please also update this line fastcgi_pass php:9000;. Replace php by the container name. Of course, container name must be unique.
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass my-php-container-name:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
Then, build your set-up
docker-compose -f docker-compose.prod.yml build && docker-compose -f docker-compose.prod.yml up
I'm trying to set up a simple Grav site workflow using git, Docker and two containers: one for nginx and one for PHP. The idea is to git clone into my Digital Ocean droplet and run docker-compose up -d --build to build and serve the website.
I'm getting permission issues whenever I try to access the sites, and even Grav's documentation about troubleshooting permission issues does not help.
Here's my docker-compose.yml:
version: '3'
services:
web:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
ports:
- "80:80"
volumes:
- ./src:/var/www/html
links:
- php
php:
build:
context: .
dockerfile: ./docker/php/Dockerfile
volumes:
- ./src:/var/www/html
And here's nginx's Dockerfile:
FROM nginx:stable-alpine
WORKDIR /var/www/html
COPY ./src .
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf
If that's any use, here's the nginx configuration I'm using:
server {
listen 80;
index index.php index.html;
server_name www.gravtest.test gravtest.test;
error_log /var/log/nginx/gravtest.test.error.log;
access_log /var/log/nginx/gravtest.test.access.log;
root /var/www/html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $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;
}
}
The PHP Dockerfile is simple, it just spawns php:7.3-fpm and installs a few dependencies like opcache, gd, etc...
Whenever I try to access the site via localhost, I get this error:
Fatal error: Uncaught RuntimeException: Creating directory failed for /var/www/html/cache/compiled/files/40779d000b68629af00dd987148afc06.yaml.php in /var/www/html/vendor/rockettheme/toolbox/File/src/File.php:325 Stack trace:....
Files are copied from the host to the container with the nginx:nginx owner, so I should be good, but looks like I'm not. I've tried setting folders/files chmod using Grav's documentation but no dice.
Am I missing something?
Answering my own question:
It turns out the images php-fpm and nginx do not use the same user, so the permission problem came from that. I simply had to add a new user to both Dockerfile, and run that container from that user.
So for PHP, my Dockerfile is now:
FROM php:7.3-fpm
# Install a few dependencies here...
COPY ./src /var/www/html
RUN addgroup --gid 1000 mygroup
RUN adduser --system --no-create-home --disabled-password --disabled-login --uid 1000 --ingroup mygroup myuser
RUN chown -R myuser:mygroup /var/www
USER myuser
And for nginx:
FROM nginx:stable-alpine
RUN addgroup --gid 1000 mygroup
RUN adduser --system --no-create-home --disabled-password --disabled-login --uid 1000 --ingroup mygroup myuser
WORKDIR /var/www/html
RUN chown -R myuser:mygroup .
USER myuser
And now everything works fine! :)
I'm currently stuck on a problem.
I got a Server where i run multiple docker.
here i need to put have an php nginx one.
i got a docker-compose file like this :
version: 2
services:
web:
image: nginx:latest
ports:
- 'XXXX:80'
- 'XXXX:443'
volumes:
- ./code:./code
- ./site.conf:/etc/nginx/conf.d/default.conf
environnement:
- VIRTUAL_HOST:...
- LETSENCRYPT_HOST:....
- LETSENCRYPT_MAIL:....
networks:
- default
php:
build:
context: ./php
volumes:
- ./code:/code
networks:
- default
networks:
default:
external:
name:webproxy
My networks make me getting a automatique letsencrypt ssl
My dockerfile for php is :
FROM php:7.2-fpm
RUN apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev \
&& docker-php-ext-install mysqli pdo_pgsql pdo_mysql
My config is :
server{
listen 80
index index.php index.html
server_name localhost
error_log /var/log/nginx/error.log
access_log /var/log/nginx/access.log
root /code
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php 9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info
}
}
My structure of folder is something like :
- imgFolder
- GameFolder
- index.html
- service.php
- imgFolder
- cssFolder
- desktop.html
- mobile.html
- main.css
All seems to be fine web i make my docker-compose compose up -d
What i meen by all seems to be fine is :
. HTML is well render
. SSL is also well apply
But sometimes (not all the time but something like half time) my php file was not found on ajax request (got a 404 file not found in networks debug)
Did someone have an idea of why my service.php is sometimes not found ?
Dunno if it could help but i got exactly the same docker compose working alongside this one (different port) and there is no prob with my php files call.
You are having this issue because you have more than one container with same hostname (php) in same network.
I simulated same scenario, and here is the result.
I'm trying to create a simple LAMP stack in a Docker enviroment. It worked by running a third-party container phpdockerio/php71-fpm:latest, but I wanted a custom PHP container with XDebug installed, for the moment.
My problem is that, if I execute docker-compose up, the PHP container exit after startup before my webserver container can make usage of it. How can I successfully tell the PHP container to wait for a connection of my nginx container?
Command-Line Output
PS C:\playground> docker-compose.exe up
Starting playground_php_1
Starting playground_web_1
Attaching to playground_php_1, playground_web_1
playground_php_1 exited with code 0
playground_web_1 exited with code 1
Dockerfile
FROM php:latest
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
ENTRYPOINT ["docker-php-entrypoint"]
CMD ["php", "-a"]
docker-compose.yml
version: '2'
services:
php:
build:
context: ./etc/php/
dockerfile: Dockerfile
volumes:
- './src:/usr/share/nginx/html'
web:
image: nginx:latest
ports:
- 8080:80
volumes:
- './etc/nginx:/etc/nginx/conf.d'
- './src:/usr/share/nginx/html'
depends_on:
- php
nginx configuration
...
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
...
I got it running, again, with my custom container. I changed the base image from php to php-fpm.
Next thing I did, was that I had to clear running containers and to delete already created images on my machine. Otherwise docker-compose would use the wrong/old container again.
Due to the fact that i live in germany i can say "Good morning" now. Its 04:18:15 and i need some sleep now. But maybe you can help me with this.
These are my first steps with docker and i cant reach the local symfony via my webbrowser (calling http://myproject.dev:8080/).
I get a 502 Bad Gateway Message in my browser
Here is what i have
i have three images. Those are placed in
/home/chucky/dockerimages/
- nginx/
- Dockerfile
- myproject.nginx.conf
- fpmimage/
- Dockerfile
- symfony.pool.conf
- symfony/
- Dockerfile
My Symfony installation (default symfony fetched from symfony installer) can be found under /var/www/symfony
Inside this folder lies a file: docker-compose.yml
Now we come to the 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 to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and 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 you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for 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 you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be 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 as i access http://127.0.0.1:8080/ or http://myproject.dev:8080/
i get new log entries on my 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 to 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 to 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 be helpful to show you the output after i execute
docker-compose up --build
Building symfony
Step 1 : FROM debian:jessie
---> 73e72bf822ca
Step 2 : VOLUME /var/www/myproject
---> Using cache
---> 0f508ee968e9
Successfully built 0f508ee968e9
Building phpfpm
Step 1 : FROM 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
Successfully built 8d18bd852576
Building nginx
Step 1 : FROM 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
Successfully built fa6b92ad1d09
Starting myproject_symfony_1
Starting myproject_phpfpm_1
Recreating myproject_nginx_1
Attaching to myproject_symfony_1, myproject_phpfpm_1, myproject_nginx_1
phpfpm_1 | 2016 03:16:45] NOTICE: fpm is running, pid 1
phpfpm_1 | [13-Nov-2016 03:16:45] NOTICE: ready to handle connections
phpfpm_1 | [13-Nov-2016 03:16:45] NOTICE: systemd monitor interval set to 10000ms
Meanwhile, after many times of debugging i got it running.
So these are my 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 to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and 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 you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for 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 you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be 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 this are all necessary files. But i had to do some more adjustments to get my symfony project running. I ran into problems like "Session Storage was not able to create directory". So i tried to modify the path for "framework.session.save_path" to something else in /app/config.yml. But the solution was more simple than that. I had to take care that the defined folder for framework.session.save_path existed.
In symfony default this is "%kernel.root_dir%/../var/sessions/%kernel.environment%". So i did some chmod and chown for this folder. (And also for cache and logs folders)
created folder /var/www/myproject/var/sessions
chown www-data:www-data /var/www/myproject/var/sessions
chown www-data:www-data /var/www/myproject/var/cache
chown www-data:www-data /var/www/myproject/var/logs
chmod 775 /var/www/myproject/var/sessions
chmod 775 /var/www/myproject/var/cache
chmod 775 /var/www/myproject/var/logs
Since i played around with some configurations in config.yml and nothing worked after this, i forgot to clear out the cache folder. So after i cleared my /var/www/myproject/app/cache folder it worked and i freaked the hell out.
I hope this helped and i did not forgot a step I took, to get my system running. I would like to know if there are any improvements you see in my configuration. I expect that there are many other ways to get a system like this running.