Code Monkey home page Code Monkey logo

nginx-php-fpm's Introduction

nginx-php-fpm - build docker hub docker hub Github docker version

Overview

This is a Dockerfile/image to build a container for nginx and php-fpm, with the ability to pull website code from git when the container is created, as well as allowing the container to push and pull changes to the code to and from git. The container also has the ability to update templated files with variables passed to docker in order to update your code and settings. There is support for lets encrypt SSL configurations, custom nginx configs, core nginx/PHP variable overrides for running preferences, X-Forwarded-For headers and UID mapping for local volume support.

If you have improvements or suggestions please open an issue or pull request on the GitHub project page.

Versioning

Docker Tag Git Release Nginx Version PHP Version Alpine Version
latest/docker version Main Branch 1.24-r6 8.2.7 3.18

For other tags please see: versioning

NOTE: From 2.0.5 onwards there are x86 and arm64 builds available

Links

Quick Start

To pull from docker hub:

docker pull richarvey/nginx-php-fpm:latest

Running

To simply run the container:

sudo docker run -d richarvey/nginx-php-fpm

To dynamically pull code from git when starting:

docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' richarvey/nginx-php-fpm:latest

You can then browse to http://<DOCKER_HOST> to view the default install files. To find your DOCKER_HOST use the docker inspect to get the IP address (normally 172.17.0.2)

For more detailed examples and explanations please refer to the documentation.

Documentation

Guides

nginx-php-fpm's People

Contributors

aschonbe avatar auchri avatar boxedcode avatar ciruz avatar decima avatar dormancygrace avatar ebuildy avatar ekohl avatar epoxa avatar fvigotti avatar guice avatar hugome avatar jackmcpickle avatar marcuswelz avatar marek-knappe avatar marsanla avatar mattclarkpgh avatar nclavaud avatar nostro2 avatar richarvey avatar robertobermejo avatar rodion-arr avatar royrico avatar sabakugaara avatar skoschnicke avatar smyth64 avatar svlentink avatar that0n3guy avatar thelittlefireman avatar yuriolive avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nginx-php-fpm's Issues

I like the templates.... but....

If you use the git pull thing it should probably do a git checkout -f to undo the templating. Then the git pull and then reapply the templating. This might be a bit of a problem with git push because the executed templates would be pushed....
Might need a slightly better way. thinking...
Thanks
Andy

Host directory owner changes

When mapping a host directory to the container volume /var/www/html, the owner of the host directory changes. This is annoying, because any update to the code will require changing the owner back.

$ ls -n
drwxrwxr-x 2 1000 1000 4096 sept. 13 22:04 src

$ docker run -d -v $PWD/src:/var/www/html richarvey/nginx-php-fpm
3d7321f9fba01f7ff36970b7525b840e24f36af0ff66d07e21a1814e64b84d09

$ ls -n
drwxrwxr-x 2  100  101 4096 sept. 13 22:04 src

I guess this is because of https://github.com/ngineered/nginx-php-fpm/blob/8137d2d0c5e1b9afa36ba2781a027184dc46ad4b/scripts/start.sh#L92-L93

Is it expected behavior, or am I missing something?

pdo driver no value

I am using the php pdo driver but the pdo driver no value ,how to set?

chown nginx.nginx error

On starting up a container I see the error:

chown: invalid user: 'nginx.nginx'

Changing this to nginx:nginx should fix it.

Default redirect to /index.php

I think nowadays most if not all PHP projects will use some kind of url rewriting that works by simply redirecting all files that are not found to an entry script.

Given some assumptions on configuration:

  1. Your whole PHP project is outside yourwebroot.
  2. There is 1 index.php file in your webroot that is the entry point for the application.
  3. Any files in the webroot can be considered public (ie css / js / images) and should be served directly.
  4. Any URLs that are not found should be redirected to index.php to give the PHP application the option to handle the request.

The only change required to support this is to replace in the default configuration:

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html
    try_files $uri $uri/ =404;
}

With:

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html
    try_files $uri $uri/ /index.php?$args;
}

Some side notes:

  1. I don't think the location / block is needed, you can just put it directly in the server.
  2. I don't think the try_files needs to be repeated inside the php location block.

Swap docker hub to promote php7 as latest

After the branches have been sorted in git hub, docker hub needs to be tweaked so that the "latest" tag and PHP7 tag are built from master and PHP5 is built from the old branch.

