Working with an instance from its creation to a full-fledged working application. Phusionpassenger guide.
- Create instance with ubuntu (Free tier eligible)
- Generate PEW key to connecting to them
- Download this key
- Change file access using
chmod
chmod 600 ~/Downloads/pemfile.pem
- Import it into your SSH store
ssh-add /path/to/pemfile.pem
Connect to your instance
ssh [email protected]
#or
ssh -i default.pew [email protected]
- Install rvm, ruby, nginx, nodejs, redis
sudo apt-get install software-properties-common
sudo apt-add-repository -y ppa:rael-gc/rvm
sudo apt-get update
sudo apt-get install rvm
echo `source "/etc/profile.d/rvm.sh"` >> ~/.bashrc
rvm install ruby-2.5.5
sudo apt-get update
sudo apt-get install -y nginx
sudo service nginx restart
sudo apt install redis-server
sudo systemctl status redis # testing redis-server
# fix rvm/bin path
echo $rvm_bin_path
mkdir ~/.rvm/bin
ln -s /usr/share/rvm/bin/rvm .rvm/bin/rvm
Create new bitbucket in your AWS Simple Storage Service Create access to this services
region and bucket name you can find in S3 -> Buckets -> Name of new bucket -> Access point Change file storage.yml to:
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
service: S3
access_key_id: <%= Rails.application.credentials.aws[:bucket_access_key_id] %>
secret_access_key: <%= Rails.application.credentials.aws[:bucket_secret_access_key] %>
region: 'us-east-2'
bucket: 'projector-kv065'
Go to Permissions -> CORS configuration and past
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://youre_ip_addres</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Create new Simple Email Service Create new access key to enable access using IAM
Test your configuration inside you rails c
ses = AWS::SES::Base.new( :access_key_id => 'abc', :secret_access_key => '123',
:server => 'email.eu-west-1.amazonaws.com', :message_id_domain => 'eu-west-1.amazonses.com')
ses = AWS::SES::Base.new( :access_key_id => 'AKIATTTHFGKFIDRMFZPR', :secret_access_key => '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', :server => 'email.us-east-2.amazonaws.com', :message_id_domain => 'us-east-2.amazonaws.com' )
ses.send_email( :to => ['[email protected]'], :source => '[email protected]', :subject => 'Subject Line', :text_body => 'Internal text body')
You can find you domain inside information about domain( if you have one), or email address
'SocketError: Failed to open TCP connection to email.us-east-2.amazonses.com:443' Enable 433 port at the EC2 server > Security > Click to unique name of Security group.
cap production deploy
sudo reboot
# or
/sbin/reboot
passenger-status
sudo passenger-status --show=requests
sudo passenger-config restart-app
# error messages if start doesn't work is in folder tmp
Passenger write all requests and errors in the file production.log
tail -f /var/www/yourappname/current/log/staging.log
cd /etc/nginx/sites-enabled/
sudo vim projector.conf
# put this inside the file:
server {
listen 80;
#listen [::]:80 ip_address;
server_name default_server;
#listen 80 default_server;
#listen [::]:80 default_server;
# Tell Nginx and Passenger where your app's 'public' directory is
root /home/ubuntu/deploy/projector/production/current;
# Turn on Passenger
passenger_enabled on;
passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.5.5/wrappers/ruby;
}
# copy settings
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
# Then restart Nginx
sudo service nginx restart
mkdir /home/ubuntu/projector/deploy/production
cd /home/ubuntu/projector/deploy/production
mkdir shared releases
scp ~/Documents/projector/config/master.key ubuntu@ip_address:/deploy/projector/production/shared/config
scp ~/Documents/projector/config/database.yml ubuntu@ip_address:/deploy/projector/production/shared/config
Sidekiq write log in the file
tail -f /var/www/yourappname/current/log/sidekiq.log
Stop sidekiq
cd ~/deploy/projector/production/current
bundle exec sidekiqctl stop tmp/pids/sidekiq-0.pid 0