In this post, I’m doing an assignment for the linux server course held by Tero Karvinen. I’m going to install wordpress to my virtual private server on Amazon EC2, which I created earlier. I will be using a MacBook Pro (late 2013) as a terminal and the Amazon EC2 virtual server as the server. The server is equipped with a minimal installation of LAMP and a .tk domain I also set up on the same article.
First off, we need to connect to the server with SSH.
ssh -i amazon_ec2_sshkey.pem email@example.com
Now I’ll navigate to the public_html folder of the ‘ubuntu’ user and replace the ‘index.html’ I created there earlier with the content of ‘Hello World!’ with the source files of WordPress and unzip the package.
cd public_html rm index.html wget https://wordpress.org/latest.zip unzip latest.zip
Now we have a folder called ‘wordpress’ containing the latest source files. Next I’ll remove the archive I don’t need anymore and move the wordpress files to document root (one level up), which is the ‘public_html’ folder we’re in. Also, remove the empty ‘wordpress’ folder afterwards.
rm latest.zip mv wordpress/* ./ rm -r wordpress
Next up is the installation. Let’s navigate our web browser to the URL in which we just inserted the installation. In my case it’s metsanheimo.tk
Before continuing ahead, we will need a database and an user for it. Let’s log on to MySQL.
mysql -u root -p Password: MariaDB [(none)]>
Now we’re in, first off let’s create the new database.
CREATE DATABASE wordpress
That was simple enough, now for the user, we’ll also associate the user with the database.
CREATE USER wordpress@localhost IDENTIFIED BY 'yourpassword'; GRANT ALL PRIVILEGES ON wordpress.* to wordpress@localhost IDENTIFIED BY 'yourpassword'; FLUSH PRIVILEGES; exit
Now we have an user that has rights to access just one database. The wordpress installation will populate the database by itself, we need to leave it empty.
Fill up the information we just created for it and press ‘submit’.
If you have the correct permissions set, you’ll get an error like me:
Now let’s do as it says. Copy that content to a new file called ‘wp-config.php’ to the document root.
Paste the content and save. Now press ‘Run the install’.
Next you’ll be prompted for an username, a password and your e-mail. Then you’ll be able to log on to your fresh wordpress installation.
Using pretty URL’s (permalinks)
For good SEO and proper linking you’ll need to change a few settings. Navigate to the permalinks menu.
There’s a list of most common usages and you can also create your own. I would recommend the ‘month and name’ or ‘day and name’ setting. Press the ‘Save Changes’ button. You’ll get a notice to update the ‘.htaccess’ file. This is the file that does all the magic. Let’s copy the content it wants us to add to it and return to the terminal.
For the ‘.htaccess’ file to word, we’ll need to enable the apache module for it.
sudo a2enmod rewrite
Also, we’ll need to add ‘AllowOverride All’ setting to the apache config file: 
sudo nano /etc/apache2/sites-available/metsanheimo.tk.conf
<Directory /home/ubuntu/public_html> Require all granted AllowOverride All </Directory>
sudo service apache2 restart
And then add the content into the file:
Paste in the content and save.
Links should now work! http://metsanheimo.tk/2015/10/08/lorem-ipsum-dolor-sit-amet/ will give me the content of the post.
Using images in your posts
To add images to your posts, the permissions need to be set right. Let’s navigate to create a new post.
Above the text field there’s a ‘Add Media’ button, let’s click it.
Now we’ll try to add an image to the site, select ‘Upload Files’.
After trying to upload an image, we got an error about permissions.
Let’s go to our terminal and navigate to ‘wp-content’ and create a folder called uploads.
cd wp-content mkdir uploads
The permissions of the folder normally look like this:
drwxrwxr-x 2 ubuntu ubuntu 4096 Oct 8 11:04 uploads/
There’s one permission missing, and that’s the write permission for others.
chmod -R o+w uploads
This command recursively adds the write permission to others for the uploads folder.
drwxrwxrwx 2 ubuntu ubuntu 4096 Oct 8 11:04 uploads/
There we have it. Let’s try the upload again!
Manually installing a module via SSH
Installing a module to WordPress is simple, but also requires some changes. For this example I’m installing a module called ‘All in one SEO‘. Wordpress naturally is very good in SEO, but it has some holes. This module covers them all.
I’m going to use SSH to download the plugin to the server. I don’t like giving wordpress the permissions to access via FTP. 
cd wp-content/plugins wget https://downloads.wordpress.org/plugin/all-in-one-seo-pack.zip unzip all-in-one-seo-pack.zip rm all-in-one-seo-pack.zip
Now that we have the plugin in the plugin folder, let’s navigate to the plugins.
And there it is! Now just press ‘Activate’ to make it active.
Manually installing and changing the theme via SSH
This is what most want to do first, the visual side. Free WordPress themes can be found at their website, and everywhere else online. For this example, I’ll be using the Sydney theme found on the popular themes.
This is more or less like the same as installing a plugin. Let’s navigate via SSH to the theme folder.
cd wp-content/themes wget https://downloads.wordpress.org/theme/sydney.1.17.zip unzip sydney.1.17.zip rm sydney.1.17.zip
Then navigate to the wordpress themes.
Here we have our themes, and WordPress automatically found the new theme.
Hover over it and press ‘Activate’ and you will have a new theme on your site!
There we have it, thank you for reading!
Class by Tero Karvinen
 AskUbuntu.com – AllowOverride All
 WordPress.org – Plugins