How to set up WordPress and Nginx based Docker Container in 2020

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and I serve very long time welcome back to WP gates again in this video what I'm going to do is try to use nginx as a reverse proxy to sort of work bris container if you have been following this channel you must have seen in the last video we created a wordpress instance using docker container and for that used a default Apache based container but there's another way of doing this which is using nginx and the reason we want to use nginx would be that it could be used as a reverse proxy which means that it can be used not just to serve WordPress but you know it could be used to serve more applications with a single air and point so yeah let's jump into it to begin with what I'm going to do is create a new docker compose file and let's call it darker those objects one of the really good things about docker compose is that you can override one file with the other so we can use our original docker compose yml file as our based docker compose file and an extra configuration in our genetics file and let's try to see how we could do that so I'm going to copy the first two services version and now coming to the wordpress part you I'm also gonna copy everything but instead of using a wordpress version 5 I will use WordPress out of time well actually I forgot the container name so [Music] let's find that out quickly so it's called the PHP 7.4 fpm top 5 we can also build it from PHP 7.3 or we can also build it from PHP 7.2 actually know the default image is 7.3 so let's go into 7.3 our point 5 - - fpm - elf - the short name so let's use that five five p.m. - pi - a quick description about PHP FPN is it's nothing but a process manager so many requests comes through a web server it hands it over to another application server to do the processing in our case the application server could be PHP fpm so what PHP fpm does is it executes the PHP part and then hands over the content back to the server Apache has modules built inside it which does that so you don't need an additional middle layer or middle process manager to do that nginx doesn't have that part built in so that's why I've used fpm which is the fast process manager so what happens is that we will need two containers one is the WordPress container which only uses WordPress and serves it through fpm and then we also need an engine X container to actually access the user request or to handle the web server server part having Terrell everything else remains the same oh yeah another thing that changes is that this image doesn't really exposed port 80 because port 80 now is supposed to be served through and nginx that's our web server this is not our web server anymore but the port it actually exposes is 9,000 so we're going to change that and let us call the WordPress image as WordPress fpm and now the important part the way we run these docker the way we merge these darker files is by using this special map doctor docker compose remains the same then we use F and then followed by the first base file then F followed by this second bit second file and want to override and then applies it but before doing that let me quickly show you what docker machines are running so right now I have two darker containers running which are experiments WordPress a new experiment DB these are based on the containers we built on our previous videos and now let's see what happens when I run the new command basically I should be seeing a third container actually up also works fine but I think I should be passing these at the end so the order actually matters let's take a look FPS perfect we have fpm image also running now and it's exposing pork by a thousand as you can see and we have birdbreasts which is exposing support 82 port 8000 so what we'll do next is create an engine X image and try to hook this up to the WordPress fpm image and let us run it on 8000 won so the next thing I'm gonna do is find nginx image I have nginx latest or I have nginx table so I'm gonna use the stereo let's call this nginx - genetics and the port that we want to expose at the container name so container name okay I made a small mistake my last container name this should be called fpm and the new one will be called into next let's try to rub this and see if we have her nginx container made an error somewhere so the container name and gen-x already exists yeah because our previous container was called engine X so the fix for this is just broker close now and then restarting everything you going to manually stop these containers down again yet there are often good dinners which people remove you okay splash cleaner all right so now we have our nginx running as well and it is also running on port 80 they forgot to map the engine exports so I'm going to do that next X support 82 8001 run the command again I'll check what's happening this is our original WordPress we haven't touched it yet and 8001 is our nginx so the engineer X server is also running fine the next thing I want to do is connect the nginx to fpm and I don't know how to do that so I'm gonna read a blog or something let's go with medium so usually there is an engine X file that I need to create rich Maps engine X's 482 FP m support by a thousand that's all it needs to be done and yeah look at the Vesta file which is the nginx conf so created correct renamed nginx the rural context you instead we are going to create a directory named conflict the name of it's called nginx Kampf this is the server listening on port 80 and clamping to WordPress 9000 so this WordPress is nothing but hostname but in our case it's called WordPress experiments we can either use this or we can use this I'm going to use this word for 7:00 p.m. 9000 and that should be it I think let's try to actually no that is not it yet we need to map this file inside the nginx container I won't go back to our genetics override /gx is mapped to this path inside the katare and hopefully that should be it so what I'm expecting to happen is when I open up localhost port 8000 1 it should simply redirect me back to localhost 8000 if everything is working fine then the page local o / 8000 a local O's 8001 should open but then WordPress will try to check if the URL in the browser is same as the website name in this case it won't because the website is on localhost for a thousand so then it'll probably try to redirect I don't know if I'm correct but this is how I am assuming so it should just go - it should either load WordPress on big thousand one or it should just redirect to 8000 neither case I'm gonna say that it is working so running the command restart my game here as you can see docker compose is actually really smart it it detects link configuration that has changed and only restarts those containers the other containers are just untouched so now let's go back and see what happens to our 8001 there you go so it got redirected to 8 8,000 which means everything's working fine at this point what we want to do is get rid of our existing Apache server we don't need that anymore right and we want to replace that Apache server with the brand-new fpm image so what we can do is we can actually override all of this in this case the we daughter converse overrides work is that it it uses all the configuration from the base image and then if something with the same key value exists say as sorry if something with the same key exists then it overrides so we actually don't need all of this here because it's already defined in the base image we also don't need this we definitely need the port we don't need links and depends we don't need restart I think this is all we need I'm going to restart it again at this point but I will start this container worthless five should not launch because technically with this command it doesn't exist so let me first shut down everything and then start it looks like it's still started of course the reason it started is because this is called worthless fpm we should instead be called WordPress and we will go here and also update this to WordPress and that river reached her shutdown everything we start yep so now I only got a database container and nginx container and an FBM container which is brilliant and localhost now if I go to port 8000 1 it should try to redirect me back to 8,000 and then give me an error because nothing exists on a thousand makes it so it doesn't 1 redirects back to 8,000 and then fails and the easiest way to fix that is change this port doing that and please start everything again okay maybe I should not have done that down everything gracefully and every starting let's fry again this is not a bug actually this is also another problem in my image so the way these ports work is that if there is a key value pair it just gets replaced but if there is a list in this case this porch is nothing but a list or an array then they get merged so what's happening is the the port 8000 is already being used by the WordPress container I don't know if there is a way to get rid of it if there is I will comment it or create a new video and that might get here later but for now I'm just gonna comment this part so I will not create for 8000 or by WordPress container and instead of create 40,000 for my nginx container let's shut down everything and then we start yeah and this time it worked still not loading them so let's see what's going on we do not see an engine X image at all which means the nginx container filled to start yeah I don't know why I didn't start before but it seems it's just let's just quickly double-check Turia we are going to also quickly check if this page is being served by nginx or not and the way I'm going to do it is I can just make the network requests the headers should let I fitted nginx watching are by PHP server picnics now what's happened the reason we are not seeing styles I really don't know everything seems to be learning fine now so everything seems to be redirecting back but this is a problem janek's config - to the nginx server things that the file doesn't exist and that's why it tries to redirect to PHP or something like that I think the problem here is that yeah this is this is the problem here but my lack of nginx knowledge is going to take some time to solve this you you so if any file that doesn't exist on this nginx machine gets forwarded to PHP and since all of our WordPress files exist on that the FBM container and not nginx container I think that's why it thinks that this file doesn't exist and then hands over the request as a PHP and eventually gets redirected so basically the nginx conflict that we copied is not perfect or we are missing a step here I'm going to quickly check the lawyers yep look at that they are also mounting the same folder the the www layer ID and UNIX and the same directory or the same path is also mounted inside the fpm I think that's the problem that's the thing we were missing so let's go back here but the mounts www exists oh yeah it did not get that because it needs to be here so we have this mount but this is only being carried forward to the WordPress machine and not to the nginx so that's one thing we needed to do here and once we have done that they can't restart everything yeah go back into nginx mission yep so let's see works fine now perfect said that is it each other and now we are going to map everything back to or a gay kid that was only one change and restart everything this is not working because WordPress is originally installed on port 8000 and not on port 80 I can use WPC ally to go back and change that that could be something for another video for now I'm just going to use continue using 4,000 yeah and that's pretty much it for this video if you liked the video make sure to press the like button and subscribe to this channel for more such tutorials there's a lot more interesting stuff going to comes here see you in the next video then have a great one
Info
Channel: WP Gains
Views: 9,956
Rating: undefined out of 5
Keywords:
Id: Dgj7SEtUzjM
Channel Id: undefined
Length: 21min 41sec (1301 seconds)
Published: Wed May 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.