GithubHelp home page GithubHelp logo

million12 / docker-nginx-php Goto Github PK

View Code? Open in Web Editor NEW
123.0 8.0 66.0 76 KB

Docker with Nginx / PHP-FPM 7.3 7.0 5.6 5.5

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

Shell 42.83% Dockerfile 57.17%

docker-nginx-php's Introduction

Nginx + PHP-FPM docker container

Build Status
GitHub Open Issues GitHub Stars GitHub Forks
Stars on Docker Hub Pulls on Docker Hub

Docker build

Felling like supporting me in my projects use donate button. Thank You!

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:php74 - PHP 7.4 # built from php74 branch
  • million12/nginx-php:php73 - PHP 7.3 # built from php73 branch
  • million12/nginx-php:php70 - PHP 7.0 # built from php70 branch
  • million12/nginx-php:php56 - PHP 5.6 # built from php56 branch
  • million12/nginx-php:php55 - PHP 5.5 # built from php55 branch

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.4 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.14.1
  • Ruby 2.3
  • Bundler
  • NodeJS
  • 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])

docker-nginx-php's People

Contributors

dimaip avatar pozgo avatar ryzy 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

docker-nginx-php's Issues

Understanding the Dockerfile of this project

I am studying carefully the Dockerfile from this project since I need to build something similar but based on Ubuntu and less complex. I have a few questions regarding it and I hope @ryzy can help me :)

I can see zz-php-directories.ini and zz-php.ini in container-files directory, I guess those are some PHP configurations that gets override, so my first question is: where? I mean where in the Dockerfile or maybe in a .sh script did you override them?

Maybe I am complete lost and this is something basic from Docker but I am still learning

Add latest MariaDB support instead of MySQL

@ryzy I would like to drop MySQL support and add support for MariaDB but I have a problem: how to deal with mysql_secure_installation which is intended to be interactive. I am following this guide but that I mention is my only concern, can you help me out a bit?

Also is a good practice to keep database files inside the docker container or would be fine to share in some volumes under the host? What do you think?

PS: If you can take a look to the fork I have created from this repo and see the new lines removing MySQL from default and adding MariaDB and let me know your toughs.

Mapped volumes, where did they go under the host?

I've seen this on docs:

/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

My question is, where this directories are mapped on the host?

how to use this image? I cannot make it working

Step to do

Method 1

$ docker run -d -v $PWD/data --name=web-data busybox
$ docker run -d --volumes-from=web-data -p=8006:80 --name=web million12/nginx-php
$ docker ps | grep web
f2090bfc52ce million12/nginx-php "/config/bootstrap.sh" 5 minutes ago Up 5 minutes 443/tcp, 9111/tcp, 0.0.0.0:8006->80/tcp web

Method 2

$ git clone https://github.com/million12/docker-nginx-php.git
$ cd docker-nginx-php
$ docker build -t nginx-php-fpm .
$ docker run -d -v $PWD/data --name=web-data busybox
$ docker run -d --volumes-from=web-data -p=8006:80 --name=web million12/nginx-php

Result

  • Both method giving the same result.
  • Open browser
  • Type: http://localhost:8006
  • it shows (changed on every refresh):
    • This site can’t be reached
    • This page isn’t working

image
image

Actually, I need to use php 5.6.
But, will try latest update first.
Please help. Thanks.

missing mysql extension for PHP?

I'm trying to use your image to run a container which runs nginx and php, which connects to the official mysql container.

When I try to start my Joomla application, tho, it says:

Error displaying the error page: Application Instantiation Error: Could not connect to MySQL.

After some digging, I've found that the MySQL extension is not loaded in PHP.

I've then mounted /etc/php.d and used it to load a custom ini file with inside:

extension=/usr/lib64/php/modules/mysql.so
extension=/usr/lib64/php/modules/mysqli.so

