I've spent most of the last three days struggling with installing RefineryCMS on Heroku.
There are a lot of questions on SO and on various blogs, as well as documentation from Refinery and Heroku (and Rails) but none of the walkthroughs have helped 100%... Every page seems to be missing some vital piece of information.
I've tried to document all the necessary steps having gone through them three or four times, refining the procedure each time (working out what is and isn't necessary).
References included where they were obvious.
Run the refinery initialisation script, with Heroku option
refinerycms myapp --heroku
From http://refinerycms.com/guides/heroku
The output should give you a new heroku app and its name listed in the output:
"Creating Heroku app.. run heroku create --stack cedar from "."
Creating ... done, stack is cedar
http://[your heroku app].herokuapp.com/ | git#heroku.com:[your heroku app].git
Git remote heroku added"
Create bucket on Amazon AWS…
Should be self-explanatory.
Set connection info for Amazon in the Heroku environment
We need both sets of credentials.
AWS_* and FOG_* is for Heroku (and the rails precompile, I believe).
S3_* stuff is for Refinery to be able to upload images etc.
heroku config:add AWS_ACCESS_KEY_ID="<your key>" AWS_SECRET_ACCESS_KEY="<your secret>" FOG_DIRECTORY="<your bucket name>" FOG_PROVIDER="AWS" FOG_REGION="<your aws region>"
heroku config:add S3_BUCKET="<your bucket name>" S3_KEY="<your key>" S3_REGION="<your aws region>" S3_SECRET="<your secret>"
Add required gems to your Gemfile
gem 'globalize3', '0.3.0'
From refinerycms not working when adding page
gem 'unf'
(fixes some warnings)
gem 'rails_12factor'
From Why is the rails_12factor gem necessary on Heroku?
gem 'asset_sync'
From https://github.com/rumblelabs/asset_sync.
This gem seems the only way to get the assets pushed up to the cloud... Although perhaps you can make do without it; perhaps someone else can confirm.
ruby '2.0.0'
[ place this at the end of the Gemfile. (Needed to clear Heroku warnings) ]
Add asset_sync asset host path in config/environments/production.rb
config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
From https://github.com/rumblelabs/asset_sync
Set the site name in config/initializers/refinery/core.rb
config.site_name = <your site name>
Set the s3_backend in the config/environments/production.rb
Refinery::Core.config.s3_backend = true
From https://github.com/refinery/refinerycms/issues/1879
Configure database details
Remove sqlite3 in config/database.yml and setting postgresql instead: this is optional but recommended by Heroku and others
For adapter:
sqlite3 => postgresql
For database name:
db/foo.sqlite3 => <sitename>_foo
Set user-env-precompile settings
heroku labs:enable user-env-compile -a myapp
From https://devcenter.heroku.com/articles/labs-user-env-compile
Run the Bundler
bundle install
Note: First of all, I had to run, as prompted:
1. rvm use 2.0.0 in order to match the version we're using in Gemfile
2. bundle update globalize3
From refinerycms not working when adding page
Create (local) production database
RAILS_ENV=production rake db:create
Set environment variables needed before asset precompile can work
(this is for *nix, do whatever you need to on your platform)
export FOG_DIRECTORY="<your bucket name>"
export FOG_PROVIDER="AWS"
export AWS_SECRET_ACCESS_KEY="<your secret>"
export AWS_ACCESS_KEY_ID="<your key>"
Precompile the assets (???)
NOTE: This MAY NOT be required... (I did do this step each time but cannot be sure whether it's required. The next steps suggest to me it's not necessary to manually precompile: we need to change the "initialize_on_precompile" to false, run a git push to heroku (i.e. without assets), then set the "initialize_on_precompile" back to true for future pushes. Not sure why we need to do this, and it may be an issue only with Rails 3.* (see: https://devcenter.heroku.com/articles/rails-asset-pipeline)
RAILS_ENV=production bundle exec rake assets:precompile
Set precompile false in config/application.rb
config.assets.initialize_on_precompile = false
From http://refinerycms.com/guides/heroku…
This setting is required the first time you git push to heroku, because otherwise the precompile step of git push heroku master always fails with:
Connecting to database specified by DATABASE_URL
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
NOTE: The reference is not clear on this (although setting intially to false then true is mentioned elsewhere).
Check in files to git and commit changes
Note: add the Gemfile.lock along with all the other changes.
Push to heroku
git push heroku master
Set precompile option back to true in config/application.rb
config.assets.initialize_on_precompile = true
From http://refinerycms.com/guides/heroku…
Add config/application.rb to git and commit (!!)
... if you don't, the next push will fail
Push to heroku (Demonstrates that this time it succeeds)
git push heroku master
Migrate and seed on the Heroku database
heroku run rake db:migrate
heroku run rake db:seed
From http://refinerycms.com/guides/heroku
Ready to go!
Hopefully from here you have access to your RefineryCMS page, with all the Refinery CSS and images displaying correctly (both on the admin screens and when 'viewing website' but still logged in.
If you add an image using the Refinery menu you should subsequently be able to see that image added to your AWS bucket. I don't have thumbnails working yet.
Related
I built a Rails 6 app and deployed it to Heroku. But any changes I make to the stylesheet are not reflected. All the Heroku documentation and SO questions/answers appear to no longer be relevant to the current Rails setup in this regard. I could precompile the assets before pushing to heroku but I'd prefer not to. And actually I did find a "solution" but it feels more like a hack than a real solution. If I open config/initializers/assets.rb and change the statement:
Rails.application.config.assets.version = '1.0'
to
Rails.application.config.assets.version = '1.1'
then it will update the assets. But that means if I am experimenting with the look of the site I would be changing the version all the time. I mean if that's they way it's supposed to work I'll live with it, but it doesn't seem right. Anyone know a way to get Heroku to just update it on every push?
You've to compile the assets from the heroku end(i.e. in your server on Heroku), so after pushing your code to Heroku, run:
$ heroku run rake assets:precompile
# If above doesn't work
$ heroku run RAILS_ENV=production rake assets:precompile
Also, it's a good practice to add public/assets(or whatever folder that precompiles to) folder to your .gitignore file, so incase if you precompile assets in your local environment this will not mess up with your production env when you push to Heroku. But everytime you change some CSS and push to heroku, you'll need to precomile assets on Heroku end from the above command.
I am trying to upload RoR application to Heroku.
OS - Ubuntu, ruby version - 2.2.2p95, rails version - 4.2.1, database - PostgreSQL, installed RoR via BrightBox (Tutorial from treehouse), using git push heroku master to upload.
On the local server app works fine. When I push it to heroku, it gives out an error:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
If you are the application owner check the logs for more information.
Log files say:
/usr/bin/env: ruby2.2: No such file or directory
I've tried all the possible variants, I could find on the Internet:
rake rails:update:bin
Remove bin from ~/.gitignore (But there is no such file)
heroku config:set PATH=bin:vendor/bundle/ruby/2.2.2/bin:/usr/local/bin:/usr/bin:/bin
Adding this to the GemFile: ruby '2.2.2'
Changed #!/usr/bin/env ruby2.2(.2 (not sure about ".2")) to #!/usr/bin/env ruby (in bin/rake, bin/bundle and bin/rails)
heroku run rails db:migrate
rake rails:update:bin
ln -s /usr/bin/nodejs /usr/bin/node
To upload to heroku, I've configured git, after that logged in heroku, after that "heroku create", after that "git push heroku master", then "heroku open"
And many others... Any ideas how to solve that problem?
Do you have the gem rails12_factor installed and config.assets.compile = true ?
Not sure you mistyped or something else. but heroku run rails db:migrate will not work it should be heroku run rake db:migrate . It might be because you don't have root page. Precompile issue etc.
Run heroku logs -a app_name to see actual logs.
I am currently first time deploying my app to Heroku, and am encountering the precompile error. When I execute the command git push heroku master, I get:
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
After a bit of searching, I encountered both Heroku's own troubleshooting guide on precompile error, as well as this post on precompile errors and Rails 3.2, and following their directions, did the following:
Added config.assets.initialize_on_precompile = false to my application.rb file
Made a new heroku app using heroku create just to be safe
Per the Rails guide, ran bundle exec rake assets:precompile
I thought that since I am doing the compiling locally, when pushing to Heroku it would just skip the compilation part based on detecting a manifest.yml file. However, even when I do so, when running git push heroku master, it will still run rake assets:precompile and generate the same error as seen above.
Thanks in advance for you help!
Addendum
In my .gitignore, I have the following:
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
At first glance, I would assume that it should work.
Can you confirm that you have committed and merged all changes into master? i.e. git status
After three evenings on this problem and reading all the posts about this, I have to ask this question finally!
I want to deploy the most simple Rails app to Heroku:
rails new test_appli
cd test_appli
git init
git add .
git commit -m "initial commit"
heroku create
git push heroku master
Everything's OK, the application works well on Heroku. After that, I'll create a SQLite3 database:
rails generate scaffold User name:string email:string
rake db:migrate
Everything's OK on the local machine. I can see localhost:3000/users well. Then I want to put the DB on Heroku. First I modify my Gemfile:
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
Then I send the whole thing to Heroku:
git init
git add .
git commit -m "with Database"
git push heroku master
heroku rake db:migrate
Then there are no errors in the batch, everything is OK, the DB is sent, but the page heroku.com/users gives the error
Rails 500, "We're sorry, but something went wrong"
I don't know more what to do. Can you help me?
I suspect you're trying to deploy a Rails 3.1 application to the bamboo stack (heroku create defaults to the 1.9.2 bamboo stack and doesn't run Rails 3.1 out of the box.). The Cedar stack is much better suited to Rails 3.1 sites -
try
heroku create --stack cedar
when creating your application on Heroku and repush it up. Also note your rake command on Heroku will become
heroku run rake db:migrate
Do:
heroku run rake db:schema:load
I had the same issue. It works for me after git push heroku master
Don't do the git init in the second set of commands - you only need to initialise your Git repo once.
Other than that this looks fine - are you seeing any errors anywhere?
Why would you use the pg gem in your production group, but the sqlite3 gem in your development group? Seems to me that your problem is likely due to the fact that you're developing with a different database then you're using in the production environment. If I were you, I would stick to one, which would make it much easier to debug.
If you really want/need to get the application running ASAP, then just run it in production with sqlite... Gemfile:
gem 'rails'
gem 'sqlite3'
Also, a quick way to figure out what the error is would be to run heroku logs from the unix console.
Which version of Rails?
Can you try creating the application running on the Cedar stack?
heroku create myapp --stack cedar
Given the application is running on cedar you need to modify the commands a bit, for example:
heroku run rake db:migrate
In any case you really need to checkout your logs, because your problem might not even be database related, but assets related.
Do you have the heroku shared 5mb database instance added?
When you create your heroku app (on cedar) it doesn't necessarily create the database automatically.
airlift:projects $ heroku create --stack cedar testapp9
Creating testapp9... done, stack is cedar
http://testapp9.herokuapp.com/ | git#heroku.com:testapp9.git
airlift:projects $ heroku addons --app testapp9
logging:basic
releases:basic
When you view your heroku config, you get nothing:
heroku config
airlift:projects $ heroku config --app testapp9
airlift:projects $
To add a database:
heroku addons:add shared-database:5mb
airlift:projects $ heroku addons:add shared-database:5mb --app testapp9
-----> Adding shared-database:5mb to testapp9... done, v3 (free)
airlift:projects $ heroku config
No app specified.
Run this command from an app folder or specify which app to use with --app <app name>
airlift:projects $ heroku config --app testapp9
DATABASE_URL => postgres://blah:blah#blah.compute-1.amazonaws.com/blah
SHARED_DATABASE_URL => postgres://blah:blah#blah.compute-1.amazonaws.com/blah
airlift:projects $
Then you should be able migrate your db.
Hey #redronin thanks for helping me find a way to connect to my postgres database on Heroku, however as a newbie to Heroku and postgresql I had to reverse engineer what "blah" was. So I figure I would break it down to help others as you helped me.
postgres://[user]:[password]#[servername].compute-1.amazonaws.com/[database]
How to deploy a Rails app using Mysql on heroku?
I find out that my app did not need Amazon RDS (Too expensive for a small app).
Here is my answer how to use Amazon RDS
Heroku help deploying Rails app that uses Mysql database
Include mysql2 gem in your gemfile:
gem 'mysql2'
Now, your choice can be: https://addons.heroku.com/cleardb add-ons. You can get upto 5mb free storage but you need to fill your credit card information for accessing it.
Steps for using clearDB add-ons are:
# add cleardb add-ons to your app
$ heroku addons:add cleardb:ignite
-----> Adding cleardb to sharp-mountain-4005... done, v18 (free)
# retrieve your database URL:
$ heroku config | grep CLEARDB_DATABASE_URL
CLEARDB_DATABASE_URL => mysql://adffdadf2341:adf4234#us-cdbr-east.cleardb.com/heroku_db?reconnect=true
# copy CLEARDB_DATABASE_URL config variable and set it to your DATABASE_URL config variable
$ heroku config:set DATABASE_URL='mysql://adffdadf2341:adf4234#us-cdbr-east.cleardb.com/heroku_db?reconnect=true'
Adding config vars:
DATABASE_URL => mysql2://adffd...b?reconnect=true
Restarting app... done, v61.
# NOTE: since we are using ```mysql2``` in our gemfile so replace mysql:// scheme in the CLEARDB_DATABASE_URL to mysql2://
$ heroku config:set DATABASE_URL='mysql2://adffdadf2341:adf4234#us-cdbr-east.cleardb.com/heroku_db?reconnect=true'
$ heroku config:set CLEARDB_DATABASE_URL='mysql2://adffdadf2341:adf4234#us-cdbr-east.cleardb.com/heroku_db?reconnect=true'
Please follow: https://devcenter.heroku.com/articles/cleardb for more information
Hope that can help you.
If you do a heroku db:push from your MySql data, it'll automatically get pushed into the heorku PostgreSQL database structure.
You can then do db:pulls and pull back into mysql. Taps provides this database magic.
It's really great -- I'd try it out first before trying to get RDS working.