WordPress is an open-source CMS originally built as a web publishing platform, quickly becoming a de-facto standard for blogs. Thanks to its huge third-party plugin ecosystem, WordPress has been adopted for use in many different situations never imagined by its creators, including dynamic websites, e-commerce platforms, and online newspapers. It's a terrific software package with a huge user base, but getting the most out of it can be tricky.
This course demonstrates installing and running WordPress on Amazon Web Services. Expert Linux System Administrator David Clinton will guide you through installation, from the easy way (using a Cloudformation template), up to deploying a highly customizable instance on EC2 and RDS. You will learn to use optimization tools like Varnish and Route53 and to monitor availability and costs with CloudWatch.
If you have thoughts or suggestions for this course, please contact Cloud Academy at email@example.com.
This is an intermediate course that will assume some basic knowledge of the AWS system. Some familiarity with the Linux Command Line Interface and MySQL might also be helpful.To move to the next step, check out our EC2 and RDS courses, and our introductory AWS video. You might also enjoy our courses on CloudFormation, LAMP stacks on AWS and Security on Linux based AWS instances, which make great follow-ups. If you want to challenge yourself, check out our questions.
Hi, and welcome to CloudAcadamy.com's video series on hosting your WordPress site in the cloud on AWS, Amazon Web Services. In this video, we'll discuss manually installing and securing WordPress using the command line on your AWS instance. Let's first create an instance using EC2. We'll launch an instance. We'll choose Ubuntu. Let's just review and launch. We're not going to worry ourselves with too many of the configuration details for now. Choose an existing key pair. We'll go with mykey.
We'll acknowledge that we have access to that key, and we'll launch the instance. Let's view instances. We will note the public IP this instance will use because we're going to have to access that later.
Now we've SSH'd into our new instance. Let's get the instance ready for our WordPress services. First, sudo apt-get update to make sure that the instance has all the necessary repository information.
Now, sudo apt-get install tasksel, which is a utility that apparently is already on the system that allows us to select software stacks. Let's now run tasksel, and we are already running the basic Ubuntu server and the OpenSSH server.
Let's use the arrow key to scroll down through the list. The list is actually quite a bit longer than what you see on the screen, but we want to install the LAMP server. We'll use the spacebar to toggle LAMP server to on, then tab to highlight okay, and then enter to get this job going. Now, let's download WordPress itself using wget https://wordpress.org/latest.tar.gz, that is the latest image of WordPress will now be downloaded directly to the directory we happen to be in right now. That was done, and that was done very quickly. Let's tar xzf, pointing to the file name we're about to enter, which is latest.tar.gz. That's done. Ls, let's list the contents of our directory. There's a new directory that was just created called wordpress. We'll enter and ls to list what's in there, and these are our configuration files we'll work with soon. First, though, let's get MySQL, the database software, set up. Sudo service mysql start. That is telling Ubuntu to, if it isn't already, start MySQL. As it turns out, it's already running. Now let's enter mysql-u. The user we're going to enter as is root, and p for password. There is no password. We didn't set a password in this particular time when we installed MySQL. Usually you would. In this case I didn't just for simplicity sake. We're now in the MySQL shell. We will now create a user called Ubuntu, and his domain will be within localhost.
It will be identified by the password, password. That actually will be the password. Normally, of course, we'd use a much stronger password than that, but I'd rather that wasn't identified on the screen. So for now, I'm just using the password, password. The very worst password you could possibly choose. Now, let's create a new database. It will be called wordpress-db. We'll grant all privileges on wordpress-db to Ubuntu, this new Ubuntu user. Meaning, the user Ubuntu has complete control over the wordpress-db database. Finally, we'll flush privileges.
That is, any changes that have been made to the privileges associated with MySQL or with wordpress-db will now be updated. And we'll exit the shell. Now, ls, let's list again the contents of our WordPress directory, and, cp, let's copy wp config sample php to wp config php. That is, we want to make that particular sample php configuration file the actual wp configuration file, which WordPress will read before starting up each time. Let's edit the file, nano wp config.php, and let's go down a few lines and look for certain key definitions. The first one is define DB_NAME. What is the name of the database that WordPress is going to use? Well, we already chose the name of our database, our MySQL database.
Wordpress-db. What the name of our user? Ubuntu. And, we'll need a password. It's the same password, obviously, we used when setting up the MySQL database, and of course it's the worst password you could possibly use, but it's the one we're going to get by with for now. Now, we would like to set up our keys and salts. That is, there are values we can assign to these keys and, what's called, salts to increase the security of our WordPress instance, and to do that, we'll head to the web.
Now, in order to generate some key and salt values, we'll go to the wordpress.org API site, and it generates, automatically for us, values for each of these keys and salts. We'll highlight them, copy them, and make note of them for later. Now, we're back in our wordpress config file.
Let's, using ctrl K, remove each line that was there by default and replace it using ctrl shift V with the new values that were copied from the WordPress website. We can now hit ctrl X, Y for yes, to overwrite and save our changes to the config file, and that's done. Now, we will move, that is, copy, using -r, which means we'll recursively copy all the directories and subdirectories here, all the contents of this directory, that is, all the configuration files for WordPress, to it's new home, var/www/html.
Now, let's just take a quick look at var/www/html. List the contents. There is a file, index.html, which is action Apache file. That's the default page a browser visiting this url will open. We want to get rid of that. We would like WordPress instead to have control of this directory.
So we'll just, let's say, sudo mv index.html to index.html.backup. We don't want to destroy it, necessarily, but at least get it out of the way. Now, let's set some permissions and create some more streamlined configurations for our WordPress instance. Sudo addgroup. We're going to add a new group called www.
Let's, sudo usermod -a -G www ubuntu. Let's add our ubuntu user to the www group. Let's now change the ownership of the group, -R www. We're going to change the group www, I should say, to become the owner of the directory of our www/html.
Let's now change the permissions associated with this directory to 2775. That is, 7, the owner of the directory, will have full control, read, write and execute. The group associated with the directory will have full control, and others will have read and execute, but not write control.
Those will be your visitors coming from anywhere on the web. Var/www/html is the directory we have now changed. We'd like these changes to affect even files and directories which may be created later.
So, let's run find /var/www -type d, that is, any directory within the www hierarchy, and then execute on that directory the similar change mode to 2775.
Let's do almost the same thing. Find /var/www anything, which is -type f, that is any file which may be associated with this directory or these directories, and execute on those this change mode. Let's now make sure that Apache can take our changes into account. Sudo service apache2 restart. And now, let's finally make sure that both Apache and MySQL are set to restart on system reboot. Let's change directory to etc/init.d. Run a list, and let's see if there's a script for either or both of these two services, which, by being in this directory, will restart on reboot. Apache2 has its script and MySQL has its script. Finally, let's point our browser to the IP address AWS gave us for our instance. We've removed the index.html file that Apache had left in the .var/www/html directory. Let's see if WordPress has replaced it with everything necessary to start the WordPress site. And it has.
David taught high school for twenty years, worked as a Linux system administrator for five years, and has been writing since he could hold a crayon between his fingers. His childhood bedroom wall has since been repainted.
Having worked directly with all kinds of technology, David derives great pleasure from completing projects that draw on as many tools from his toolkit as possible.
Besides being a Linux system administrator with a strong focus on virtualization and security tools, David writes technical documentation and user guides, and creates technology training videos.
His favorite technology tool is the one that should be just about ready for release tomorrow. Or Thursday.