Using WordPress to Create a Static Website

So I want to create a serverless website.  But I am horrible at artistic design and I really don’t want to spend the time typing in HTML5 by hand.  So I need a solution.  WordPress makes some nice websites, but how do I make it static.  A Google search shows an answer called Simply Static.

Simply Static is the easiest way to create a static site. It crawls through your WordPress site, creating static copies of your pages and including assets like stylesheets and JavaScript files.

Simply Static is a plugin in WordPress that will traverse your wordpress website and turn all of the dynamic content into static content.  That will be great, but I’m going to need a server running WordPress.  That’s where AWS comes in.  And since I am the only user of the WordPress server, it can be a tiny instance.

  • 64 bit Amazon Linux AMI
  • t2 micro instance
  • Default settings, except
    • IAM roles should allow full access to an S3 bucket where you are hosting the static version of the website
    • Security group
      • Allow SSH from your local IP
      • allow HTTP from anywhere (yes anywhere, the Simply Static  crawl through the website will not come from your IP)

Once that starts up you will need to SSH in and install the following.  You have to be careful with the versions as WordPress can be sensitive.

  • Apache HTTPD version 2.4
  • MySQL version 5.7
  • PHP version 7.1
  • WordPress version 4.8.2
  • Simply Static version 2.1.0

And optionally

  • Landing Pagency WordPress theme version 4.0
  • phpMyAdmin version 4.7.5

There are a number of steps that need to be taken, so I created a user data script to handle it all.  Now I can use that to create a server that functions from the start with the software I need.


#!/bin/bash

# bring the instance up-to-date
yum update -y


# install Apache httpd version 2.4
yum install httpd24 -y


# change the httpd.conf file
cd /etc/httpd/conf
mv httpd.conf httpd.conf.old
sed '0,/Directory \"\/var\/www\/html/! {0,/AllowOverride None/ s/AllowOverride None/AllowOverride All/}' httpd.conf.old > httpd.conf


# start httpd
service httpd start
chkconfig httpd on


# install MySQL Server version 5.7
yum install mysql57-server -y
service mysqld start
chkconfig mysqld on
mysqladmin -uroot create wordpress
mysql_secure_installation << $$
N
replaceme
replaceme
Y
Y
Y
Y
$$


# Install PHP version 7.1
yum install php71 php71-mysqlnd php71-mbstring php71-gd -y
service httpd restart
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php


# install WordPress version 4.8.2
cd /var/www/html
wget https://wordpress.org/wordpress-4.8.2.tar.gz
tar -xvzf wordpress-4.8.2.tar.gz
rm wordpress-4.8.2.tar.gz
cd wordpress
cat wp-config-sample.php | sed -e 's/database_name_here/wordpress/' -e 's/username_here/root/' -e 's/password_here/replaceme/' > wp-config.php


# install Simply-Static WordPress Plugin
cd /var/www/html/wordpress/wp-content/plugins
wget https://downloads.wordpress.org/plugin/simply-static.2.1.0.zip
unzip simply-static.2.1.0.zip
rm simply-static.2.1.0.zip


# install landing pagency theme
cd /var/www/html/wordpress/wp_content/themes
wget https://downloads.wordpress.org/theme/landing-pagency.4.0.zip
unzip landing-pagency.4.0.zip
rm landing-pagency.4.0.zip


# install phpMyAdmin version 4.7.5
cd /var/www/html
wget https://files.phpmyadmin.net/phpMyAdmin/4.7.5/phpMyAdmin-4.7.5-all-languages.tar.gz
tar -xvzf phpMyAdmin-4.7.5-all-languages.tar.gz
mv phpMyAdmin-4.7.5-all-languages phpMyAdmin
rm phpMyAdmin-4.7.5-all-languages.tar.gz
cat > /var/www/html/phpMyAdmin/config.inc.php << $$
<?php
/*
 * Generated configuration file
 * Generated by: phpMyAdmin 4.7.5 setup script
 * Date: Mon, 30 Oct 2017 18:07:16 +0000
 */

/* Servers configuration */
\$i = 0;

/* Server: localhost [1] */
\$i++;
\$cfg['Servers'][\$i]['verbose'] = '';
\$cfg['Servers'][\$i]['host'] = 'localhost';
\$cfg['Servers'][\$i]['port'] = '';
\$cfg['Servers'][\$i]['socket'] = '';
\$cfg['Servers'][\$i]['auth_type'] = 'cookie';
\$cfg['Servers'][\$i]['user'] = 'root';
\$cfg['Servers'][\$i]['password'] = 'replaceme';

/* End of servers configuration */

\$cfg['blowfish_secret'] = ')j}[c:|}{1gZ>4#(#{Pg@?m5Dy/gA;95';
\$cfg['UploadDir'] = '';
\$cfg['SaveDir'] = '';
\$cfg['DefaultLang'] = 'en';
\$cfg['ServerDefault'] = 1;
?>
$$


# adjust the user group and umask settings
usermod -g apache ec2-user
usermod -a -G ec2-user ec2-user


# adjust the http file owner and permissions
chown -R ec2-user:apache /var/www/*
chmod -R g+w /var/www/*
echo "umask 2" >> /home/ec2-user/.bashrc