Welcome back.
This is part two of this lesson.
We're going to continue immediately
from the end of part one,
so let's get started.
Now that we've created all of those,
we need to go ahead and install
WordPress on our EC2 instance.
So move back to Instances.
By now the instance should be in the running state.
Right-click,
select Connect.
Change it to Session Manager,
and then go ahead and click on Connect.
And this will allow us to connect into the EC2 instance
without worrying about direct network access
or having an SSH key pair.
Once you're connected, go ahead and type,
sudo bash, and press Enter.
Then type, cd, and press Enter.
And then type, clear, and press Enter.
And that will just clear the screen
to make everything easy to see.
Now at this point, there are a lot of commands
that you'll need to type in to manually install WordPress.
Now you can copy and paste these
out of the text instructions
for this stage of the demo lesson
but while you're doing so, I want you to imagine
that you'd have to type these in one by one
because I want you to get an appreciation
for just how long this install would take
if you were doing it entirely manually.
So first, we need to set some environment variables
on this instance with the parameters
that we've just stored in Parameter Store.
So go ahead and copy all of this set of commands
out of this stage's instructions,
and this will set environment variables
on this instance with values from the Parameter Store.
And again, imagine how long this would take
if you had to type all of this manually.
Once we've got those variables configured,
next, we need to just update
the operating system on the instance,
make sure it's running with all the patches
and just update the package repositories.
And we can do that with these two commands.
The next set of commands in this stage's instructions
install prerequisites.
So this is the MariaDB database server,
the Apache web server that you'll get,
some libraries,
and a stress test utility.
So go ahead and paste in the next block of commands
to install all of these packages.
Make sure that you do press Enter on the last command
if it doesn't execute automatically
because we need to make sure
that all of these are installed.
Now, again, this is something that we will automate
later in this demo series
but I want you to have an appreciation
for just how long this takes.
And then if it doesn't automatically
press Enter on the last line,
just go ahead and press Enter to install that final utility.
I'll type, clear, again to clear the screen.
And then the next set of commands
will start up the web server and the database server
and ensure that both of them start up automatically
when the instance's operating system is first started.
So if we restart this instance,
both of these services will start up automatically.
Again, make sure you press Enter on the last command
to make sure that starts up successfully.
So that's the Apache web server
and MariaDB that are both started
and set to automatically start on operating system boot.
Again, I'll clear the screen.
And the next command that you'll run
sets the root password for the MariaDB database server.
So this is MySQL admin,
and you're setting the password for the root user,
and we're using the environment variable
that we created earlier
with values taken from the Parameter Store.
So that sets the root password
for the local database instance.
Next, we're going to download and install WordPress
and we do that with the next block of commands.
So this first downloads the WordPress package.
It moves into the web route directory.
It expands that package
and then clears up after itself.
So now we have WordPress installed.
Again, I'll clear the screen to make it easier to see.
This next set of commands
replaces some placeholders in the wp-config.php file
which is the configuration for WordPress.
And it replaces the placeholders with values
taken earlier from the Parameter Store.
So this is how we're configuring WordPress
to be able to connect to the local MariaDB database server.
The next block of commands that we use
will fix up the permissions
of all of this directory structure
so we don't have any problems accessing these files
or any of the security issues.
Again, make sure you press Enter on the last command.
And then we're almost done.
The last step is to actually create the WordPress database,
create the WordPress database user,
set the password,
and then grant permission on that database to that user.
So these are all steps that we need to do
because we're using a self-managed
MariaDB database instance.
So paste in this next block of commands and press Enter.
So this has created a db.setup file
with a number of SQL commands.
And then it's used the MySQL utility to run those commands
which have created the database,
the database user, and set permissions.
And then it's cleared up the temporary file
after all of that's been done.
And at this point, that's all of the configuration needed.
We've installed WordPress,
we've installed MariaDB.
We've started them both up.
We've corrected permissions
and adjusted the configuration files.
Now you've had the ability to copy and paste these commands
from the lesson instructions.
But imagine if you had to type them in all one by one.
It would take much longer
and is also something that's prone to many errors.
That's something important to keep in mind
as we move through this advance demo.
So the next step is to move back to the EC2 console,
make sure you've got the WordPress-Manual instance selected,
and then copy down the IP version
for public IP address into your clipboard
and make sure that you do copy the public IP address
and don't click on the open address link
because that uses HTTPS, which we're not using.
So go ahead and open that in a new browser tab.
Now this is going to take you
to the setup screen for WordPress.
We're going to perform a quick setup.
So under site title,
I want you to enter, Cartogram.
Under username,
I want you to enter admin.
We'll keep things simple.
For password, enter the Animals For Life password
that we've been using in previous steps.
Under email, go ahead and enter a fake email address
and then click on Install WordPress.
That will perform the final installation steps.
At which point, you can click on Login.
You'll need to enter the admin username
together with the password that you've just chosen,
and then click on Login.
So this is the WordPress dashboard
and this suggests that our WordPress application
is working absolutely fine.
So to test it, just go to Posts.
We're going to delete the default post of Hello World!
Once done, go ahead and click on Add New.
You can just close down this
"Welcome to block editor" dialogue.
Under Title, use "The best animal," and then "s"
because we might have more than one animal
and then just put an exclamation mark at the end for effect.
Click on the plus underneath that title,
select Gallery.
Click on Upload,
select some animal pictures to upload.
If you don't have any, you can go to Google Images
and download some cat or dog
or gerbil or guinea pig pictures,
anything that you want, chickens, snakes.
Just select a couple of animal pictures to upload
and then click on Open.
And then once uploaded, you can go ahead
and click on Publish
and then Publish again.
And this will publish this post.
And what it's doing in order to publish it,
is it's uploading the images into a local image store
that's called wp-content.
And in addition to that,
it's storing the metadata for this post
into the local MariaDB database.
So, there are two different places that data is stored,
the local content store, as well as the database.
So keep that in mind, as we move on throughout this lesson.
At this point, click on View Post.
Just verify the post loads.
It does, so that means everything's working as expected.
Now the configuration that you've just implemented
has a number of important limitations.
The first is that the application and database
have been built manually,
which takes time and doesn't allow automation.
It's been slow and annoying
and that's very much the intention.
Additionally, the database and the application
are on the same instance.
Neither of them can scale without the other.
The database of the application is stored on an EC2 instance
and that means that scaling in or out
risks data in this database.
The application media,
so the content is stored also
local to the instance in a folder called wp-content.
And this means, again, any scaling events in or out
risks this media.
Additionally customer connections
are directly to an instance
which prevents us from doing any form of scaling,
automatic healing or any health checks.
One final part about WordPress that isn't commonly known
is the IP address of the instance
is actually hard-coded into the database.
Now where this starts to exhibit problems
is when running inside AWS
because EC2 instances don't have static IP addresses.
If we go back to the EC2 console,
right-click on this instance,
and then stop the instance.
Remember, a stop and start of an instance
force the change of the public IP address of the instance.
So restarting it isn't enough.
You need to stop and then start.
Notice how in my case, the IP address for this instance
is 54.85.210.127.
Watch what happens when the instance
fully moves into a stop state.
First, it loses this public IP address
and it moves into the stop state.
If I right-click and then start,
that will take a few moments.
But what will happen is once it's fully started,
it will have a different IP version for public address.
So now if I copy that IP address into my clipboard,
move back to the tab where the website was previously open,
and then open this new IP address
in a different browser tab,
and note how it doesn't load.
Even though the IP address is correct,
it's not loading our WordPress website.
The reason for that is the application is hard-coded
with the IP address that was used to install WordPress.
And so what it's attempting to do now
is reference the old IP address.
It's trying to contact the previous EC2 instance.
Now, this is crucial
because it prevents us from scaling the application.
If we create new EC2 instances,
they'll all point back at this instance.
Even if we fix the database and content issues,
we need to resolve the ability of WordPress to scale.
And don't worry, we'll look at that later
in this demo series.
For now that's everything you needed to do
in stage one of this advanced demo.
You've manually created a WordPress application
with the application and database
running on the same instance.
In stage two, you're going to automate this process.
So go ahead, complete this part of the demo series.
And when you're ready, I look forward to you
joining me in stage two.