I'm trying to deploy an app to heroku. I'm running an ubuntu VM. I just had a lot of trouble getting postgres set up, but I think I'm good to go with that.
I've run
heroku create
and i've committed the most recent changed upon my master branch. When I run bundle install - everything is ok. And when I run
git push heroku master
Everything is smooth, including the installing of the gems. Until I reach the line
------> Writing config/database.yml to read from DATABASE_URL
Everything stalls and I'm greeted with this message 15 minutes later
Timed out compiling ruby app (15 minutes)
for good measure here is my database.yml code
development:
adapter: postgresql
database: saasbook
pool: 5
password:
And here is my gem file
gem 'rails', '4.0.2'
gem 'rails_12factor' , group: :production
gem 'pg'
gem 'saas-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'oauth2'
gem 'figaro'
gem 'rake'
gem devise'
gem 'bootstrap-sass'
gem 'rails_layout'
gem 'zxing'
gem 'rmagick'
gem 'carrierwave'
gem 'rqrcode_png'
ruby "2.0.0"
The heroku deployment tutorial stated to insert the line ruby "2.0.0" after bundle install, and before the commit. I am currently running ruby 1.9.3 if that matters/ would have a conflict.
Any suggestions would be a huge help! thanks!
Edit
I'll leave this out here in case this problem ever arises again for someone
Alas, heroku doesn't like java/C dependent gems, and the QR decoding gem ZXING cannot be used on heroku, that was the reason it was stalling.
For starters, you're missing a quote in your Gemfile for devise:
gem devise' should be gem 'devise'
I would also recommend moving the ruby "2.0.0" line to the top of the Gemfile. It may not matter, but it's worth a shot.
Could be a network issue. Be sure the network you are using has all the appropriate ports open for GIT and heroku. You will need more than port 80.
I am sure you solved this already but for ref:
Make sure that your IDE (mine is RubyMine) is not open on that project or the build will stall/fail.
Related
In my gemfile I have:
gem 'mysql2'
My database.yml is as follows:
default: &default
adapter: mysql2
database: <%= ENV['db_name'] %>
username: <%= ENV['db_user'] %>
password: <%= ENV['db_pass'] %>
host: <%= ENV['db_host'] %>
pool: 32
socket: <%= ENV['socket'] %>
development:
<<: *default
production:
<<: *default
I've run both bundle update and bundle install and my Gemfile.lock shows mysql2.
However when I run rake db:migrate I get this on both my computer and on the staging server:
myproject.com(master)$ rake db:migrate
WARNING: Use strings for Figaro configuration. 10000012508 was converted to "10000012508".
WARNING: Use strings for Figaro configuration. 860526407370038 was converted to "860526407370038".
rake aborted!
Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
.....
Just to make sure there wasn't a bad version of mysql2 or something, I did bundle clean --force and ran bundle install and bundle update again and when I run gem list I see mysql2 (0.4.0) and no other versions.
Any ideas would be most appreciated.
SOLUTION
It's currently an issue with Rails 4.1.x and 4.2.x, per this bug report, it will be fixed in the next release of rails 4.2.x (credit to dcorr in comments for the link).
In the mean time you can fix by doing downgraded to version 0.3.18 of mysql2 by adding this line to your gemfile:
gem 'mysql2', '~> 0.3.18'
Just do:
gem 'mysql2', '~> 0.3.18' this gem works with rails version 4.x.x
if install gem 'mysql2', '~> 0.4.0' it produces gem load error and causes compatibility issues
Just a further update - the solution in the question is correct.
The 4th comment is worth taking note of:
This isn't a bug with mysql2, it's a problem with the requirement in
the ActiveRecord adapter: http://github.com/rails/rails/issues/21544.
This is fixed in rails master:
https://github.com/rails/rails/commit/5da5e3772c32593ecf2f27b8865e81dcbe3af692
I was able to tie Rails 4.2.4 to the 4-2-stable branch and get it working with the latest mysql2:
gem 'rails', '~> 4.2.4', git: "git://github.com/rails/rails.git", branch: '4-2-stable'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] #-> Rails 4.1+
#DB
gem 'mysql2'
This issue was addressed here: https://github.com/brianmario/mysql2/issues/950
For Rails 4.x please pin the gem to mysql2 '~> 0.4.0' to avoid the 0.5.x upgrade.
Gemfile:
gem 'rails', '4.2.8'
gem 'mysql2', '~> 0.4.0'
Then run bundle update rails mysql2
I am currently using mysql v 8.0.11
The answer to this particular question relative to when it was posted and the version of Rails being used is that the problem is caused from doing a bundle update and your mysql2 version updates to 0.4.x which has an incompatibility issue with latest Rails ActiveRecord.
Again, please note this is NOT the solution for people using older versions of Rails / ActiveRecord.
The quick solution is to simply specify the mysql2 version in your gemfile as follows:
gem 'mysql2', '0.3.20'
The long solution would be to wait for either an update to ActiveRecord or something in mysql2 to change.
If you are able to upgrade your rails version, then change your Gemfile to this and it will solve the problem without downgrading the mysql2 gem version:
gem 'rails', '4.2.6'
As a complete beginner i got confused on how to do this so I just did a trial check and finally got my server working , here is how i got it working .
get into the file of working directory("work") and from there get into the file of the app you created("sample_app")which has mysql 2 installed go to gem file ("Gemfile")edit gem 'mysql2' to gem 'mysql2', '~> 0.3.18'
now go back to cmd and run command "bundle install".
so the directory to edit file taking consideration of above files in brackets should be .
"c\work\sample_app\Gemfile"
hope i was of some help .
This usually happens when you are missing some mysql packages on your machine. Do you get any errors from gem install mysql2? What OS are you working on?
If on debian or ubuntu try sudo apt-get install libmysqlclient-dev.
Also make sure that the gem is not placed inside a group statement in your Gemfile.
Had same issue but adding source 'https://rubygems.org' to the top of gem file solved issue.
Steps:
add source 'https://rubygems.org' to your gem file.
Comment out mysql2 gem and add gem 'mysql2', '~> 0.3.18'
Run bundle install
try this:
bundle update mysql2
this command will update your 'mysql2' gem to the latest version (should be 0.3.17 or higher) and start your rails server.
gem 'rails', '4.2.11.3'
gem 'mysql2', '~> 0.4.0'
Try this. This will remove the mysql2 load error.
I am trying to use postgresql with Ruby on Rails on Heroku but got an error
Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
Please help me to solve this issue.
This worked for me
gem 'pg', '~> 0.20'
Thanks to Piers C
Got this answer from
Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE
In your Gemfile
group :production do
gem 'pg'
end
Then run bundle install and try to deploy on Heroku.
If you want to use PostgreSQL on all environments and not only in production (recommended) add the gem outside the :production group and remove other database adapters such as sqlite.
As a side note, you may also want to add the rails_12factor gem as suggested by Heroku.
Add pg in gemfile
gem 'pg', '~> 0.20'
then bundle update & commit Gemfile & Gemfile.lock to heroku.
simple include like gem 'pg' will not work.
I added the following version into my gemfile, and it is solved.
gem "pg", "~> 0.18"
I have been repeating this tutorial for weeks now:
https://www.digitalocean.com/community/articles/how-to-1-click-install-ruby-on-rails-on-ubuntu-12-10-with-digitalocean
Here are the specifics of my project:
I am using Mongoid with database.yml production set to my tested and working Droplet (DigitalOcean VPS) running MongoDB.
My gem file is here, I am new to Rails and am not quite sure if it's set up right, so I just moved them all to assets hoping Unicorn might serve these gems for me?
source 'https://rubygems.org'
gem 'rails', '3.2.14'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails"
gem 'redcarpet', '1.17.2'
gem 'uglifier', '>= 1.0.3'
gem "will_paginate_mongoid"
gem 'will_paginate', '~> 3.0.5'
gem 'will_paginate-bootstrap'
gem 'devise'
gem 'jquery-rails'
gem "mongoid", "~> 3.0.0"
end
Here's what I did:
I used DigitalOcean's 1 click installer. Then I used FileZilla to SFTP into the credentials they provided me with. I deleted all the files in /home/rails and put my new files in from my project. Then I executed bundle install, and restarted the unicorn service. In the tutorial I had seen I can track the log of unicorn, so I executed this: tail -f /home/unicorn/log/unicorn.log
Here is the output which concerns me:
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.3.5/lib/bundler/runtime.rb:33:in `block in setup': You have already activated rack 1.5.2, but your Gemfile requires rack 1.4.5. Using bundle exec may solve this. (Gem::LoadError)
I saw some other solutions to this, all failed. Here are the solutions I tried:
Deleting my Gemfile.lock, and re bundle installing it. Going into the file and removing where it said rack. Running bundle install --binstubs. Restarting the unicorn service with bundle exec before it. The error remains the same.
I've had many different errors before, but I feel this is the closest I have gotten. If someone could explain this to me (I'm new to Rails and would like a thorough explanation) and possibly help me fix the error that would be fantastic and end this frustration.
Just a wild guess
gem "rack", "~> 1.4.5"
May work for you, then of course bundle install afterwards.
This solves the problem:
gem uninstall rack -v 1.5.2
Possibly reload your Ubuntu installation from the DigitalOcean control panel, then try and install Ruby on Rails with Apache and Passenger?
Install RoR
Install Passenger (skip to passenger installation)
You will have errors when first creating your site with rails new as it will try and use SQL when it won't be installed, if you wish to use MongoDB
Having the following issue, BRAND NEW TO RoR, first time ever trying to upload an app to go live, first had hosting issues, then decided if i could fix them with heroku i would just use a custom domain with heroku...... No this isnt a test app "learning rails" thing, actual app i want to deploy for use within the business I own, any help would be great, I have searched and havent seen a solution to this problem.
Make sure 'gem install sqlite3 -v 1.3.7' succeeds before bundling.
Failed to install gems via Bundler
Heroku push rejected, failed to compile Ruby/rails app
To git#heroku.com:peaceful-chamber-6371.git
[remote rejected] master -> master <pre-receive hook declined>
error: failed to push some refs to 'git#heroku.com:peaceful-chamber-6371.git
Gem File
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'twitter-bootstrap-rails'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
try this,
remove Gemfile.lock file and do bundle install , then git add, git commit and git push .
Look though the all of the output that Heroku writes to the console -- your error is likely to be there somewhere. I ran into this and found that the precompile step had failed. That can be run locally as well:
rake assets:precompile
Although the question has an accepted answer, the answer did not help me,
I had the same problem. The following worked for me, hence contributing. Heroku does not support sqlite 3. In this case, I had sqlite3 gem in my gemfile, which you are supposed to put in development group, and put postgres gem (which heroku supports) in production group.
1) Delete the gemfile.lock file (from your project folder)
2) In the gemfile, remove gem sqlite3 or similar sqlite3 gem
3) Instead of that add following to the end of file:
group :development, :test do
gem 'sqlite3'
end
gem 'pg', group: :production`
Now, run the following commands in terminal:
bundle install
git add .
git commit
git push
git push heroku master
Although it was a silly mistake, It took me time to realize the same. Hope it helps someone.
Heroku's asset plugins no longer work since Rails 4 does not support plugins. You need to use Heroku's asset gems instead. Place this in your Gemfile:
group :production do
gem 'rails_12factor'
end
Answer found here: Heroku does NOT compile files under assets pipelines in Rails 4 worked for me
My issue was that I had my bower directory ignored in .gitignore.
So I either need to do bower install from my packages.json or check in my bower dir.
http://xseignard.github.io/2013/02/18/use-bower-with-heroku/
I chose to check in my bower dir for a quick solution right now.
Heroku does not like sqlite3, change gem 'sqlite3' with gem 'pg'
For M1 users,
bundle lock --add-platform x86_64-linux
to resolve the architecture conflict
I just started the ruby.railstutorial.org book by Michael Hartl and have been working through the first chapter. I am using mac book OS X, Terminal, and Sublime Text. Everything has gone according to plan, up until it was time to test deployment to Heroku. I am able to connect to Heroku and run the $ git push heroku master command. But the deployment fails:
Installing sqlite3 (1.3.5) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
An error occurred while installing sqlite3 (1.3.5), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.5'` succeeds before bundling.
!
! Failed to install gems via Bundler.
!
! Detected sqlite3 gem which is not supported on Heroku.
! http://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development
!
! Heroku push rejected, failed to compile Ruby/rails app
Here is my Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3', '1.3.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.5'
gem 'coffee-rails', '~> 3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :production do
gem 'pg', '0.12.2'
end
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
I have sqlite3 designated for development and not production, so I thought Heroku would just ignore it all together, but that does not seem to be the case.
Also, when i create the bundle i am using
$ bundle install --without production
I know that some people has suggested to just install PG and use that, but I really want to stick to the tutorial as much as possible, before I venture out and try a different approach.
I am a bit lost at the moment, and not sure how to proceed from here. Any help that you can provide would be most appreciated.
Thanks
Heroku can't install the sqlite3 gem, for whatever reason. But you can tell bundler that it shouldn't be trying to except when developing.
In your Gemfile, replace gem 'sqlite3' with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
Then bundler on heroku, running as production, won't try to install it.
I was finally able to deploy successfully to Heroku. Thanks to evanc3 for pointing me to an article on the Heroku site. It appears that I simply forgot to commit my Gemgile updates before deploying to Heroku. So for all of you just starting out, you need to make sure you commit your changes before deploying to Heroku.
Heroku do not support sqlite3...
Remove sqlite3 from your Gemfile, use pg gem instead. Do following change in gem file
change following in your Gemfile
gem 'sqlite3'
to
gem 'pg' #you will have to install postgresql
Important: Run
git add .
git commit
git push heroku master
Note: If you are planning to deploy for heroku, I suggest it is better to use postgres in your development phase also(install postgresql in your computer), heroku prefer psql.
If you want to use sqllite for development and postgresql for Heroku, use following config.
group :development do
gem 'sqlite3' #gem to use in development environment
end
group :production do
gem 'pg' #gem to use in production environment
end
Heroku will use pg gem since heroku run your application in production enviroment
On Heroku, your app doesn't have access to the filesystem. There's a number of reasons for this - it's basically due to the fact that you can scale your app's performance by adding new instances (i.e. running multiple servers at once), and these instances aren't guaranteed to be on the same physical machine - copying the files across would be extremely slow.
SQLite just stores the database to a file in your db/ folder, which is why it's incompatible with Heroku.
The best option, as suggested in the help link, is to move away from SQLite, because there are sometimes subtle incompatibilities between SQLite and PostgreSQL (Heroku's database of choice) and you want to find this out before you deploy to production!
After you install PostgreSQL (exactly how to do this depends on your OS) and then add gem 'pg' to your Gemfile.
I have a solution for if you don't have sqlite3 directly in your gemfile and you're still getting this error.
Most likely, you have a gem that uses sqlite3 as a dependency and it's including the gem without you knowing.
1) Go to Gemfile.lock and do a search for sqlite.
2) Locate which gem is using sqlite then move the gem into the development or test group.
3) Bundle
In Rails Tutorial they have you using sqlite3 in development & pg in production. One reason heroku deployment may fail is if your production deployment on heroku still references sqlite in your database.yml rather than postgres.
tldr; your config/database.yml should match the one shown here:
https://github.com/mhartl/sample_app_6th_ed/blob/main/config/database.yml
most importantly your production config lines should match this (so that adapter: postgres rather than adapter: sqlite3):
production:
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
database: sample_app_production