Install a webserver on Linux in 15 minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today let's install a web server on linux and no i'm not talking about a simple install engine x with unencrypted http traffic no no no i'm talking about a fully functional containerized web server with a database server trusted https certificates that are auto renewed and that in 15 minutes let's go hi everybody my name is christian and i always make great tutorials and content for it professionals i also stream every wednesday thursday and sometimes monday on twitch so if you have any questions don't miss that in this video we will set up a web server and setting up a web server can be complicated because a web server contains many different components like you want to have a database server you want to have an intrusion prevention like fail to ban you want to have trusted https certificates and so forth and in this video i will use a simple approach because i've searched for a solution that can be easily deployed in just a few minutes but still has all the necessary components has trusted https certificates and so on and that's why we're using a containerized approach with docker and docker compose so that can be simply installed not if you're not familiar with docker already you should check out my other two videos about docker and docker compose there i will teach you all the fundamentals about containerizing how it works and how you can easily install docker and docker compose on your linux server so don't forget to check out these videos before watching this otherwise it can be a bit tricky because one thing we need to do before starting with the installation of our web server you need to have a linux server running that can be any linux distribution that supports docker you need to have docker and docker compose installed and also have a public domain that will point to the ip address of your web server and your web server needs to be accessible from the public internet on port 443 and port 80. so don't forget to check all these prerequisites before starting the installation so check out my videos if you want to know how to install docker or you simply can just refer to the official docker documentation they are just a few commands you need to execute i've put your link in the description below but you could also use a cloud provider like digitalocean because they have a droplet in their marketplace where you can easily deploy an ubuntu server that already has docker and docker compose pre-installed and that will be just created in a few minutes no this is not a sponsored video by digitalocean in any way but you will find a referral link in the description below if you use that link to sign up you will get 100 free credits for 60 days you know the deal okay so if you have installed your linux server and you have installed docker and docker compose on your server we can start configuring our web server so we will start with creating a configuration file that is called the docker compose file and this is used to configure all our services that are used for the web server stack and i'm using an image from linux servers dot io so i have already used some images in my wire guard tutorials they are some enthusiasts who managed container images for the community and they have some awesome stuff on their homepage and i found an interesting image that is called swag so this contains an ngx image with file to ban it also automatically obtains trusted https certificates and it can also run a database server and it can also act as a reverse proxy which is also pretty amazing but in this video we will mainly focus just on the web server configuration with the database server so if you check out the github homepage you can find an amazing documentation there are many different examples with different approaches and you also have this weird swag dude up here so they just got me when i've seen this this is just amazing and here you can find some interesting examples for docker compose configuration files but we will use a very simple approach with installing a simple web server with a database server and use that to deploy a wordpress homepage so let's start and don't waste any time because the timer started now okay so i have installed a new server droplet on my digital ocean cloud with ubuntu and automatically docker and docker compose installed so first let's check if docker was installed correctly and also docker compose is there so with these two commands you can check if docker and docker compose are running correctly if you see the version numbers everything is fine i also will add a new user because i don't want to do everything with the root user so i will add a new user question i will automatically create a personal home folder with the dash m parameter add a comment so this is an administrative user and i will add this user to the two groups docker and sudo and i will also change the default shell to bin bash so now i will create a new folder in the home christian that is called dot ssh and add the public key to the authorized key fights there by the way if you are not familiar with private and public key authentication or linux servers you should check out my video about this i've put your link in the description below okay so let's check if we can log in with the user now so let's exit here i also forgot to set up a password for this user and let's check if we can now log in with the user question so now i will check if i need to do any updates on this server and do some updates by the way if you don't want to remember all the commands i'm using you can also have a look at the link to my written blog article there you can copy and paste all the commands i'm using in this tutorial so you don't need to write down this or remember this okay so the server is now updated and ready to be installed with a web server so i will create a new folder in the opt folder that is called web server swag and i will also change the owner of this folder to my administrative linux user now i need to check which user and group id my user has and that will be important later so execute the id and copy this user id and the group id so now we can add our docker compose static files and i have prepared two test files that i will show you in this video so let's go to my project folder this is in the research folder web server stack and there you can see there are two files the simple and the complete yaml so we will start with a simple docker compose configuration file and i will open this in visual studio code so we will first start with version number two services and we add a new service with the name swag and that will use the image from linux server i o that is called the swag image and we simply set the container name also to swag now we need to add this parameter here and you can look this up in the official docker documentation so this will allow the docker container to access the network stack on the host operating system then we will need to add some environment variables and the pu id and the p group id should be the user and the group id of your administrative linux user so note that the docker container will set the permissions to this user id so remember i don't have the user id 1000 i have the user in the group id 1001 so i need to change that now we need to add the time zone so i've added this to berlin which is the time zone in germany and then we will need to add the url of our website so the url in my case is do-test-1.thedigitallive.com and i have set this on my dns server to point to the public ip address of my digital ocean web server and i will also add a sub domain so you can add different sub domains in my case i will add the three w's so this is very common and i will use this as my main domain for my website there then we have the validation method so this should be http by default so this is for the let's encrypt https certificates and if you want to use a wildcard certificate you would need to change that a bit so you probably will need to look up the documentation of linux server i o but for one sub-domain or one domain this is totally fine to choose the http then we need to add a volume and the volume need to point to a folder on your host operating system so don't change the last part but the first part you can choose whatever you like to store the configuration on your host operating system then we will need to forward the ports 443 and 80 to the docker container so this is important otherwise the docker container is not able to accept any network connections from the public internet and we will also set the restart to unless stopped so that means whenever you restart your host operating server the docker container will also be started if it was started before if it was stopped it won't start the container automatically so i will now copy this file here to my linux server so i will just use the scp command i've showed you this in my ssh private and public key remote login video also so i will use the simple.yaml file and simply copy this to christian at and then the public ip address of my server or i will just use the dns name that points to the public ip address there the digital and i will place this in the opt web server swag folder and call this docker compose.yaml let's go back to our web server here and see if the file is there so i will cd into this folder here and do an ls command and there you can see here is our docker compose file let's check if everything is working fine and you can see i can also open this on the server here let's quit so let's just try to start this and let's see if this deploys us a simple website let's execute docker compose up and i also will add the dash d parameter to run this in the background so let's hit enter and you can see it didn't pull down the linux server swag image before so that's currently downloading the image and then it will simply start the docker container that will run the web server stack inside so you can also check with the docker compose ps command if this is running correctly and you can see the swag container is now up and running it has two ports forwarded the 443 and port 80. let's see if we can do a test connection to this website so that's absolutely amazing you can also see the docker image has obtained trusted https certificates so you can inspect this so that's perfect and we can now simply just start to configure and deploy our website here so let's go back to our web server i will show you what the linux server image has done so let's execute an ls command and you can see there's a new folder here that's a config folder if we cd into this config folder and execute nls you can see there are many different configuration folders and files and if you want to configure your nginx web server within this docker container you can simply just go to this folder here and see the different configuration files like the site config the enginex.conf and you can have a look at this we can also go back and check the php configuration and check the php local ini yeah you can add the php ini file and overwrite any settings there and if you want to put a website on your server just go to the 3ws folder here execute an ls command and there you can see here is our index.html test file that will just present us this test here but you can just remove this and place a website in here so this is the next thing we want to do because i want to deploy a simple wordpress homepage on this server but before we do that we will need something else because we will need a database here so i will also show you how to edit a database to this server so i have created a new file this is called complete.yaml and i will add an example from the linux server io documentation we will use the image from linux server io set the container name to mariadb and then we will also need to change our user and group id or adjust this according to what user you are using on your web server and then we have the different mysql configuration so we would start with my secret root password then we have the time zone and also the mysql database the user and the password and then we also have the volume so we have the opt web server spec config and i will add a new folder that is called mariadb where i will store my my sql database configuration files and route this to the config folder inside the docker container and i will also add the restart unless stopped image there not it's also recommended to add something at the end of this swag container here so when we're doing this here we also should add a depends on and then the name of our service here that is called mariadb so that means whenever the swag is trying to start it will check first if the other container is running and otherwise it won't stop this container okay so i also needed to change the user and group id here i forgot to do that and now we have created our docker compose file so let's also copy this to the server and we simply just overwrite the old docker compose file first let's stop the container here so we execute docker compose down so this will delete our container and then we simply copy the complete yaml file let's switch back to our web server let's go back to the root folder and inspect the docker compose file and there you can see we have added our mariadb steady configuration here so let's just try to start this container just simply execute up and the dash d parameter so this should also pull the new image for the mariadb from linux server i o and then try to start this container before starting the swag container and we will check with docker compose ps if both containers are running correctly now i want to deploy a wordpress block on this website so to do that we will just simply go to this folder here so the config folder and then the three ws and we will download the wordpress block image and extract this here in this folder you should definitely check out the linux server io documentation there you will find a lot of great examples like how to use this as a reverse proxy and how to host the wordpress site so we'll just use this and i've basically just used this as my example here and now we will need to download the wordpress block and we'll add this to the folder now i will need to change those three commands before i will execute them so i will show you a simple trick to do that just hit ctrl x e and this will automatically start in nano editor and you can just place your commands in here modify them before executing them so first command will download the wordpress latest tarball and then we will extract this in the folder but we will need to change this as this is not the correct folder so i have placed the configuration the opt folder web web server swag config and then the free w folder okay then we can delete this so let's exit this and you can see our commands are now executed so if we do an ls command you can see there is a new wordpress folder but the problem here is that our root folder points to the w folder and we need to change this to the wordpress folder so let's go back to our configuration and go to the enginex configuration now let's go to confs and edit the default file so this is a static configuration file and you can see linux server io has added some great examples how to set up a web server so they have made a redirection from port 80 to part 4 for free they have added http 2 and added some good recommended configuration settings so of course you can customize anything in here so this is just a great example you can easily customize but i'm looking for one specific config and this is the root folder here so we will need to change this here from the config 3w folder to and add the wordpress folder here okay let's write and exit this file and now we will need to restart the docker containers to do that simply just execute docker compose up d and then force recreate okay let's go back to our website and let's see if the wordpress page is loading let's reload this and you can see we now can set up a wordpress block here so if we go through the menu you can adjust the database so if you want to do that we will need to use the same configurations as we use don't use the root password you need to use this password here and then you need to change the database host because this is not the localhost in this case because we are running this in a different container so the swag container needs to connect to the mariadb service and we simply can't just use the name as the host name because docker takes care of those redirections and network host names so let's submit this and we can simply just run the installation so this is just a simple example how you could set up a simple website or you can do whatever you like with it and you should have your web server now up and running so i hope this didn't take too long than expected but i don't want to rush through these tutorials without any detailed explanation because otherwise i think it doesn't help anybody so you should really understand the underlying concept and note we have just scratched the surface you can use these docker images and these custom configuration files to do whatever you want you can add some customizations to these steady configuration files in the config folder you can do some adjustments you could also use this in a reverse proxy setup so i hope you enjoyed this video and this was helpful to you please don't forget to hit the like button and leave me a comment if you are interested in more videos and tutorials about this stuff and if you are interested in content for it professionals in general then don't forget to subscribe to my channel a quick reminder i always stream every wednesday thursday and sometimes monday so if you have any questions and you can also come to my discord community if you want to get in touch with people who share the same interests like you so before i go i want to thank all my supporters on patreon especially mason who is a producer of this show so without you the community this whole project wouldn't be possible at all so thanks everybody for watching enjoy the rest of your day take care of yourself and i see you soon [Music] you
Info
Channel: The Digital Life
Views: 16,879
Rating: 4.8669834 out of 5
Keywords: linux, python, cloud, networking, webserver, nginx, linuxserver, docker, docker-compose, web server, linux server, linux web server, linux tutorial, web server vs application server, web server tutorial, nginx docker, mariadb docker, nginx mariadb, nginx mysql, mysql docker, nginx tutorial, ubuntu server, lamp stack, linux tutorial for beginners, how to
Id: 7GTYB8RVYBc
Channel Id: undefined
Length: 19min 44sec (1184 seconds)
Published: Sun Oct 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.