Hosting Your Own WordPress Blog – Step 4 – Install Apache and PHP on Your Cloud Server

Step 4 – HARD

Installing Apache and PHP on your cloud server with command line tools will feel awkward to the uninitiated. But mostly you’re just copying and pasting commands, then… waiting for them to finish.

First, we log into the server via our Terminal application, similar to step 2, right after we created our EC2 cloud server instance. See below, copied from the step 2 blog post:

Open an SSH client (the Terminal application), then run the example SSH command. Note that the file “MY_SERVER_KEY_PAIR.pem” should be in the same folder that you’re executing the command from. On my device, we default to the “home” folder, so I’ve copied the file there. Full path to the file looks like: /home/MY_SERVER_KEY_PAIR.pem. Execute the command like so:

Connect via Terminal
Connect via Terminal

A lot of the information provided in the terminal will not be interesting to you, so you can ignore it. What you’re looking for is a successful connection as indicated by the green line at the bottom:  ubuntu@ip-172-31-19-107:~$ This indicates that you’re connected and able to execute commands as the “ubuntu” user. Type “exit” into the terminal if you wish to disconnect for now.


Second, we need to issue a list of commands to install the Apache server software:

Command 1 will update your system, preparing it to grab the latest Apache version.

sudo apt-get update && sudo apt-get upgrade

While command 1 executes, you will see a bunch of “Get” statements executing, the reading of package lists, and a list of packages that will be upgraded. Then you will be prompted to continue: “After this operation, 165 kB of additional disk space will be used. Do you want to continue? [Y/n]”. Answer with a “Y” and hit Enter. You’ll then see a flood of “Preparing” and “Unpacking” statements.

Note: If you are prompted with questions like the following: “A new version of [XYZ] is available, but the version installed currently has been locally modified, What do you want to do about modified configuration file?”, simply select “Keep the local version currently installed” and hit Enter.

When the process is complete, you’ll be returned to the command prompt: ubuntu@ip-172-31-19-107:~$

Command 2 will install everything you need for the Apache software:

sudo apt-get install apache2 apache2-doc apache2-utils

Similar to command 1, you will see a bunch of  statements executing. When prompted to continue: “After this operation, 31.0 MB of additional disk space will be used. Do you want to continue? [Y/n]”. Answer with a “Y” and hit Enter. You’ll then see a flood of “Preparing” and “Unpacking” statements.

When the process is complete, you’ll be returned to the command prompt: ubuntu@ip-172-31-19-107:~$

Command 3 will restart Apache. Enter this in your terminal.

sudo service apache2 restart

Third, we need to modify our security groups. You may not know this, but all Amazon EC2 instances have very high security by default. Try connecting to your EC2 instance from your web browser now by typing in the amazon address, IP address, or your domain name. Notice it fails? This means, NOBODY can connect to your server except you, and that requires a special connection with your key/pair file.

This level of security is obviously no good for our purposes. We want our users to connect to our website in their web browsers, so we need to modify our security policy to allow for HTTP connections.

AWS Management Console Login
AWS Management Console Login

Once again, log into the AWS console with our account here:  AWS Management Console. This is the same console we’ve been using all along.

 

 

 

 

 

Navigate to your EC2 instance and click on it. In the panel that appears at the bottom of the console, you’ll notice the following. It’s the inbound rules that we need to modify. Click on the “launch-wizard-7” link to open the editor:

Security Groups
Security Groups
Security Group Editor - Inbound
Security Group Editor – Inbound

 

Click on the “Edit” button, and you’ll be presented with a dialog similar to the below. Make the following changes then click “Save”. This will add two new rules to the inbound rules above:

  • Type: HTTP
  • Source: Anywhere
Edit Inbound Rules
Edit Inbound Rules
Apache 2 Ubuntu Default Page
Apache 2 Ubuntu Default Page

Now you can confirm access via your own web browser, and see the Apache start page. You can copy and paste the Amazon URL, the IP address of your instance, or the website name you connected in step 3: Create a Hosted Zone Using Amazon Route 53. As a reminder, these would look like so:

ec2-34-221-223-243.us-west-2.compute.amazonaws.com
54.189.133.122
infinitedab.com

 

 

 

 

Finally, we need to install PHP 7. This the server-side run time environment for WordPress. If you don’t have PHP installed, the .php scripts required by WordPress will not be able to execute.

Command 4 will get PHP installed and run as an Apache module. Enter this in your Terminal. When asked if you wish to continue, type “Y”. When the process is complete, you’ll be returned to the command prompt once again: ubuntu@ip-172-31-19-107:~$

sudo apt install php libapache2-mod-php php-mysql

Command 5 will restart Apache. Enter this in your terminal.

sudo service apache2 restart

Congratulations!

You’ve completed step 4, which is ranked at HARD difficulty. Now onto step 5.

 


All Steps:

Introduction & Overview- Hosting Your Own WordPress Blog

  1. (EASY) Buying a Domain Name
  2. (HARD) Create a Cloud Server Using Amazon AWS
  3. (EASY) Create a Hosted Zone Using Amazon Route 53
  4. (HARD) Install Apache and PHP on Your Cloud Server
  5. (EASY) Create MySQL Cloud Database Using Amazon RDS
  6. (EASY) Download and Install WordPress on Your Server

Leave a Reply

Your email address will not be published. Required fields are marked *