Coder Social home page Coder Social logo

hetian9288 / docker-nginx-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from million12/docker-nginx-php

0.0 2.0 0.0 64 KB

Docker with Nginx / PHP-FPM 7, 5.6, 5.5. CentOS-7 based.

Home Page: https://registry.hub.docker.com/u/million12/nginx-php/

Shell 100.00%

docker-nginx-php's Introduction

Nginx + PHP-FPM docker container

This is a million12/nginx-php docker container with Nginx + PHP-FPM combo.

For different PHP versions, look up different branches of this repository.
On Docker Hub you can find them under different tags:

  • million12/nginx-php:latest - PHP 7.0 # built from master branch Circle CI
  • million12/nginx-php:php70 - PHP 7.0 # built from php70 branch Circle CI
  • million12/nginx-php:php56 - PHP 5.6 # built from php56 branch Circle CI
  • million12/nginx-php:php55 - PHP 5.5 # built from php55 branch Circle CI

BREAKING CHANGES (2015-12-19) !!!

million12/nginx-php:latest is now PHP 7.0 !!!

Since PHP 7 has been released, we retagged :latest Docker image tag so it now contains PHP 7.x version.
For PHP 5.6 (old :latest) is now available as million12/nginx-php:php56.

Things included:

- Nginx with HTTP/2 support

This image is based on million12/nginx.
Default vhost is configured and served from /data/www/default. Add .php file to that location to have it executed with PHP.

- PHP-FPM

PHP 7.0 is up & running for default vhost. As soon as .php file is requested, the request will be redirected to PHP upstream. See /etc/nginx/conf.d/php-location.conf.

File /etc/nginx/fastcgi_params has improved configuration to avoid repeating same config options for each vhost. This config works well with most PHP applications (e.g. Symfony2, TYPO3, Wordpress, Drupal).

- PHP basic tuning

Custom PHP.ini directives are inside /etc/php.d.

- Common dev tools for web app development

  • git 2.x
  • Ruby 2.0, Bundler
  • NodeJS and NPM
  • NPM packages like gulp, grunt, bower, browser-sync

Directory structure inside image

/data/www # meant to contain web content
/data/www/default # root directory for the default vhost
/data/logs/ # Nginx, PHP logs
/data/tmp/php/ # PHP temp directories

Error logging

PHP errors are forwarded to stderr (by leaving empty value for INI error_log setting) and captured by supervisor. You can see them easily via docker logs [container]. In addition, they are captured by parent Nginx worker and logged to /data/logs/nginx-error.log'. PHP-FPM logs are available in /data/logs/php-fpm*.log` files.

- pre-defined FastCGI cache for PHP backend

It's not used until specified in location {} context. In your vhost config you can add something like this:

location ~ \.php$ {
    # Your standard directives...
    include               fastcgi_params;
    fastcgi_pass          php-upstream;

    # Use the configured cache (adjust fastcgi_cache_valid to your needs):
    fastcgi_cache         APPCACHE;
    fastcgi_cache_valid   60m;
}

Usage

docker run -d -v /data --name=web-data busybox
docker run -d --volumes-from=web-data -p=80:80 --name=web million12/nginx-php

After that you can see the default vhost content (something like: 'default vhost created on [timestamp]') when you open http://CONTAINER_IP:PORT/ in the browser.

You can replace /data/www/default/index.html with index.php and, for instance, phpinfo() to inspect installed PHP setup. You can do that using separate container which mounts /data volume (docker run -ti --volumes-from=web-data --rm busybox) and adding the file to the above location.

Customise

There are several ways to customise this container, both in a runtime or when building new image on top of it:

  • See million12:nginx for info regarding Nginx customisation, adding new vhosts etc.
  • Override /etc/nginx/fastcgi_params if needed.
  • Add custom PHP *.ini files to /etc/php.d/.
  • Add own PHP-FPM .conf files to /data/conf/php-fpm-www-*.conf to modify PHP-FPM www pool.

ENV variables

NGINX_GENERATE_DEFAULT_VHOST
Default: NGINX_GENERATE_DEFAULT_VHOST=false
Example: NGINX_GENERATE_DEFAULT_VHOST=true
When set to true, dummy default (catch-all) Nginx vhost config file will be generated in /etc/nginx/hosts.d/default.conf. In addition, default index.php file will be created displaying results of phpinfo(). Caveat: this causes security leak because you expose detailed PHP configuration - remember to remove it on production! Use it if you need it, for example to test that your Nginx is working correctly AND/OR if you don't create default vhost config for your app but you still want some dummy catch-all vhost.

STATUS_PAGE_ALLOWED_IP
Default: STATUS_PAGE_ALLOWED_IP=127.0.0.1
Example: STATUS_PAGE_ALLOWED_IP=10.1.1.0/16
Configure ip address that would be allowed to see PHP-FPM status page on /fpm_status URL.

Authors

Author: ryzy ([email protected])
Author: pozgo ([email protected])


Sponsored by Prototype Brewery - the new prototyping tool for building highly-interactive prototypes of your website or web app. Built on top of Neos CMS and Zurb Foundation framework.

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.