Skip to content

Amazon Linux 2

Tibor Bödecs edited this page Sep 22, 2022 · 18 revisions

⚠️ This is a work in progress guide about setting up a really basic environment for Feather CMS.

These are the most necessary steps to host Feather using an (AWS) Amazon Linux 2 instance.


cat /etc/os-release


sudo vi /etc/environment

# contents

🔒 Keep in mind that you might want to enable other security features or install monitoring tools.


Add EPEL -

sudo amazon-linux-extras install epel -y
# sudo yum install -y
# sudo yum-config-manager --enable epel

Set editor & custom PS (personal preference)

# editor & PS1 .bashrc

export EDITOR='/usr/bin/vi'
export VISUAL='/usr/bin/vi'
PS1='\u@\w: '

SSH agent

# .bashrc
if [ ! -S ~/.ssh/ssh_auth_sock ]; then
   eval `ssh-agent`
   ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock

Add swapfile

When physical RAM is not enough

# 128mb * 32 = 4gb
sudo dd if=/dev/zero of=/swapfile bs=128M count=32
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
sudo vi /etc/fstab
#add line
/swapfile swap swap defaults 0 0

# reboot
free -hm

Install nginx

sudo yum install nginx
# sudo amazon-linux-extras list | grep nginx
# sudo amazon-linux-extras enable nginx1
# sudo amazon-linux-extras install -y nginx1 
# nginx -v

# auto start nginx after boot
sudo chkconfig nginx on

Configure nginx

Setup web directory

# sudo mkdir -p /var/www/
# sudo vi /var/www/

# contents:

Setup domain configuration

# sudo vi /etc/nginx/conf.d/

# contents
server {
    listen	 80;
    root /var/www/;
sudo service nginx restart

Install letsencrypt's certbot

# install certbot with nginx plugin
sudo yum install certbot python-certbot-nginx

# generate certificate 
sudo certbot --nginx -d

Auto renew certificates

# sudo crontab -e 

0 12 * * * /usr/bin/certbot renew --quiet

Install git

sudo yum install git -y

Install swiftenv

git clone ~/.swiftenv
echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile
echo 'export PATH="$SWIFTENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(swiftenv init -)"' >> ~/.bash_profile

Install Swift

sudo yum install binutils gcc git glibc-static gzip libbsd libcurl libedit libicu libsqlite libstdc++-static libuuid libxml2 tar tzdata
sudo yum install libsqlite3x.x86_64 libsqlite3x-devel.x86_64 
sudo yum install -y zlib zlib-devel

swiftenv install --list
swiftenv install 5.5.2
swift --version


# sudo vi /lib/systemd/system/todo.service
Description=Todo server daemon

ExecStart=/var/www/todoapp/Run --log notice


# commands to run
sudo chown -R ec2-user:ec2-user /var/www/todoapp/
sudo chmod +x /lib/systemd/system/todo.service
sudo systemctl daemon-reload
sudo systemctl enable todo.service
sudo systemctl start todo
sudo systemctl status todo

Nginx proxy

server {
    listen 80;

    location / {
        proxy_pass              http://localhost:8080;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
        proxy_read_timeout      90;

Build & deploy

swift package update
swift build
sudo systemctl stop todo

rm Run
rm -rf ./Resources
rm -rf feather-core_FeatherCore.resources/

cp -R .build/debug/feather-core_FeatherCore.resources/ ./
cp .build/debug/Feather ./Run

sudo systemctl start todo 
sudo systemctl status todo