rm /usr/share/nginx/html/*

The line:
rm /usr/share/nginx/html/*
in startup script doesn't delete subdirectories nor .git* files causing "git clone" to fail.
I suggest changing it to
rm -Rf /usr/share/nginx/html

php.ini not taken into account

Just check out you new build. Although you edit the file /etc/php5/php.ini in the Dockerfile, the phpinfo() just don't seem to use it. All values are the default ones.

Configuration File (php.ini) Path   /etc/php5
Loaded Configuration File   (none)

mysql.default_socket missing?

I installed this image (php7-bransch) and it looks like a phpinfo(); command gives me the following output:

mysql.default_socket    /var/run/mysqld/mysqld.sock /var/run/mysqld/mysqld.sock

However, when trying to connect to my database it appeared as if there was a problem with the socket so I had a look inside the container and could not find the /var/run/mysqld/ folder.

What am i missing?

Edit: I attached my log from nginx-php-fpm:

nginx-php-fpm-log.txt

letsencrypt-setup changes $WEBROOT back to default path

when i ran docker with WEBROOT specified

docker run --name web -p 80:80 -p 443:443 -e 'WEBROOT=/var/www/html/public' -e 'DOMAIN=mydomain.com -e 'ETC=..' -d richarvey/nginx-php-fpm:latest

docker exec -t web letsencrypt-setup

then i got 404 response from https:// (tcp/80 works just fine)

i found that the /etc/nginx/sites-enabled/default-ssl.conf has been changed from /var/www/html/public to /var/www/html

index.php 404 Not Found

When I try access page index.php it show "404 Not Found".no problem with index.html.
please help me for fix this problem thanks.

Promote PHP7 to master

As PHP5 becomes (all be it) soft end of life in December we need to start staging the master branch to become the master branch.

PHP is not logging errors to stdout or stderr

I have an app installed atop this (Laravel 5.2, but not really relevant here), but I'm not getting any errors showing with docker logs.

As I understand it, supervisord is configured to display all stdout/stderr messages from the php5-fpm and nginx processes.

In an attempt to fix it, I edited the php5-fpm config file to disable cache_workers_output which redirects stdout/stderror to a log file.

; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
catch_workers_output = no

But still having no joy. This configuration value has indeed stopped it logging to /var/log/php5-fpm.log, but it's also not appearing in /tmp/supervisord.log / docker log either...

I'm fairly certain I've got errors being sent to stderr (I manually created a script to write to php://stderr).

Any ideas?

403 Forbidden

Hi,

Sorry docker noob here. But I get 403 Forbidden with this package when I try to mount a volume on my host machine.

Docker seems to be running as root, so I am not sure why it would happen. It should have read access everywhere no?

Is it 403 on the host machine files, or files inside the container? I am not sure how to debug this.

Any tips?

php5-soap in php7 build

Ran into issue of SoapClient not found on :php7 Looks like the extension for soap was missed as it is still php5.

Exif PHP extension

Hi,

I have a problem with the exif extension when I run my website on nginx-php-fpm container :

Error: Call to undefined function PHPExif\Adapter\exif_read_data()

My website runs well on my non-Docker installation (Archlinux/Nginx/PHP-FPM). Any ideas ? I've tried some tweaks but I didn't find nothing related to extensions.

Thank you !

docker image php7 has wrong php-fpm sock location

I just pulled the latest php7 image (docker run --detach richarvey/nginx-php-fpm:php7) and I saw that I was getting this error:

2016/09/08 16:34:43 [crit] 67#0: *15 connect() to unix:/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client:

I changed the location of the sock file in /etc/nginx/sites-enabled/default.conf to /var/run/php-fpm.sock and reloaded nginx and it all worked fine.

Trying to build from the php7 branch gives the following errors:

ERROR: unsatisfiable constraints:
  php7-ctype (missing):
    required by: world[php7-ctype]
  php7-curl (missing):
    required by: world[php7-curl]
  php7-dom (missing):
    required by: world[php7-dom]
  php7-fpm (missing):
    required by: world[php7-fpm]
  php7-gd (missing):
    required by: world[php7-gd]
  php7-iconv (missing):
    required by: world[php7-iconv]
  php7-intl (missing):
    required by: world[php7-intl]
  php7-json (missing):
    required by: world[php7-json]
  php7-mcrypt (missing):
    required by: world[php7-mcrypt]
  php7-memcached (missing):
    required by: world[php7-memcached]
  php7-mysqli (missing):
    required by: world[php7-mysqli]
  php7-mysqlnd (missing):
    required by: world[php7-mysqlnd]
  php7-openssl (missing):
    required by: world[php7-openssl]
  php7-pdo (missing):
    required by: world[php7-pdo]
  php7-pdo_mysql (missing):
    required by: world[php7-pdo_mysql]
  php7-pdo_pgsql (missing):
    required by: world[php7-pdo_pgsql]
  php7-pgsql (missing):
    required by: world[php7-pgsql]
  php7-phar (missing):
    required by: world[php7-phar]
  php7-sqlite3 (missing):
    required by: world[php7-sqlite3]
  php7-xml (missing):
    required by: world[php7-xml]
  php7-xsl (missing):
    required by: world[php7-xsl]
  php7-zip (missing):
    required by: world[php7-zip]
  php7-zlib (missing):
    required by: world[php7-zlib]

ERROR: An another FPM instance seems to already listen on /var/run/php-fpm.sock

After cloning the branch php7, completing a docker build & run as-is, getting issues starting up php-fpm7.

~/github/nginx-php-fpm (php7) docker run -ti nginx-php-fpm
2016-08-18 17:38:42,558 CRIT Set uid to user 0
2016-08-18 17:38:42,564 INFO RPC interface 'supervisor' initialized
2016-08-18 17:38:42,565 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2016-08-18 17:38:42,565 INFO supervisord started with pid 9
2016-08-18 17:38:43,569 INFO spawned: 'php-fpm7' with pid 12
2016-08-18 17:38:43,570 INFO spawned: 'nginx' with pid 13
2016-08-18 17:38:43,601 INFO exited: php-fpm7 (exit status 0; not expected)
2016-08-18 17:38:44,604 INFO spawned: 'php-fpm7' with pid 23
2016-08-18 17:38:44,604 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
[18-Aug-2016 17:38:44] ERROR: An another FPM instance seems to already listen on /var/run/php-fpm.sock
[18-Aug-2016 17:38:44] ERROR: FPM initialization failed
2016-08-18 17:38:44,631 INFO exited: php-fpm7 (exit status 70; not expected)

2016-08-18 17:38:46,643 INFO spawned: 'php-fpm7' with pid 25
[18-Aug-2016 17:38:46] ERROR: An another FPM instance seems to already listen on /var/run/php-fpm.sock
[18-Aug-2016 17:38:46] ERROR: FPM initialization failed
2016-08-18 17:38:46,670 INFO exited: php-fpm7 (exit status 70; not expected)
2016-08-18 17:38:49,679 INFO spawned: 'php-fpm7' with pid 27
[18-Aug-2016 17:38:49] ERROR: An another FPM instance seems to already listen on /var/run/php-fpm.sock
[18-Aug-2016 17:38:49] ERROR: FPM initialization failed
2016-08-18 17:38:49,708 INFO exited: php-fpm7 (exit status 70; not expected)
2016-08-18 17:38:50,710 INFO gave up: php-fpm7 entered FATAL state, too many start retries too quickly

Alpine linux & nginx version

After updating to alpine linux, the nginx version provided doesn't provide the realip module:

nginx: [emerg] unknown directive "set_real_ip_from" in /etc/nginx/sites-enabled/[...]

PHP version

How about using php5.6 or even php7, is this doable ?

php mail / sendmail doesn't work

Error: "sendmail: can't connect to remote host (127.0.0.1): Connection refused"

Steps to reproduce: Use php mail function or the sendmail function, check logs for error. It seems sendmail is installed. I can run it from the console, but returns the above error.

OS: Ubuntu 16.04
Other containers jwilder/nginx-proxy | thomastweets/docker-letsencrypt-nginx-proxy-companion

ZipArchive?

qq 20160825152537
does not exist ZipArchive
ZipArchive must be available

Request to add session support

By default, session support doesn't seem to be is not enabled. I know this prevents Laravel applications from working out of the box, but I think this may also affect Symfony's HttpFoundation component.

Would you consider adding php5-session/php7-session to the defaults?

Error in docker log

I get a lot of this error when I try to run the stable image

sed: -e expression #1, char 18: unknown option to `s'

I run mariadb like this

docker run --name mariadb -e MYSQL_ROOT_PASSWORD=******** -e MYSQL_DATABASE=ocloud -e MYSQL_USER=ocloud_user -e MYSQL_PASSWORD=********* -d mariadb

I run nginx-pgp-fpm as follows:

docker run -v /home/cosku/owncloud/www/owncloud-8.1:/usr/share/nginx/html -v /home/cosku/owncloud/ssl:/etc/nginx/ssl -v /home/cosku/owncloud/sites-enabled:/etc/nginx/sites-enabled -p 80:80 --link mariadb:mysql -d richarvey/nginx-php-fpm:stable

Can't get enviroment variables to work as described

I'm trying to set up this container and have it be linked to a mysql container, but I can't work out how to get access to the enviroment variables for things like the mysql server's IP, and so on.

I'm launching the mysql container like so:

sudo docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=yayMySQL -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wordpress_user -e MYSQL_PASSWORD=wordpress_password -d mysql

And the nginx-php-fpm container like so:

sudo docker run --name nginx -p 80:80 -e TEMPLATE_NGINX_HTML=1 -v /home/username/www/html:/usr/share/nginx/html --link some-mysql:mysql -d richarvey/nginx-php-fpm

Inside ~/www/html, I have a file called index.php, with the following code:

<?php $database_name = $$_MYSQL_ENV_MYSQL_DATABASE_$$; ?>

In a browser, this yields the error:

Parse error: syntax error, unexpected '$' in /usr/share/nginx/html/index.php on line 1

Other variations do the same thing. PHP just doesn't like those dollar signs in all instances.
print_r($_ENV); displays an empty array. get_env() on all the variables mentioned in the documentation yields nothing.

How is this meant to work?

Split documentation

Split the docs up to make it easier to read and produce getting started guides

Can't pull code from git

Hi,I was puzzled by Dynamically Pulling Code from git.My steps are blow:

  • pull image
  • ssh-keygen -t rsa -C "my.email" && enter enter...
  • add ~/.ssh/id_rsa.pub to github
  • git clone [email protected] proj to proj dir
  • base64 -w 0 ~/.ssh/id_rsa.pub and copy the result
  • sudo docker run --name aha -d -v /path/to/proj:/var/www/html -e '[email protected]' -e 'GIT_BRANCH=develop' -e 'SSH_KEY=paste' -e 'GIT_NAME=myname' -e 'GIT_EMAIL=myemail' --link db:db richarvey/nginx-php-fpm

and In my proj there is just only a index.php file which likes this:

<?php
$name = 'test';
echo "hello $name";
?>

after Running the docker command I can see it is running by sudo docker ps but I cannot access the url host:80

And when modify the proj remotely and push it ,I cannot run sudo docker exec -it aha /usr/bin/pull to pull the latest code,it reports that it uses /root/.ssh/id_rsa to verify my identity which looks very strange.
How can I solve this problem?Thx

PHP7 Does not have php alias.

When using the php7 tag the php cli is not available as php, instead it is only available as php7 which breaks things like composer.

apt-get update required AFTER adding ppa

Hi,

it seems that in commit 195e699 you moved the apt-get update command before the apt-add-repository command, which makes sense to install the latest software-properties-common. However you still have to update after adding the ppa because otherwise the nginx shipped with ubuntu will be installed and not the one from the ppa.

Undefined GLOB_BRACE

One of our internal libraries uses GLOB_BRACE and using this container I'm getting:

 Use of undefined constant GLOB_BRACE

Ideas on how to solve?

Do you not have VOLUME directive in Dockerfile for a reason?

I really like the simplicity of the project, and would like to use it in DEV and in Production environments. I'm wondering if this is intentional that you don't have VOLUME directive in the Dockerfile, which would allow for a more standard workflow on a developer's machine?

I would suggest allowing to bind volume for /var/www/html, or since there's a repo layout proposition than maybe as an option something like /var/www/html/src ..

or do you not include it for some specific reason?

PS: what i mean by more standard, is that developer can continue to work within local file system, rather than having to work through dockerized volume.

Questions for ubuntu:14.04

I'm try to build an different image, so i use ubuntu:14.04
But i'm not found "listen = 127.0.0.1:9000" in /etc/php5/fpm/php-fpm.conf

Problems with Composer / Doctrine in nginx-php-fpm

I'm having issues getting Composer to work in a convenient way, and running with Doctrine does not appear to work at all.

I'm trying to execute all my Composer commands from outside of my container - usually I'd do:

docker exec [container-id] composer install

This unfortunately doesn't appear to work with this image - I'm getting the following error:

"PHP Fatal error: Class 'Phar' not found in /usr/bin/composer on line 23"

I can get around this problem with no real issue - executing:

docker exec [container-id] /bin/sh -c "cd /var/www/html/; php7 /usr/bin/composer install"

This works - all my composer packages are installed as expected. It's a rather ugly solution though and it makes me think something is probably not in order with the composer installation. Maybe an incorrect assumption?

The real issue however, is that i can't use the doctrine package.

Running:

docker exec [container-id] /bin/sh -c "cd /var/www/html/; vendor/bin/doctrine"

(which should give me the doctrine CLI) throws me an error:

"PHP Fatal error: Class 'PDO' not found in /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php"

Not really sure how to get passed this problem... Anyone having similar problems? Or maybe ideas that could point me in the right direction?

(I'm using the php7 branch of the nginx-php-fpm repo by the way)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.