Question

Ruby on Rails and Solr installation is not working on Ubuntu 16.04

I installed and deployed Ruby on Rails 3.2.13 following these tutorials on Ubuntu 16.04: Tutorial. Tutorial I installed Solr with Jetty server following this tutorial: Tutorial Everything is working good when I do not use Solr, connection with mysql database is working. Solr is running when I go to http://MY_IP:8983/solr. My application connection with Solr is not working:

Connecting to database specified by database.yml
Started GET "/" for 62.65.227.251 at 2017-09-07 12:27:05 +0000
Processing by CarsController#index as HTML
Completed 500 Internal Server Error in 561ms

RSolr::Error::Http (RSolr::Error::Http - 400 Bad Request
Error: {'responseHeader'=>{'status'=>400,'QTime'=>12,'params'=>{'q'=>'*:*','start'=>'0','fq'=>['type:Vehicle','type_id_i:1','advert_id_i:[* TO *]','activated_b:true'],'sort'=>'popularity_i desc','rows'=>'12','wt'=>'ruby'}},'error'=>{'msg'=>'undefined field type','code'=>400}}

URI: http://146.185.140.73:8983/solr/select?wt=ruby
Request Headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}
Request Data: "fq=type%3AVehicle&fq=type_id_i%3A1&fq=advert_id_i%3A%5B*+TO+*%5D&fq=activated_b%3Atrue&sort=popularity_i+desc&start=0&rows=12&q=*%3A*"

I need to run rake sunspot:solr:reindex RAILS_EBV=production in production environment to make my sunspot solr installation working. Every time I got the following:

rake aborted!
Mysql2::Error: Access denied for user 'root'@'localhost' (using password: NO)
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `connect'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `initialize'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:308:in `clear_cache!'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activerecord-3.2.13/lib/active_record/railtie.rb:104:in `block (2 levels) in <class:Railtie>'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:418:in `_run__740716662354118830__prepare__1984631507565864982__callbacks'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/sergei/webauto/config/environment.rb:5:in `<top (required)>'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.13/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/bin/ruby_executable_hooks:15:in `eval'
/home/sergei/.rvm/gems/ruby-2.0.0-p648/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => sunspot:solr:reindex => sunspot:reindex => environment
(See full trace by running task with --trace)

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

The key part of that error message is:

Mysql2::Error: Access denied for user 'root'@'localhost' (using password: NO)

This say that Rails is unable to connect to the MySQL database. As you are calling rake with RAILS_EBV=production, make sure that the database connection information for production is configured in config/database.yml. Check out the “Configure Database Connection” section of this tutorial for more info.