Hosting a Website on Google Cloud Platform | Free Hosting

Tech Boss
138 followers
15 Video Views·Oct 18, 2022
Are you sick of paying for web hosting? How would you like to pay less than one dollar for an entire
year and have it hosted in a data center where you don't have to have extra hardware or anything else?
Sound too good to be true? Well it's not. I've done it for the past five years and literally have
spent less than five dollars in that time. Pretty incredible and I'm going to show you how to do it.
So first couple things here. One you have to have a google account which you're on youtube so you
have that. Go to the google cloud platform, sign up, create a project and we can get going. Other
prerequisites is the google gcloud needs to be installed on your machine. I highly recommend
using this. The web-based ssh is okay but it gets real finicky and a little buggy so I always
recommend installing gcloud. Other things to note the charge that you actually incur on this
is from the static ip that you rent out from google and that ip I've seen charges as little
as one penny on my credit card which I think it costs them more money to charge the card at that
point and then as expensive as seven cents. So that is how cheap it is. As far as the micro survey
we will be configuring in this video that is actually free as long as you have a credit card
on file with google cloud platform. Now I was totally paranoid when I first started this it
sounded too good to be true and five years ago it was I thought but after doing it for such an
extended period of time I thought why not go ahead and show it to you because it is extremely powerful
and I'm sick of seeing all these ads for all these web hosting companies and they're literally the
ones that set it up like this they're using the same services it's probably sitting in the same
data center right now the only difference is you're paying twenty dollars a month and they're
paying pennies probably even less than pennies because they had the big servers and throw
hundreds of websites on one server so they're paying even less than what you're about to pay
with that said let's get into the video this is a long video check the time stance if there's
specific things you're going to have to come back to there's going to be questions hit me up in the
comments hopefully the community can answer those or I'll try to answer them if it's within the
first day or two I will and with that said let's make it happen and get into it all right let's
start by creating our vm in google cloud platform if you haven't already make sure one you have a
google account you've signed in and signed up for google cloud platform I highly recommend adding a
credit card so you can get the free tier and it will you know have a couple penny charge that
I've already gone over and then also make sure you install the gcloud package the link is in
description below if you're unfamiliar of gcloud but it is a simple apt-get or if you are on arch
it is in the aur so let's go ahead and pull up gcloud you can simply type console.cloud.google.com
and it'll pull up this page from here make sure you go to the compute engine and once here you'll
have this screen we're going to create our first vm in our google cloud instance you can choose
whichever one you want I'm actually going to change this just for simplicity sake and go with
an LTS version of Ubuntu at 20 gigs I believe the micro instance up here right there is what we
want as far as the region goes I'm central so I like to do central one and then that is pretty
much set up on firewall make sure you allow HTTP and HTTPS so you get your web traffic through to
this machine so with that we're creating a 20 gig a micro instance and this is going to be our
and just make sure everything is lowercase all right we'll hit create and this will take a little
bit I'm going to go ahead and speed this up usually this creation process takes about one
to two minutes so not very long at all just know it's not an instantaneous thing okay so for this
one what we need to do now is run our gcloud command to connect to this instance that is now
created it is very simple to install gcloud again I left the link in the description below
it's just a simple apt-get or an aur install so we'll view our command and just simply copy this
and we just paste that into terminal so let's go ahead and do just that enter passphrase
I'm going to probably just completely wipe this out afterwards so I don't really care
about the passphrase because I'm not going to be blurring out like external IPs or any of that
business so nobody needs to get any ideas about it I'm just going to delete this entire project
after I am finished with this video all right so we're installed this is the first boot up of this
actual instance so the very first things we always do is just a simple AP update and a
pseudo apt upgrade now the beauty of google cloud is they're constantly updating their images
because people are constantly launching these things so when it updates stuff it's usually
like one or two packages and then it's done so it's not like a fresh install on your home pc
people system admins all over the world are constantly sitting here pegging the system so
they're always updating these so the update and upgrade as you see here is pretty much done after
just a couple seconds to a minute on this little bitty micro machine all right so with that done
we've done our update everything's set to go let's get into step two installing the swap file and
optimizing performance because this is what we're working with with a micro instance not much we got
about 582 megs of ram one shared cpu and no swap file by default now obviously we're going to be
using 582 megs of memory in this sucker so having a swap file can be very vital to its performance
so that's the very first thing i'm going to set up going into step two so to do the swap file
we just need to do first an f allocate and i'm just going to do one gig that should be plenty
for this system there's no reason to make a giant swap file thinking you'll get more memory
swap files don't work that way this just helps with the low memory usage so with the f allocate
done we need to do a dd and wipe this file out that's good the dd usually takes about a minute
to do i'll go ahead and speed up for this part all right that is finished so from there we just need
to make this readable only by the root just as a security precaution so we'll do a chmod 600
swap file from here um now the swap file is all prepped we can actually make the swap so
sudo make swap swap file yay it is done so with that we can actually turn it on swap on swap
file with the swap on and swap file it is now utilizing the swap file the last thing is on
reboot we need to make sure we edit our f stab to show this change so we just simply add that in
there so it's going to be a swap partition uh swap is the actual type of partition it is and
then just defaults and zero zero is all we need for this and after doing any modification f stab
always do a sudo mount dash a just to make sure you didn't have any misspellings in there so swap
files done step two is done uh let's verify with an h top and you see the gig of space in our swap
so uh first level is done now it is time to install the lamp stack which stands for linux
apache mysql and php this is the bread and butter of any system admin that does any kind of websites
they can know a lot about doing lamp stacks and this is the easiest way i've found to do it
seamlessly and pretty darn quick so let's go ahead and jump right into it um first we're
going to do a pseudo apt install task sel i use this basically to jump over having to constantly
cut and paste whole bunches of packages into apt so now with this installed we can just do a pseudo
task sel and we just do install lamp server this will go ahead and install all our packages the
ones i just named now there's a couple more that we need to do just because this is a wordpress
instance and i'm going to go over that after this finishes installing again this install will take
about 30 seconds to a minute usually so all this goes pretty darn quick all right the lamp stack
is installed and now let's go ahead and add the extra stuff from apt again the copy paste will be
done i'll leave a link in the description below with the entire article with all this stuff in
here so you can easily copy and paste this just like i'm doing right here from my cheat sheet
that'll be on my website christitus.com so with that let's go ahead and install the rest of our
dependencies and we'll pretty much be ready to configure this thing all right we're done all
the prerequisites have been met all the requirements are ready we can go ahead and jump into the
configuration and get going so from this point you would actually go ahead and get the static ip
for this machine so we'll just do a curl and just grab this this is the easiest way to do it is just
curl ifconfig.me and this would grab our external ip which is this guy again i'm going to wipe this
ip out afterwards so don't bother going after this instance because it will be wiped out so copy that
and then you would go into your dns registrar and let's say you have your domain mine's christitus.com
you would create an a record for that domain and point it to this ip that means any traffic going
to christitus.com would go to this cloud google cloud instance and it would be you know hopefully
pull up the website after we're all done so that is the basis of actually getting it going now
obviously i don't have a sample website and i don't want to waste all the time doing a dns update
and then waiting hours for it to finally update so we're going to cheat in this section just ignore
the next couple things i do just because i'm going to be modifying my host system here and then also
the google cloud system or instance so it thinks that hey this website is real and we can pull it
up and configure it so to do this i'm going to completely take dns out of the equation and then
do direct modifications to my host file if you don't know anything what i just said just know
you don't need to do this as long as you add that a record into your dns server and then you need to
we'll make a fake domain under the name square gator is for noobs.com you see what i did there
yeah all right and then we also need to do it on this machine too so let's go back to my home
machine that's what i just did with my multiplexer and we will do the same thing square gator is for
noobs.com yeah we'll exit this all right we're back on our google cloud dns has been set up
we're ready to rock and roll so the next thing we need to do is actually set up our domain name
in our apache configuration file so to do this we go to etc apache to and sites available
so we have the default site and we need to actually copy this guy to our i like to name
it the exact same as the domain name it's just a best practice especially when you have multiple
websites hosted on one server for you it probably doesn't matter you could honestly just edit the
zero zero default and not have to worry about any of this but i do like to actually configure this
so let's go ahead square gator is for noobs.com.conf notice i added the .conf onto it and
it helps if you do it as super user and honestly on this we're gonna go ahead and switch into root
just because i'm you're really done user abilities on servers and stuff a lot of people are knocking
me in some past videos just because a lot of times i would run as root just so i could configure the
server exit and then i'd probably never touch that server for like another year so i didn't
really care about running root it's just i've gotten into practice doing a lot of desktop linux
work now i'm doing sudo all the time just because it's ingrained in me but running sudo is probably
a good habit but for today we're gonna go ahead and run as root we're gonna live on the edge so
let's go ahead and edit this config file first thing we set up is our server name and square
gator is for nibs and let's go ahead and make an alias as well just in case we have a www all right
and then we also need to set up a directory path i'm going to leave everything under html
also if you're doing multiple websites you probably don't want to do that you probably
should choose another directory so that said just know that require all granted all right
we're set up so this is it for this config we'll exit out now i like to go ahead and disable the
default so let's go a2 a2 dis site and again we're running as root so we don't have to do sudo
all right the default site is disabled let's go ahead and a2 insight it's kind of funny i never
actually said that out loud it's insightful all right square gator so after this our site is all
set up so if we just do a system control reload apache 2 all right our apache 2 is all set up
and we will go ahead and test this pull up our website here let's type in square gator is for
noobs.com oh apache is installed and it works fantastic so we can continue with our configuration
next up we're going to prep the database and php um easiest way to do this a lot of people like to
use php at my admin honestly i don't recommend you do that unless you're constantly in the
database doing this and that a lot of times i like to just do it once from terminal and then
you don't ever have to mess with it again so you know to each his own today i'm just going to show
you the terminal way because i find it easier dash u for user root and let's go ahead and create
our database semicolon after every command in the mysql prompt and then we just need to grant
all privileges and create our user grant all wordpress dot star we need all the tables
to uh let's call this wordpress user real inventive identified by secure
one two three four the most secure password in the world and enter oh forgot the semicolon
all right well that was embarrassing uh make sure you spell identified by correctly
identified yay ah english wasn't my strong subject in school by the way
mathless all right so with that done we can go ahead and quit out of our mysql prompt after
misspelling identified so many times and from here let's go ahead and secure our installation
actually you know what i'll choose yes because you should always be using a strong password
you can choose low medium or strong uh let's go ahead and just choose low but i highly recommend
you choose at least medium all right new password for root all right do you wish to continue with
password provided yes remove anonymous users yes disallow root login remotely yes remove test
database yes reload privilege tables yes all done all right so mysql secured we created our thing
make sure you remember the passwords you used up in this section right here uh we need to know that
the database names wordpress our users wordpress user and then our password secure one two three
four exclamation mark and a capital s ah super secure all right one last thing before we're
ready to go and download our wordpress a couple php modifications i usually always make let's go
ahead and flip over to our php directory and see what we got we go to etc php the version
in apache 2 and we're gonna nano into php.ini from here uh i'd like to just do a search
first thing i change is the max input time this is set at 60 i believe um let's go ahead
max input time again yeah i like to set this down to 30 and right below it usually
is let's see if i can catch it it's the upload is what we need it's not right below it so we'll
just do upload we're changing the max upload that we need so file upload size this is always set at
two megs which is extremely low especially if you're migrating wordpress it's going to be well
over two megs so i at least set it to 20 megs in some instances i've even upped it to 100 megs
on really big really big websites but 20 megs should get you by the last thing is the post
max size i like to set this just a hair above the upload max size so let's find the post max size
we'll do a control w post max size and that's set at eight megs let's go ahead and set that at 21
so with that we should be able to import things do things a little easier in php so i do like to
make those little modifications there's other hardening and security measures you can take
which i do recommend uh just make sure that you follow the steps these things i think are pretty
essential to pretty much any wordpress install all right i think we're ready guys to install
our wordpress so let's go over to our directory and see what we got we have our index file showing
that beautiful apache test page from earlier let's go ahead we'll just move that index
to a lower directory ah all right so this directory is nice and clean below the w get
our latest wordpress so we're gonna go on to wordpress.org forward slash latest dot tar dot gz
and from here we'll just do a tar x ah xbf latest all right this puts it into wordpress directory
which you know we want it in our root directory so let's go ahead move all files to the lower
directory so if we look this is gone and all our files are now in this directory so we can go ahead
and remove that wordpress folder and that latest tar zip and now we need to make the actual
configuration let's go ahead and i'm going to change the sample file and we'll use that to
we'll just make it wpconfig.php and remember if you're working on a live server
i highly recommend you hurry up in this section or make a sample file change it first and then
push it to the wpconfig and load it right up because your system's completely wide open
when it's like this so very important to know once you've actually configured this
you need to jump right in and configure the next part once wordpress is configured so let's do our
config file and now earlier we set up all those things make sure you go back and verify that this
is the right thing so we're going to do wordpress and then for the database user this is going to be
wordpress user i was really inventive with the password and usernames here secure1234
exclamation post name all the rest of this you can pretty much leave default last thing is the
salts always fill this in do not just leave the defaults so just take this copy it all right so
then we get our salts let's just ctrl a ctrl c that and pop back into our file paste this in
output done so from here we're pretty much done with the wordpress configuration everything's set
we should have a website at our wonderful website for hosting that you know everyone's going to
want to use so let's see square gator is for noobs.com let's see if we did it right hot dog
let's say site title visit me on patreon you see what i did there yeah and then your user let's
call this one chris titus password that let's just copy that guy make sure you copy your password
and save it somewhere special contact at chris titus.com and install wordpress
installs actually goes pretty darn quick you should have that set up you can just go chris
titus and then our password remember me welcome to wordpress now from here you can just take it
and go you now have your very own wordpress install from a hosted solution that you're
paying literally pennies for and those pennies are literally only the static ip that you're
paying for so for an entire year your hosting cost will be less than one dollar pretty awesome stuff
extremely powerful now again this is only for people with you know lower end visitors i currently
get about a thousand unique visitors a day on my site so a micro instance is not what i use i'm
the level up from this and once it starts getting kind of hit and maxed out and seeing sluggish
performance i'll probably up it to more of like a 20 plan at that point but if i get to that point
we're talking like a hundred thousand visitors and that's going to be drawing some serious cheese at
that point it'll be 100x growth from where i'm at right now so that 20 a month is not going to
matter to me one one bit pretty awesome stuff this is the stock settings everything's set up
like this out of the box now you install your themes and go to town from here now there's one
last thing i wanted to show you before we go away there's tuning that needs to happen on this and
the tuning is critical to get proper performance because by default micro instances are way
over tuned meaning they allow way more traffic than they should you need to be throttling this
using what's called the npm pro yeah pre-fork and that is actually up here in the title it was one
of my very first videos when my channel name was the technology vault i don't know i don't know
so the video quality is not the best however uh the content is still very good it shows you
what npm pre-fork tuning does how to modify it to each specific system that it's on
and how to properly do this now i'm going to go ahead and do it for a micro instance so if you
want to copy these settings you totally can just know that that's what i'm doing that's how i come
by these numbers and it's just good and i might even throw in a little script here just so you
guys can see what a tuning looks like this script's going to be completely off basis because this
needs to run and see traffic for probably at least a couple days before the script actually
gives you a good baseline before doing the tuning but let's do uh the traditional tuning i like to
do for the micro instances so let's go ahead and nano back into our apache mods enabled and npm
pre-fork.conf is what we need so what this is is right now it's tuned for basically a full system
which this is definitely not start servers one min spare servers two maximum spare servers two
request workers is going to be 10 maximum connections per tile you can leave this at zero
i like to amp it up to about a you know probably a thousand anything over that you know it's
awfully it's a runaway connection and it's probably best to shut down it doesn't really
matter you could leave this at zero but i like to at least configure it a little bit from here
i'll go ahead and write this out let's see actually max spare servers i'm going to change this to five
i did that wrong so start servers one minimum spare servers two max spare servers i put it
five and then max request workers is 10 so just kind of have that in the back of your mind what
you should have and what you should not so let's exit out of here with this and i'm going to show
you a script that i like to do it's by richard forth this genius on github created this script
and it is just fantastic so let's go ahead and not put the pearl script in the root of our
of our website let's go back to our home directory and do it there let's make it
writable and from here we can just go ahead and run apache 2 buddy and what this does is it kind
of goes through checks out sees any problems with it and then reports back what your settings are
and says hey your settings are junk or not and there you go so right now it says hey max request
workers is far too low we recommend between 15 and 17 well this is a brand new instance it has
extremely low uptime so there's no real good basis of this yet i i have a hunch if i left
this going and configured this site and added plugins and things like that memory usage would
go far up and that 15 and 17 would probably go down to 10 or maybe even a little less i might
even need to edge this down i need to revisit this in a day or two if i kept this site up and going
so that was it guys pretty incredible stuff when it comes to getting this working uh i didn't
figure this is hard and if you're already a linux user you're going oh my god titus this is way
easier than i ever anticipated that's pretty powerful and it is and i've used it for years
and years and it has served me incredibly well i can't speak highly in the five years i've been
on google cloud platform hosting a website it has gone down this many times zero times
that's how many i don't have any crazy disaster recovery plans or anything with them i'm just
using most of the free stuff now i have stepped up since my website has seen more traffic in the
recent months that i've had to step up from a micro server to the next best thing i think i'm
actually to a dedicated cpu because i do monitoring and some other stuff using nagios but
the end story of this is is so much cheaper just to do it this way and you get just as good as
performance reliability and security than you would if you go through these other companies
and i'd even venture to say you'd have probably a better security and uptime than many of these
really cheap web hosting companies that are like five or ten bucks a month so with that said guys
let me know what you think in the comments visit me on patreon and i'll see you in the next video
