Docker configuration nginx,php7,mysql

Download php7, mysql, nginx

$ docker pull php:7-fpm-alpine
$ docker pull nginx
$ docker pull mysql

Run php

在这里必须挂载目录到php-fpm, nginx不会直接执行,它检测到php文件,会把php文件的路径发到php-fpm去,php-fpm再依据nginx发过来的路径找到代码并执行啊。

$ docker run -it --rm --name xphp --link xmysql:xmysql -v /Users/zhouitpro/www/docker_web:/usr/share/nginx/html php:7-fpm-alpine
# --link xmysql:xmysql 映射mysql

Install php ext

# 安装pdo_mysql
$ docker exec -it run xphp bash
Docker# docker-php-ext-install pdo_mysql
Docker# docker-php-ext-enable pdo_mysql

Run Nginx

nginx config file

server {
    listen       80;
    server_name  localhost;
    root /usr/share/nginx/html/;
    location ~ \.php$ {
        fastcgi_pass xphp:9000; # 这里对应上面的php-fpm别名, php-fpm端口默认是9000
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    location ~ /\.ht {
        deny  all;
$ docker run -it --rm  --link xphp:xphp -v /Users/zhouitpro/www/docker_web:/usr/share/nginx/html  -v /Users/zhouitpro/www/docker/site.conf:/etc/nginx/conf.d/default.conf -p 9090:80  nginx

# -p 是转发端口 外部的 9090对应nginx提供的80端口
# --link 是映射上面的 php-fpm
# -v 是映射本地的web目录到nginx的www目录,和配置文件


$ docker run -it --rm --name xmysql -e MYSQL_ROOT_PASSWORD=root mysql

11 thoughts on “Docker configuration nginx,php7,mysql”

  1. Thank you for every other wonderful article. Where else could anybody get that
    kind of information in such a perfect method of writing?
    I have a presentation subsequent week, and I’m at the look for such info.

  2. I usually do not drop a leave a response, however after reading a few of the remarks here Docker
    configuration nginx,php7,mysql – 秀坤.
    I actually do have 2 questions for you if it’s allright.
    Is it only me or do a few of the remarks come across like they are written by brain dead
    individuals? 😛 And, if you are posting at additional social
    sites, I would like to keep up with everything fresh you have to post.
    Could you make a list of all of your public sites like your linkedin profile,
    Facebook page or twitter feed?

  3. Greate pieces. Keep writing such kind of info on your site.
    Im really impressed by your site.
    Hey there, You’ve done an incredible job. I’ll certainly digg it and in my opinion recommend to my friends.
    I am confident they’ll be benefited from this website.

  4. Admiring the persistence you put into your website and detailed information you provide.
    It’s good to come across a blog every once in a
    while that isn’t the same outdated rehashed material.

    Wonderful read! I’ve saved your site and I’m adding your RSS feeds to my Google account.

  5. Someone essentially assist to make significantly posts I would state.
    This is the first time I frequented your website page and so far?
    I surprised with the analysis you made to make this particular publish extraordinary.
    Great job!

Leave a Reply

Your email address will not be published. Required fields are marked *