Comments on Dockerizing Wordpress with Nginx and PHP-FPM on Ubuntu 16.04

In this tutorial, I will guide you step-by-step to use docker-compose. We will deploy 'Wordpress' with Nginx, MySQL, and PHP-FPM. Each service has its own container, and we will use images from the docker hub registry. I will show you how to create containers from docker images and manage all containers with docker-compose.

26 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: TiTex

docker.io package is alwasy outdated , you should check this page to install latest docker https://docs.docker.com/engine/installation/linux/ubuntu/

usermod -a -G hakase dockershould be usermod -a -G  docker hakase

 

 

Next, create new file called 'docker-container.yml', and create a new directory for the project. Just type the commands below:should beNext, create new file called 'docker-compose.yml', and create a new directory for the project. Just type the commands below:

 

you do not need to expose ports on the host for mariadb and php-fpm , if you don't want to do anything with them

    ports:        - '9000:9000'     ports:        - '3306:3306

By: nam

some small mistake in command when add user to docker group

"usermod -a -G hakase docker" 

usermod -a -G docker hakase

By: till

Thank you @TiTex and @nam. I've corrected the tutorial.

By: David Dumonde

I haven't been able to create more than one wordpress site on a single host using docker-compose. Any suggestions for creating multiple wp containers with this setup?

By: PokePango

Don't know if it's the best solution but you could create another Nginx docker that will use the port 80. It would be the only one to use this port and all the others Nginx docker will pass through it.

By: TiTex

you need to change each nginx container's ports to something unique like

    ports:        - '8080:80'

    ports:        - '8081:80'

By: David Dumonde

Thanks, @TiTex, that works in a sense, but it will leave the url exposed as example.com:8080 or example.com:8081. Without docker, I can set up nginx server blocks for each domain so that they listen :80, and then are separated by their root, such as root /var/www/html/site1 or root /var/www/html/site2 without needing separate ports. So I don't think the port settings are the answer I'm looking for, but I appreciate your help.Right now I'm looking at how to change the location block setting for different sites to fastcgi_pass site1:9001 or fastcgi_pass site2:9002. I got it to work with two sites, then when I added a third site I started getting 502 bad gateway errors. I'm still tinkering.

By: Marc

Hey David, did you finally worked it out? I'm struggling with a very similar issue by using multiple compose configurations.Any information / update on this would be wonderful :)

By: ofthesun9

Thanks for this clear & simple howto !

What would be the changes required to have wordpress install in "mysite.com/blog" instead of mysite.com ?

By: Joe Sixpack

Great tutorial. Thanks for posting and making docker easy. One feature request is to have phpmyadmin added to the docker-compose mix. 

By: RonNa

I followed exactly above. It worked ;-)

I want to add phpmyadmin (complete compos file):

nano docker-compose.yml-------------------------------------version: '2'services:   nginx:     image: nginx:latest     ports:       - '80:80'     volumes:       - ./nginx:/etc/nginx/conf.d       - ./logs/nginx:/var/log/nginx       - ./wordpress:/var/www/html     links:       - wordpress     restart: always   mysql:     image: mariadb     ports:       - '3306:3306'     volumes:       - ./db-data:/var/lib/mysql     environment:       - MYSQL_ROOT_PASSWORD=aqwe123     restart: always   wordpress:     image: wordpress:4.7.1-php7.0-fpm     ports:        - '9000:9000'     volumes:       - ./wordpress:/var/www/html     environment:       - WORDPRESS_DB_NAME=wpdb       - WORDPRESS_TABLE_PREFIX=wp_       - WORDPRESS_DB_HOST=mysql       - WORDPRESS_DB_PASSWORD=aqwe123     links:       - mysql     restart: always   phpmyadmin:     depends_on:       - mysql     image: phpmyadmin/phpmyadmin     restart: always     ports:       - 8081:80     environment:       PMA_HOST: mysql       MYSQL_ROOT_PASSWORD: aqwe123     networks:       - backnetworks:   back:volumes:   db_data:-------------------------------------

However, if I try phpmyadmin it says host mysql not found. Where do I think wrong?

 

 