(I've also tried writing just mysql.so without the full path)

But nothing seems to load...

Any clue?

cannot run composer using RUN command

After build docker image
When it reach RUN composer install command
I got this response

Step 6 : RUN composer install --prefer-source --no-interaction
 ---> Running in 06cfef7336f4
/usr/bin/env: php: No such file or directory
The command '/bin/sh -c composer install --prefer-source --no-interaction' returned a non-zero code: 127

Please advise.

problem in osx, volume permissions ...

/config/init/20-php-dirs.sh
not working

[root@f756d2e59450 data]# ls -li /data/tmp/php
total 0
1773 drwxr-xr-x 1 1000 ftp 68 Oct 27 13:30 sessions
1772 drwxr-xr-x 1 1000 ftp 68 Oct 27 13:30 uploads

can not change user www:www

do not allocate TTY?

I've got a little problem with this image.

It's quite weird, but if I run docker-compose run web ls from within my VPS, it all works out fine.
However, if I try to run it over SSH, like so: ssh myvps docker-compose run web ls it very annoyingly always attached to the tty, so my process never exits. Also, if I CTRL+C, the container keeps hanging around if I do docker-compose ps as docker_run_web_XX...

Do you have any idea how to mitigate this problem?

Update Ruby and NodeJS/npm to the newer versions (not available in yum repos)

Because we need to compile it from the source, we could use trick like here (to install development tools and uninstall them afterwards):

https://github.com/promptworks/docker-ruby-2.1/blob/master/install_ruby.sh

export RUBY_INSTALL_VERSION=0.4.3
export RUBY_VERSION=2.1.2

cd /tmp

yum list installed | cut -f 1 -d " " | uniq | sort > /tmp/pre
yum install bzip2 git tar wget -y

wget -O ruby-install-$RUBY_INSTALL_VERSION.tar.gz \
  https://github.com/postmodern/ruby-install/archive/v$RUBY_INSTALL_VERSION.tar.gz
tar -xzf ruby-install-$RUBY_INSTALL_VERSION.tar.gz
cd ruby-install-$RUBY_INSTALL_VERSION
make install
ruby-install -i /usr/local ruby $RUBY_VERSION

make uninstall
yum list installed | cut -f 1 -d " " | uniq | sort > /tmp/post
diff /tmp/pre /tmp/post | grep "^>" | cut -f 2 -d ' ' | xargs echo yum erase -y
yum clean all
rm -rf /usr/local/src/ruby*
rm -rf /tmp/*

A few questions regarding customization of this container

So, I've been reading carefully each file under container-files directory because I want to add xdebug extension and also install some composer packages by default and under global but I've a few questions regarding this:

  • Add xdebug would be easy as add php70-php-pecl-xdebug extension but, where I should add the default configuration for xdebug to work properly? I mean the configuration that install by default under /etc/php.d/15-xdebug.ini file on Fedora/CentOS.
    • How do I expose the port 9001 so I can use it from within the IDE? The port should be listening for incoming connection from the host.
    • How do I install some composer packages globally like PHP Code Sniffer, PHP Mess Detector and so on?
    • I've seen that composer is already included on the container, is installed globally?

That's it. Can any one help me to achieve this?

Starting my own repository based on yours or fork this and add my contribution to a new branch?

Hi there, I have recently decide to start my own repository based on yours since it's an excellent job, why?because yours has several things that I wont use and will make the image larger (like Node, Ruby or NMP packages). Also I want to add my own libraries as Xdebug so I have open this question in StackOverflow and I would like to know your opinion before keep going.

I don't know if that's the right way or choice or you have a better idea but I am open to heard about them.

Thx in advance

Temp directory not writable by Composer?

In my Dockerfile I have a composer run directive: RUN composer --working-dir=/data/www install`.

I cannot get this to run successfully, I keep getting the error message:

PHP temp directory (/data/tmp/php) does not exist or is not writable to Composer. Set sys_temp_dir in your php.ini
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Generating optimized autoload files

Any idea why this is happening and how can I fix it?

I am using million12/nginx-php:latest

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.