
I will start by assuming that you already have an Amazon.com account. Go to http://aws.amazon.com and sign in to your account.
AWS provides dozens of services. The one we are looking for is EC2 (which stands for Elastic Compute Cloud). After you sign in to AWS, you should see a link to the EC2 section
Which Instance Type?
I have had good success with a c3.xlarge instance serving 2 million pageviews per month. If you do not expect much traffic, you can start with a t2.small or t4g.small instance
Logging in from Linux
ssh -i /path/my-key-pair.pem ubuntu@ServerIP
Logging in from Mac
ssh -i ./.ssh/my-key-pair.pem ubuntu@ServerIP
so for mac you should just copy .pem key to .ssh folder but you should change the key permission:
below command to change permission
sudo chmod 600 my-key-pair.pem
Installing WordPress
here are various ways of installing WordPress. Here I will show the manual, reliable way of doing it.
Step 1. Go to your document root directory (/var/www/html). “Directory” is the Linux word for what is commonly called a “folder” on Windows.
cd /var/www/html
Step 2. Download the latest zipped version of WordPress.
sudo wget http://wordpress.org/latest.tar.gz
wget is the standard Linux download utility. The link shown above will always contain the latest version of WordPress (the developers update the file as the new versions are released without changing the link).
Step 3. Extract the WordPress download into its own directory.
sudo tar xzvf latest.tar.gz
This will create a directory named “wordpress” in your root directory that will contain your WordPress files, thus you will end up with:
3. Installing and Configuring Your Server Software
/var/www/html/wordpress
Step 4. You won’t need the zipped version of WordPress anymore that you downloaded in Step 2 (since you have unzipped it). Run the rm command to remove the unnecessary file:
sudo rm latest.tar.gz
Step 5. You will now create the necessary changes to the MySQL database to make it ready for WordPress. WordPress doesn’t store its data (things like posts) in files, it stores them in a database for quick access, for this reason you need functioning database software on your site to run WordPress. Fortunately, MySQL is a free and powerful database management system, for this reason you will not be needing anything more for your database needs.
Log into the MySQL “server” (i.e. the MySQL program) running on your server. The wording can be confusing. Your Ubuntu installation is a “server”, while the Apache program running inside it is also a “server”, and of course MySQL is also a server. A server is any program that stays up and waits for other programs to make requests to it. That are various other servers running on your server, but these are enough to know about, at least at your current stage.
sudo mysql -u root -p
Run the following five statements (pressing Enter after each line). You can keep everything as it is, except for the “password”, which should be changed to something a bit less easy to guess.
CREATE DATABASE wordpressdb;
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
FLUSH PRIVILEGES;
EXIT;
The next step is to create the WordPress configuration file and make a few necessary changes to it. Go into the WordPress directory:
cd /var/www/html/wordpress
WordPress provides a sample configuration file (wp-config-sample.php) to get you going. Copy this file and name it wp-config.php to turn it into the real configuration file.
sudo cp wp-config-sample.php wp-config.php
Now, open wp-config.php for editing. There are various text editors that come with Linux. Personally I prefer Vim, but beginners will enjoy nano more. To open the file, type:
sudo nano wp-config.php
Use your arrow keys and the rest of the keys on your keyboard like you’d do on a Windows text editor. Here are the lines you’d need to change:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'password');
The “wordpress” in the first line above is the database name that we chose in the first line of your MySQL statements. The second and third lines come from the second line of your MySQL statements.
There are eight lines of code starting with “define('AUTH_KEY...” and ending with “define('NONCE_SALT...”. These are important definitions required for the safety of your installation. Go to https://api.wordpress.org/secret-key/1.1/salt/ to generate these eight lines automatically and copy and paste them into your wp-config.php file instead of trying to come up with your own random strings. Thus, you start with the following:
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
Then, you delete all of these lines, go to the link provided above, and copy and paste everything from there.
Setting Up a .htaccess File
WordPress uses a type of Apache configuration file called a .htaccess file that controls the way Apache processes particular directories. Your WordPress installation needs a .htaccess for certain tasks, such as setting up pretty permalinks. For this reason, it is important to create this file. To do so, first visit https://codex.wordpress.org/htaccess and at the top, in the Basic WP section, you will see the default WordPress .htaccess file that you can use for your own install.
Navigate to /var/www/html/wordpress. Run the following command to create an empty .htaccess file:
sudo touch .htaccess
Change the file ownership so that Apache can modify the file when necessary:
sudo chown www-data:www-data .htaccess
Then edit the file to paste the default .htaccess contents into it:
sudo nano .htaccess
If you are using PuTTY, you can just copy the content of the .htaccess file from the website, open up the .htaccess file for editing, then right-click on the PuTTY window to paste it into there.
After your server’s IP changes, your WordPress installation may start malfunctioning, loading
What this means is that your browser is failing to load the WordPress style files. This happens because WordPress is still referencing your old IP address in its internals, trying to load part of your site through the new IP and part of it through the old IP.
To fix, this go into MySQL to update WordPress’s idea about your site’s IP address. Type the following command in the command line:
mysql -u wordpressuser wordpressdb -p
This tells MySQL to log in as the wordpressuser and to select the wordpressdb database. The -p tells MySQL to prompt you to enter a password. If you omit the -p, you will be denied access. Enter the password for the wordpressuser which you set earlier in this book and press Enter.
If you are using PuTTY, you can copy the password (if you have it saved in a file), then right click on the PuTTY window to paste it. PuTTY will not give any indication that a paste has occurred since this is a password prompt and Linux does not show any feedback when typing passwords.
Once you are inside the MySQL command line, type the following command to update your IP in the wordpress database:
update wp_options set option_value = "http://NEWIP" where option_value = "http://OLDIP";
To get a domain, first you need to buy it (though you can test a domain without buying it as I explain in the next section) from a “domain registrar”. There are seemingly endless companies that sell domains, including even Google. Sign up with such a company, find the domain you like and buy it. Then, visit your domain’s “DNS Settings Page”. Different registrars have different ways of referring to this page, search the registrar’s knowledge base or wiki for “change dns settings” to find out where you can find this page.
Once on that page, choose to add an “A” record to your domain.
AWS makes it very easy to add new drives to your server. Note that in general it is better to use one large SSD disk on AWS rather than multiple small ones. Due to the way the AWS infrastructure is designed, one large disk will probably get you better speeds than multiple smaller ones
But if you need extra space and you do not want to migrate your data to a large disk, then attaching a new disk is the best option you have. One reason why you’d want to use an attached disk is that you want to create backups that are not always accessible from your server. You’d attach the disk, put your backups on it, then detach it and perhaps copy it. This way you’d have a safe copy of your data stored on AWS that cannot be harmed if hackers break into your server.
To create a new disk drive (also called a “volume”), on the EC2 dashboard, click the “Volumes” link on the left menu.
Important: Make sure to choose the same Availability Zone for the volume as you chose for your instance, otherwise your disk will end up in a datacenter miles away from where your instance is.
This course is the course I wish I had when I started managing my own web servers for the businesses I own. Due to the complexity of the technologies involved, there is often limitless room for ambiguities and misunderstandings when dealing with servers. You are trying to do tasks that should be simple in theory, but you end up wasting hours and even days trying to make it work. This course helps you avoid that by taking the guesswork out of setting up your web servers on cloud providers, configuring them and scaling them.
This course provides a broad overview of the entire process of building and scaling web servers using a VPS/Cloud provider, while also providing minute step-by-step instructions (with lots of and command line examples) on performing each and every important task necessary to get your server(s) going.
Note that this course does not teach you programming or website design. It teaches you how to create, manage and scale web servers, and it even shows you how to create a working WordPress installation that you can edit and publish stuff on. It is assumed that you’d use a web developer’s services to customize your websites, or that you are a web developer yourself.