By: Denver Prophit Jr.

It would be really nice if you focused on https only with http2 instead of non https wordpress. Insecure login is very bad.

By: Paul

I tried this on my mac and getting a 502 gateway error. Been trying lots of different configurations with no luck.

By: nbrb

502 error is caused by the following error:

request: "GET /info.php HTTP/1.1", upstream: "fastcgi://172.17.0.3:9000"

as you can see it is using ip 172.17.0.3 from hosts file on nginx container

 

By: Senrabdet

This post is really helpful.  It worked for me (eventually would like to add in the ssl stuff, but actually prefer just http as a way to get started).  I am trying to add in a reverse proxy, so one could have a single public ip and multiple instance of lamp/wordpress with logins as distint upstream docker instances.  My assumption is this would include being done with locations.  Has anyone done this?  My attemps so far are unsuccessful.  Can share my code attempts if that would help?  Thx

By: Apurva Bhandari

I did exactly the same as mentioned above as it is but not working at all.

nginx:

    image: nginx:latest

    ports:

        - '80:80'

    volumes:

        - ./nginx:/etc/nginx/conf.d

        - ./logs/nginx:/var/log/nginx

        - ./wordpress:/var/www/html

    links:

        - wordpress

    restart: always

 

mysql:

    image: mysql

    ports:

        - '3306:3306'

    volumes:

        - ./db-data:/var/lib/mysql

    environment:

        - MYSQL_ROOT_PASSWORD=root123

    restart: always

 

wordpress:

    image: wordpress:4.7.1-php7.0-fpm

    ports:

        - '9000:9000'

    volumes:

        - ./wordpress:/var/www/html

    environment:

        - WORDPRESS_DB_NAME=wpdb

        - WORDPRESS_TABLE_PREFIX=wp_

        - WORDPRESS_DB_HOST=mysql

        - WORDPRESS_DB_PASSWORD=aqwe123

    links:

        - mysql

    restart: always

 

here is output;

502 Bad Gateway

i tried with serverip/localhost/127.0.0.1/172.17.0.1 but same error

nginx/wordpress.conf

server {

    listen 80;

    server_name wp-abc.co;

 

    root /var/www/html;

    index index.php;

 

    access_log /var/log/nginx/access.log;

    error_log /var/log/nginx/error.log;

 

    location / {

        try_files $uri $uri/ /index.php?$args;

    }

 

    location ~ \.php$ {

        try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass wordpress:9000;

        fastcgi_index index.php;

        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_param PATH_INFO $fastcgi_path_info;

    }

}

 

logs/nginx/error.log

[error] 5#5: *20 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: wp-abc.co, request: "GET / HTTP/1.1", upstream: "fastcgi://172.17.0.3:9000", host: "localhost"

I don't know where is the issue. Please help me out for the configuration.

By: Sascha

I have the exact same problem with Ubuntu 18.04 and the same configuration now. How did you fixed it?

By: patrick

Bonjour,

je cherche ou se trouve php.ini car je suis limité a 2Mo 

Merci

 

ps: c'est le seul tuto qui fonctionne pour moi.

By: Raj

Great Explanation.

By: Patrick

I have the same problem.

Did you solved it?

If yes, what is the solution?

By: Sascha

I'm also looking for the solution of this problem. Did you solved it?

By: Philippe

Hello,

I am a bit confused about volumes;

Can anybody explain why 

    volumes:

        - ./wordpress:/var/www/html

Is needed for php-fpm and nginx, and how it does work behing the scenes ?

 

Thanks 

By: Noy Tsarfaty

Amazing! Very explicit and helpful. Thanks a lot :) 

By: Tobias

Hello,

I checked out the code but it is not working on my mac os in the browser. 

Any idea??

"This site can’t be reached

Check if there is a typo in wp-hakase.co.

DNS_PROBE_FINISHED_NXDOMAIN"

By: asuran

what will be the server ip?

how to find my server ip address?

 

By: srikanth

Hello Sir ,

Can you the same POC with separate compose files for each like nginx-php-fpm compose , sql compose and wordpress compose file please i am trying that please help me.

 

Regards,

Srikanth