Are you a developer?
Don't have a resume website yet?
Is money the main reason you haven't got one?
If you answered yes to the questions above, then this guide is for you and today those excuses are gone! I've done all the hard work for you, just follow this guide and start applying for developer jobs today!
If you just want to take a crack at cheaper self hosted options for your WordPress site then this guide is also for you.
Hopefully this guide will be verbose enough to keep you on track and teach you a thing or two. Follow along! Every section is concluded with a video recap but to see those you'll have to look at the original post at https://drewlearns.com/move-your-wordpress-website-to-aws-from-another-host-for-free/
I created this for myself out of frustration that I couldn't find a single document that accurately walked me from nothing to a working WordPress site on AWS with an SSL and without paying for an AMI on free tier AWS.
If you make it all the way through this guide and would like to know how to add an autoscaling group, place your setup on your own AMI, host your images on an S3, leverage CloudFront's CDN and much more - Let me know in the comments section!
Table of contents:
- Creating your resume website (Optional if you are just migrating a site)
- Creating Your First EC2 Instance
- PHP installation
- Install MariaDB (MySQL) and Apache
- Install a certificate with auto renewal
- Secure your Database
- Install WordPress
- Set up FTP/SFTP for file transfer
- Migrate your site from local to your AWS account
Creating your resume website (Optional if you are just migrating a site)
If you'd like to create a site from scratch, this is a great place to start:
You can build a Resume using the Starter files you created from my video tutorial or my written tutorial. All totally free of charge!
You can access the starter files from that tutorial here: https://share.drewlearns.com/4gujpBpl/ (if that link doesn't work try this one).
Creatinging Your First EC2 Instance
-
Create Amazon account - it will charge you $1 but that charge will fall off.
-
Navigate to EC2 service
-
Click "Review and Launch"
-
Click "Launch".
-
Click the first drop down and select "Create a new key pair" then name the keypair "wp-keypair".
-
A file will download called "wp-keypair.pem".
-
In terminal move that file to your root directory.
mv ~/Downloads/wp-key-pair.pem ~/ && cd ~/
-
We have to add permissions to the file to use it so run
chmod 400 wp-key-pair.pem
then click "Launch Instance" -
You should see your EC2 instance dashboard and an Instance ID with an Instance state saying "Pending" followed by "Running".
-
Click the Instance ID link in blue and an instance summary will appear. Select the "Security" tab .
You can also find your public IP address in this screen. From that IP, you can point your domain to it, I'd strongly recommend doing that to take the full benefit of this guide. If you chose not to, you'll need to use your AWS public domain or IP address in the steps that follow instead of example.com.
-
Add your IP for inbound SSH connections then save rules ( I skipped this step in the video recap at the bottom of this section but don't worry, we come back to it)
-
Return to the EC2 dashboard and select the Instance you just edited. Click it's check box then Actions > Connect.
-
Click the "SSH Client" tab. There is an example snippet, copy paste it into your terminal and press return. Type "yes" and press return again to acknowledge connecting. You are now SSH'd into your Instance.
-
Check for updates:
sudo yum check-update && sudo yum update
PHP installation
PHP is our backend server language for WordPress. Let's get it installed.
-
Let's confirm amazon-linux-extras, if you don't see a directory output then you'll have to install using
sudo yum install -y amazon-linux-extras
- I think this comes standard now, though I'm not positive. -
Let's make sure that the PHP version we would like to use is available. Run:
sudo amazon-linux-extras | grep php
.
I personally prefer having my site as secure and performant as possible so I like the latest version where possible. I recognize some plugins/themes don't support latest versions of plugins/themes, in those cases I'd dump the plugin/theme over instead of lay blame on the PHP version as being the issue. I don't want plugins installed that don't operate on currently supported PHP versions myself.
-
Install PHP 7.4 using the following command:
sudo amazon-linux-extras enable php7.4 && yum clean metadata && sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap} -y
-
Verify PHP is installed by running
php -v
You may also be curious what PHP modules are installed, you can find this using
php -m
-
Make sure PHP is installed, and running and no longer ephemeral by running the following:
sudo chkconfig php-fpm on && sudo service php-fpm start && sudo service php-fpm status
Install MariaDB (MySQL) & Apache Webserver
-
Install it, but make sure to agree to installation.
sudo yum install -y httpd mariadb-server
-
Enable the database service:
sudo systemctl enable --now mariadb
-
Start and create a symlink for your Apache Web Server so that it starts on reboot automatically.
sudo systemctl start httpd && sudo systemctl enable httpd && sudo systemctl is-enabled httpd
-
Verify it's running by going to your EC2 Dashboard and clicking the instance ID link and then going to the IP address in your browser, it should look like this:
-
Update your ec2-user's permissions to have access to manipulate the apache directory
sudo usermod -a -G apache ec2-user && exit
-
Use your "Up" key to reuse your ssh connection command.
If you use
groups
command, you will see "apache" listed for your user. -
Update the ownership of your www directory:
sudo chown -R ec2-user:apache /var/www && sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \; && find /var/www -type f -exec sudo chmod 0664 {} \;
Install a certificate with auto renewal:
-
Run the following command to install EPEL (Extra Packages for Enterprise Linux)
sudo wget -r --no-parent -A 'epel-release-*.rpm' https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/ && sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-*.rpm && sudo yum-config-manager --enable epel* && sudo yum repolist all
-
Update your apache config file to show your new domain:
sudo nano /etc/httpd/conf/httpd.conf
-
Locate the line that reads "Listen 80" and just after it paste the following:
<VirtualHost *:80> DocumentRoot "/var/www/html" ServerName "
example.com
" ServerAlias "www.example.com
" </VirtualHost> - Locate the line that starts with <Directory "/var/www/html" and add these 2 lines inside the Directory brackets & ddit the line that says
AllowOveride None
to sayAllowOveride All
-
Press "Command" + "X", then "Y", then "Return".
-
Restart Apache:
sudo systemctl restart httpd
If you made any mistakes in the httpd.conf file, you will get errors about httpd.service failing. You can get more details about the error by running
systemctl status httpd.service
-
Add your certbot and run it!
sudo yum install -y certbot python2-certbot-apache && sudo certbot
-
Enter your email address.
-
Press return, then "Y" and return again
-
Again, press return, then "Y" and return again
-
Type
1, 2
. (assuming you are using an alias domain like www you provided in httpd.conf file) -
Automate the certbot!
sudo nano /etc/crontab
-
Add a cron job with root permissions to run
certbot renew --no-self-upgrade
twice daily at 01:30 & 13:30:30 1,13 * * * root certbot renew --no-self-upgrade
-
-
Restart your cron daemon:
sudo systemctl restart crond
Your site is now secure!
Secure your Database
-
Secure and test your database connection:
sudo mysql_secure_installation
-
When prompted for a password press Return
-
Change/Set the root password? [Y/n]
Press "y" and "return".
New password: Re-enter new password:
-
Remove anonymous users? [Y/n]
Press "y" and "return".
-
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]Press "y" and "return".
-
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]Press "y" and "return".
-
Disallow root login remotely? [Y/n]
Press "y" and "return".
-
Remove test database and access to it? [Y/n] y
Press "y" and "return".
-
Reload privilege tables now? [Y/n]
Press "y" and "return".
-
Start your MariaDB:
sudo systemctl enable --now mariadb
-
Make sure you can log in by typing:
mysql -u root -p
-
Create a new user, obviously change "wordpress-user" and "your_strong_password" to suite
CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'your_strong_password';
Query OK, 0 rows affected (0.001 sec)
-
Create your database and name it something meaningful:
CREATE DATABASE `WordPres
s-db
`;💡 Don't forget to close that command out with a
;
-
Provide that database full privileges for your user. Be sure to update the wordpress-db name and the wordpress-user name to match what you just called it in the previous ste.
GRANT ALL PRIVILEGES ON `
WordPress-db
`.* TO "wordpress-user"@"localhost"; -
Flush your privledges to pick up all your new configurations:
FLUSH PRIVILEGES;
-
Exit your mysql prompt with
exit
.
Install WordPress
- Let's install a base WordPress image onto our WordPress
The following command downloads, cleans up and creates a wp-config.php file.
cd /var/www/html/ && sudo wget https://wordpress.org/latest.tar.gz && sudo tar -xzf latest.tar.gz && sudo rm latest.tar.gz && sudo cp -r /var/www/html/wordpress/* /var/www/html/ && cp wp-config-sample.php wp-config.php && sudo rm wp-config-sample.php && nano wp-config.php
-
Use your d-pad to navigate and edit the following fields with the information you created in the section above.
Remember this is not your maria-db root password for your DB_PASSWORD field! -
Edit your Salts:
-
Change your database table prefix to something more obscure than
wp_
and make it something likewp_123456_
. Bear in mind, it has to end with an underscore. -
Press "Control" + "X" to close the editor and then press "Y" then "Return" to save.
-
We have to make sure the server has complete access to these files so we need to edit their permissions:
🚨 If you miss this step or it fails, you'll get a weird ftp credential popup when trying to install plugins/themes.
sudo chown -R apache:apache /var/www/html
-
Navigate in a browser to your domain. You should be prompted with a WordPress Welcome screen. Fill out those details.
Set up FTP/SFTP for file transfer
Currently your site is lacking connectivity to the EC2's file system. We need to add FTP or SFTP. This will allow us to install plugins and more. You may be curious or interested in the ability to upload your file system to S3 and since I'm currently over my PUTS limit this month, I'll be holding out on a tutorial about this for a little while. If you are really wanting to do it though, here is a good guide I found: https://docs.aws.amazon.com/codedeploy/latest/userguide/tutorials-wordpress-upload-application.html
-
Add an FTP plugin to your server:
sudo yum install vsftpd -y
-
Restart your FTP server:
sudo systemctl restart vsftpd
-
Add a new SFTP user to your site using the following two commands, bear in mind you can choose any username you'd like, these are just placeholders.
sudo adduser awsftpuser
&
sudo passwd awsftpuser
You'll then be prompted for a password twice.
-
Grant that user permissions to update the home directory:
sudo usermod -d /etc/httpd/ awsftpuser && sudo usermod -a -G root awsftpuser && sudo systemctl restart vsftpd && sudo chkconfig --level 345 vsftpd on
-
Edit your vsftpd conf file by typing:
sudo nano /etc/vsftpd/vsftpd.conf
Find the line that reads:
# Allow anonymous FTP? (Beware - allowed by default if $ anonymous_enable=YES
to
# Allow anonymous FTP? (Beware - allowed by default if $ anonymous_enable=NO
Uncomment out the line that reads:
chroot_local_user=YESAt the bottom of the file add:
pasv_enable=YES pasv_min_port=1024 pasv_max_port=1048 pasv_address=
🚨Don't forget to change the part of that line. You can grab this from your EC2 dashboard by clicking on the instance ID.
-
Press "Control" + "X" to close the editor and then press "Y" then "Return" to save.
-
Restart the FTP pod one more time:
sudo systemctl restart vsftpd
Migrate your site to the AWS server!
Your WordPress Site is now up and running. If you already have a site on another host, you can migrate it.
The Easiest way to migrate a site is to install a plugin called "Migrate Guru: Migrate & Clone WordPress Free" on both sites and let it do the magic.
If you'd like a more indepth discussion on how to manually migrate your site's files and database from one host to another Let me know in the comments section below.
Top comments (0)