Run your Ruby on Rails application in AWS from scratch
This article will introduce how to run your Ruby on Rails application in AWS from scratch. I will describe the steps from installing Ruby, MySQL, to setting up the Rails application.

Install RVM and Ruby 3.1.1
You could install RVM via the following command. For more detail, please check the article below.
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB#if error occured, type the following lines:
curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
curl -sSL https://get.rvm.io | bash -s stable --rails
rvm install 3.1.1
Install MySQL
sudo apt install mysql-client-core-5.7
sudo apt-get install mysql-server
Reset MySQL root password
# Enter mysql console without passwordsudo mysql --user=root mysql# in mysql consoleUPDATE mysql.user SET authentication_string=null WHERE User='root';flush privileges;ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';flush privileges;exit
Replace ‘your_password’ with the password you would like to use.
Clone your Rails project from GitHub
mkdir projects
cd projectsgit clone xxx (your project)
Bundle install
rvm use ruby-3.1.1
bundle install
You might encounter the following error when you run the bundle install. Please run the following command to solve it.
sudo apt-get install default-libmysqlclient-dev

Copy database.yml
If you didn’t commit database.yml, secrets.yml, initializers/devise.rb to git repository, please remember to copy it to the project folder in AWS.
Run your application
Run your application at port 80, then you could easily access it from outside without mentioning the port number.
rails db:createrails db:migratervmsudo rails s -b 0.0.0.0 -p 80
Now you can access it from the browser by the public IP you assigned in AWS.