Tutorial: Setup Load Balanced WordPress website with Lightsail Object Storage

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome back to another web hosting video tutorial in this video i will walk you through the setup of a load balanced wordpress website on the light cell platform now i have done this tutorial in a previous video one of my early first few videos i've done a walkthrough of setting up a load balance wordpress website in light cell and in this video we'll do the same steps however in this tutorial i am going to use the new object storage that's available in the lightsail platform which makes it very easy to connect an s3 bucket to your light cell wordpress based instance here's a diagram that we will have finished set up after i'm done with this tutorial however you see this distribution cdn section that will be done in a different tutorial so subscribe if you want to see or if you want to get notified when i publish that video so without further ado let's get started [Music] all right um to get started i will start creating my first wordpress instance so from the light cell dashboard i'll click click on create instance choose your instance location for the platform pick linux unix and then for the blueprint uh click on apps plus os and then pick the wordpress blueprint then choose your instance plan i'm going to go ahead and go for the 10 plan and then give your instance a name i'll just keep this as the default and click on create instance all right so while this instance is coming up if you are migrating an existing website that is already on uh the wordpr or the like cell platform then all you need to do you probably need to skip this step you don't need to create another instance you can go to the next step that i'll show you which is to create the database service and set up the object storage if you have an existing wordpress website and that is not on the light cell platform then you'll want to follow the steps and migrate your website over to this instance first and then follow on the steps to you know create the load balance setup so those are two things that i won't show you here i'm just going to show you how to create a brand new instance whether for a brand new website once this instance is up and running i am going to set up a sample wordpress website using a theme and some dummy content for this tutorial alright here is the wordpress instance go into the instance dashboard i'll click on networking and i'm going to create a static ip address and have it attached to this instance the next thing that we're going to do is add a sample theme and some dummy content to this wordpress instance so let's come back out here here's your ip address copy the ip address go to your browser and okay the website is up so the instance must have completed its provisioning steps now the next step we will do is go into the wp admin and set up the dummy theme and content so the username and password will be the username is user and the password i need to get so i will click on the web-based ssh terminal and cat bitnami application password copy this password to my login screen we are logged in so under themes i am going to add a new theme install this new theme and activate it and then we will try one of these starter sites i need some of this so install and activate so we'll just pick this thing import so just for this tutorial i have included or installed a theme imported some dummy content so that we can have a site besides the default wordpress theme and no content so here's the content so the next thing we will do is set up an external database service so as part of the load balance setup as we saw in the diagram we need to move the database from this wordpress instance to an external database service and light cell provides one so if you click on from the dashboard databases we'll create a database and we'll move the mysql tables and database that were part of the wordpress instance over to this once it's provisioned so on the create a database page click select your database region you do need to keep in mind that this region and availability zone i believe should be the same as your wordpress instances so just make sure those are the same leave my sql selected and the latest version you have the option of specifying login credentials and if you don't put anything in here the default is db master user the password will be created for you and then you can specify the database name if you don't provide one then the master database name is db master choose your database plan and then give your database name and create days so now this will take a few minutes for the database to get provisioned and available and so once it's done the next things we will do is export the mysql database from the wordpress instance and then import that database into this database service that we just created that way the database is now on its own separate infrastructure and we eventually create two different or two or more wordpress instances those wordpress instances will connect to this single comment database okay the database service is up and running so the next thing we need to do is export create an export file from our wordpress instance and then import that into this database now the reason we needed to make sure that the database and your instances are in the same zone and region is because this database and the instances need to be able to connect to each other and they can only do that if they're in the same region as you'll see right here only your light cell resources in the same region as your database can connect to it so for this reason we want to make sure that the zone and region are the same as your instances to export the wordpress database from your instance we will go into the ssh terminal you can use the web-based one but for this tutorial i am going to use a client ssh client software i am going to use bitvise ssh client for windows and if you're on a mac you can use a putty or if you're on linux you can use putty and putty also is available for windows as well i just prefer bit buys for my needs and here we go so inside the terminal the command to create and export database in mysql is called the mysql dump command so you will start by typing in sudo my sql done dash u for user root dash p for a password and we'll provide the password once we hit enter and then you'll provide the database name for bitnami based wordpress instances the database is bitnami underscore wordpress and then we'll send it to a file so you put the greater than sign and type in a file name so we'll say database dot sql so now once i hit enter it will prompt me for the password the password is the same one that we used to log into the wordpress admin hit enter it will ask me for the password right click and then clipboard contents get pasted hit enter and if you did not receive any errors and if it was successful you should be brought back to the command prompt now if you do ls you'll see that there's a file called database.sql so this has the entire wordpress database for the site that we just created now with this database we will import that into the database service that we just created so for that we'll run the command from the same ssh terminal we'll do sudo mysql dash h for connecting to a remote host if you were connecting to a database on the same server you don't need to provide the dash h parameter but since we're going to connect to a remote external database service you have to do dash h and then the host name so we'll come back to the light cell dashboard come over to databases click on your database service and your endpoint here is the host so we'll copy that right click to paste it then we'll provide dash u parameter for user and since i did not modify the user name when the database service was created it will be db master user which is the default dash p for password and then the database name and again i did not modify it so the default is db master and in this case we'll do a less than sign and then the name of the file that we used to create the export which was database dot sql now this will prompt me again for the password so i want to before i hit enter i'll come back here and i'll say show password and i will copy this into my clipboard so i have it available click on my ssh window hit enter will ask me for the password right click so the clipboard is pasted and then hit enter and again if no errors are returned and you're brought back to the command prompt or terminal prompt that means the database import was successful if you do run into errors then the best thing i can recommend is find the air and search on google and see if there are any answers to the errors that you're getting so now we have our database on an external database service the next thing we'll do is set up the optic storage that's part of the new offering in the lightsaber platform and we'll go back to our dashboard click on home click on storage and then click on bucket or create bucket now this is primarily going to be used for all of your media files so any images or any media items that you upload into wordpress you want those to also be stored on a shared location so that your multi-instant setup will always refer to the same uh s3 bucket to pull that media item and render it so we'll create a bucket again make sure it's in the same uh region well actually in this case it might not be needed uh it's not required to be in the same region but just for simplicity or consistency's sake just make sure you're in the virginia region pick your storage plan based on the amount of storage that you need for your website and then you can give your bucket a name or you can just leave it the same and and that will set up a domain name for your bucket and then hit create bucket now your s3 bucket is provisioned you can click here for permissions and then we will change the permissions and we will pick the last option here or actually individual objects can be made public and read-only so this is what we want we want the objects to be public because it's on a public website but we also want this storage to be read only and so that external public users cannot store objects or create objects in your s3 bucket so we'll hit save or actually let's see what else we need to do attach an instance so we'll hit save hit yes save and then we need to attach an instance so you click on attach instance from the drop down you will pick your the instance that we have hit attach and you can come back here and attach more instances so you'll see that when we create the second instance or if you create more than one instance you'll be able to attach additional instances here so we'll do that and i think that's it uh we're here now let's go back into our wordpress website go back into the wp admin and we will add a plugin and you just search for s3 and the plugin that we need is wp offload media lite install that click on activate and then we'll go and set up the plugin so click on settings and offload media lite then we'll click on the my server is on amazon web services and i'd like to use iam roles click on next and then we'll have the providers amazon s3 and then browse existing buckets and you should have your newly created bucket listed here click on that and then save selected bucket and here is your url preview and in these settings the only thing that i think we may want to turn on is actually we do want to turn on force https and we'll also want to turn on uh remove files from the server and this is maybe an optional item for you uh what makes sense for you you can do that but this is an option where once the once all of this is configured and you upload media items to your wordpress website and this plug-in will copy it over to the s3 you can select this to have it removed from the local instance as well if you if that's something that you want to do so i'll turn that on and hit save changes okay i think we have everything configured so the next thing we'll do let's just go ahead and test and upload and see if that works so these are all existing images that were part of my dummy content that was installed when i set up the theme and content so these are not on the s3 media object bucket storage that we just created these are still on the local server as i mentioned the plugin that we have does not transfer existing items only new items after the plugin was configured so you will have to if you have an existing website and you have lots of media items you'll have to do that manually you have to move those manually to your um your s3 bucket but if you upload a brand new item so we'll hit media library add new select files and this is good and you'll see that the media item uh was just uploaded now if i click on this and you see the path the file url you'll see that it's now pointing to a the bucket that we just configured so that means that this file should be now on your object storage and not on the local server so we can also verify that by going to light cell going to your bucket section click on objects and now you'll see that there is a wp content folder you click on that your uploads folder 2021 11 and here is the image and the various versions that were rendered out so that's uh that's an indication that our plugin is set up correctly and our configuration for this object storage is working now what i did mention is that if you have existing images that's part of an uh your website you can upload them here or you can use a s3 client that can connect to s3 and you can do it that way as well but somehow you'll need to get your existing website images up uploaded to the s3 bucket okay so the next thing that we need to do is modify the wp config file and we'll change the database connection string to now use the database service that we just created earlier so back into our ssh terminal window find the wp config so for this it will be under stack slash wordpress back press oh i had a spelling error earlier and then there's the wp config so i will use the vi editor wp-config.php open that up for editing and then what we want to do is modify this right here we're going to modify the database name the user the password as well as the location so instead of the local host or the local database we're now going to have it connect to the uh database service that we created so let's go back here so we can get the necessary information so let's start with this copy and back to the ssh terminal i for insert and then hit the delete key to remove localhost leave the colon 3306 there because that's the port that my sql runs on and listens to and here we'll do shift insert and that should insert the [Music] endpoint that we just copied where my cursor was so that's there hit escape let's do the same thing for password i for insert and hit the delete key to remove the existing password let's hit show password copy the password to my terminal shift insert there we go same thing for the database user we'll hit delete to remove it i'm already in the insert mode so i didn't hit i again the database user was right here i don't need to copy but db master user db master user and then the database name is dbmaster okay so once we have these changes done hit escape and then we'll hit the colon key w key and q key for write and then quit so that quits the vi editor and writes the file saves the file so now that we have our database connection strings done let's go ahead and test out the site and make sure it's still working so come back to our wordpress website let's visit the site and it is still working that means that we are now using the s3 object storage for media assets and our database service is being used for the wordpress database so now the next step at this point before we get to the next step at this point you have your instance configured the way it should be for a load balance setup so you have the wordpress instance you have the external database service and you've configured the object storage for your media items so everything is in place the next thing we need to do is duplicate this instance make a snapshot and create another instance from this snapshot so that's what we will do next let's go to instances click on wordpress click on snapshots and then create a snapshot before i do that i am going to log out of the ssh terminal i notice in the past that have having it connected just takes a little bit longer for the snapshot to be created so exit out of any ssh connections and then create snapshot and this usually takes anywhere from between five to ten minutes and once it's available we'll be able to create another copy of this website on another instance so i'll come back once this is ready okay my snapshot creation is complete so from here you can click on this menu icon and you can create new instances copy to another region or export to an amazon ec2 if you wish but we will create create new instance so we're making a copy of the website pick your instance location again probably leave it the same as your original instance pick the instance plan identify your instance with a name i'll just leave it here and then click create instance and you can create as many instances as you want based on your needs for your load balanced environment so we'll give this a few minutes and that should be up and running and since we created a snapshot from this first instance that we already configured with the database service and object storage we don't need to do that again for the second instance that's why we did all of that up front before making uh instances from that copy okay so the second instance is up and running so what we will do next is create a static ip address do that create static ip address and attach it to the instance here's our second ip address so now the next step will be to set up the load balancer so that we can balance traffic between these two instances so click on the networking tab in the light cell dashboard create load balancer and then again make sure i would just make sure keep this in the same region as all of your other services you just created and then go to balancer create there we go and then second step would be to add the instances to the load balancer so here select your first wordpress instance attach it attach another instance so we'll select the second attach that and if you have more than two just keep attaching and this will take again another few minutes to complete this process and then we'll move on to the next step okay so the process of attaching has completed health check is passed now we'll click on inbound traffic and we need to attach an ssl certificate to our load balancer so to do that we'll create create certificate or we'll click on create certificate and we'll type in the domain that you intend to use for your website so i will use www.mduv.site and if you have any alternate domains you can put those in here at this time so those certificates get created well once you're done click on create and this will give us a validation cname record that we need to create at our domain registrar for this domain that i'm using i'm using the light cell dns zones so i'll show you how to do that in light cell but if you have your domain dns managed by a domain provider or domain register or somewhere external then just know that you'll have to create these entries there so what we'll do is copy the cname name part go over to actually what i'm going to do is right click open this link on a new tab so i have the light cell dashboard in two tabs just to make it easier for copy paste go over to networking and then click on my dns zone as i mentioned it's in light cell and i don't have any records so we'll click on add a record we need to add a cname record and we'll paste the value i just copied now i copied the entire string but as you'll see that in light cell the dot mdub dot site is already there so i'll just remove that part from my string of copied copied stream and so just leave it at www and then that maps to a value so we'll come back to this tab and copy the value here and then hit check mark for save and then over here this notice up here it does say it takes up to 72 hours for light cell to verify that we own this domain or to verify this record was created correctly usually i've seen it only takes a few minutes um but just come back here and make sure that this validation has completed if it hasn't completed in 72 hours or so then there's a chance that you might have missed some step here or may have copied this incorrectly or something is not right here usually it only takes a few minutes but like i said one way you can verify that this is correct is going over to a service like dns checker and copying this the name part over to a service like dns checker paste that here remove the ending dot or period from this drop down select cname and then hit search and it should point to the value that we just created or we just set up in our dns record so you'll see that it starts with underscore 1 9 b8 so if we look at the light cell that is underscore 19b8 so we set up our dns cname record correctly so that's one way you can validate or ensure that at least you have it set up correctly now you just have to wait for this to complete sometimes if you hit refresh light cell dashboard isn't refreshed you'll see that oh there we go yeah so um status of my ssl certificate is valid but i have not used it yet so to use it we'll need to come up here and click on select an ssl tls certificate to enable https select the one that we just created and here we go so we have done everything in the load balancer part the last step is to now point www.mdub.site our domain name to this load balancer and if you're using a dns provider other than light cell then you'll copy this dns name and you'll create another c name that points to this as the value but since i'm using light cell i just need to go over to the light cell dns management interface refresh and we just need to create add record leave this the same i'll put www in front for the site that i'm using and just point it to this load balancer that we created that should start propagating as well you can come back here to the dns checker website and type in www.mduv.site with the cname so let's see if that works or actually it's a a record right so you have that points okay so it's starting to resolve and set up so if we come back to our website instead of the ip address i should be able to type in https www.mdb.site and seems like it is resolving so if we click around here see but the images are not showing up so we'll have to see what's that about but so far everything seems to be working now one other thing that we need to do to our load balancer is on this same inbound traffic page come down and enable session persistence so this is good if you have a e-commerce site or some sort of a transactional feature to your website you want inbound traffic or your customers or your visitors to always connect to the same instance as they're browsing the website you don't want them to get load balance from instance 1 to instance 2 or vice versa while they're doing some sort of a transactional activity on your website so always i usually tend to select this and it just makes it uh for a better experience for the end user so select that and i believe that should be that should be it um if we go back to the website i am not sure why some of the images are not showing up i'll have to debug that um if i do an inspect oh okay uh it's because of the mixed content issue and that's why they're not showing up so one one thing that we still would need to do is update the content to now use uh the domain name instead of the ip address so if we go to our wp admin get my password paste it so once we're inside our website then one thing that we need to do is go into our content for example about us and we'll need to update for example this location so this is going to be different based on how the content was created or how your images were pasted in if they're using relative url then all of this should work if they were using absolute urls typically you know you'll see that in css files or if somebody just copied an entire url and pasted in the content then those images would break so you'll have to do something some you know clean up activity uh once you have your domain set up on your load balanced environment uh one thing that i would suggest you look at is i have a video on wp cli usage and if you check that out i do show you command line utility in wordpress that you can use to do a search and replace so you could do a search for all the urls that start with your old domain or your ip address and then replace it with your domain that you're using for the site so you can do those kind of things with the wp cli and i have a video tutorial on that that you should go check out oh actually one more step we have left to do we need to attach the second instance to our object storage so back in the light cell dashboard click on home click on storage and then click on your bucket click on permissions and then here we have only one instance attached so we'll have to attach our second instance as well hit attach and that should work as well so now we have completed the entire setup for a load balance wordpress website one of the things that i haven't found out or haven't found a solution for is how to solve the issue of themes and plugins remember that our object storage is only used for the uploads so your media content they're not used for your themes and plugin files so updating plugins updating themes those still have to be done on all of your instances manually and the way to do that is you may not be able to use the domain name because you don't know which instance you're going to get sent to by the load balancer so what you would have to do is use the static ip address to to log into each instance individually and either add a plugin or update your plugin and likewise do the same thing for themes and uh and any other items that you need to do for each of your wordpress sites so i have not found a way and i don't think that feature is available in the optic storage maybe that is something amazon will add in the future but right now it's not but if you do have any ideas or if you know of a way to do that on both instances without having to log in then please let us know in the comments below and that will help out myself me and others as well the last part of this tutorial was to set up a cdn service using the light cell distribution capability and i will do that in a second video this video is already long enough so my second video uh our second part of this tutorial will be uh the the setup of the light cell distribution service for this setup and if you'd like to get notified when i do publish that do subscribe to the channel and subscribe to the notification icons however that second video is really optional you can just leave everything as is here and your website should function just fine if you do want caching available then you know you'll have to follow my video to create a distribution or you can also put another service like cloudflare in front of your entire setup and cloudflare will also take care of some caching as well so there are two options and you can pick that should you need that for your setup all right so i hope you found this video tutorial useful if you did give it a thumbs up if you have any questions or run into any issues please note them down in the comments below and i'll try my best to answer them if you would like to get notified when i publish the second part of this video which is to connect a cdn or distribution to the setup that we have just done then be sure to subscribe to the channel and subscribe to the notification so that you get notified when i publish it again thank you for watching and until the next video take care [Music]
Info
Channel: Mukesh's TechSpace
Views: 5,000
Rating: undefined out of 5
Keywords: amazon web services, high availability, amazon lightsail, load balancer, amazon lightsail tutorial, aws cloud tutorial, load balancer configuration, aws lightsail wordpress ssl certificate, aws lightsail wordpress domain, amazon web services tutorial, aws lightsail wordpress backup, aws lightsail wordpress migration, aws lightsail setup, amazon lightsail setup, amazon lightsail review, amazon lightsail wordpress
Id: IRj3pkR2mmA
Channel Id: undefined
Length: 39min 41sec (2381 seconds)
Published: Fri Nov 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.