Rails (postgeresql. Ubuntu environment), heroku deployment

1 Install rails gem

#For rails6
gem install rails -v 6.0.1
#rails5.In case of 2
gem install rails -v 5.2.1

2 Postgresql installation

$ sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
$ wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql-common
$ sudo apt-get install postgresql-9.5 libpq-dev

3 Create a PostgreSQL Account

$ sudo -u postgres psql
postgres=# create role <username> with createdb login password '<password>';
postgres=# \q

4 Rails new

rails new appname -d postgresql
cd appname

5 Edit config / database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  #Below, 3 lines added
  username: <username> #Same as the set PostgreSQL Account
  password: <password> #Same as the set PostgreSQL Account
  host: localhost
development:
  <<: *default
  database: appname_development #The appname should be the appname for rails new.
test:
  <<: *default
  database: appname_test #The appname should be the appname for rails new.

6 Create database with rails db: create & install webpacker

$ cd appname
$ rails db:create

#Not required for rails5
$ source <(curl -sL https://cdn.learnenough.com/yarn_install)
$ yarn install --check-files
$ rails webpacker:install

#config/enviroments/development.rb
config.hosts.clear

7 Heroku CLI Download and install

$ sudo curl https://cli-assets.heroku.com/install-ubuntu.sh | sh

$ heroku --version

8 Heroku login

$ heroku login
Email: [email protected]
Password: xxxxxxxx

9 Heroku Deploy Ready & Deploy

$ cd rails app
$ git init
$ git add -A
$ git commit -m "first"

#Deploy
$ heroku create
$ git push heroku master
$ heroku run rake db:migrate

--Application--Create heroku app with SSH settings 1 First, log in to Heroku.

$ heroku login --interactive
#You will be asked for your email address and password, so enter them and click enter
Enter your Heroku credentials:
Email: [email protected]
Password: *********

2 Next, add the key to Heroku.

$ heroku keys:add

3 Do you want to upload to Heroku? Is asked, so enter y

? Would you like to upload it to Heroku? (Y/n)

#Then, if the following code appears, it is successful.
Uploading /home/ec2-user/.ssh/id_rsa.pub SSH key... done

4 deploy

$ heroku create newsable-skillhub

#An app is created on Heroku.
Creating ⬢ newsable-skillhub... done
https://newsable-skillhub.herokuapp.com/ | https://git.heroku.com/newsable-skillhub.git

$ git init
$ git add -A
$ git commit -m "first"
$ git push heroku master

$ heroku run rake db:migrate

Recommended Posts

Rails (postgeresql. Ubuntu environment), heroku deployment
Rails Heroku deployment procedure
[Rails] Heroku deployment flow
Rails6 (MySQL, Ubuntu environment, Cloud9)
Deploy heroku with Rails6 (Cloud9 + Ubuntu) + MySQL
[Rails] Nginx, Puma environment deployment & server study [AWS EC2]
[Flutter] Ubuntu 20.04 environment construction
Rails Docker environment construction
Heroku app moving (rails)
rails heroku error log
Beginners use ubuntu in windows to prepare rails environment
Created the first LINEbot on AWS Cloud9 (Rails + Heroku deployment)
[rails] heroku deployment error ActionView :: Template :: Error (Mysql2 :: Error: Table --- doesn't exist):
Rails6 development environment construction [Mac]
Rails engineer environment construction ruby2.7.1
Rails environment construction Rails5.2.1 ruby2.5.1 Catalina
[Environment variables] What are rails environment variables?
[Docker] Rails 5.2 environment construction with docker
[Rails / MySQL] Mac environment construction
Laravel environment construction (Ubuntu 18.04 LTS)
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS