How to use Byebug with a remote process (e.g., pow)
Joseph's answer was good but confusing in some small ways. He places the starting of the byebug server in config/environments/development.rb
, when it would be better in an initializer. Additionally the exporting of the environment variable go in .powenv
or .powrc
. This is how I got it to work.
In your gemfile:
gem 'byebug'
On the command line:
bundle install
If you are using Pow, add the following to .powenv
:
export BYEBUGPORT=3001
If you are using other frameworks (e.g. just foreman
), you may have to modify .env
instead.
In config/initializers/byebug.rb
if Rails.env.development? and ENV['BYEBUGPORT'] require 'byebug/core' Byebug.start_server 'localhost', ENV['BYEBUGPORT'].to_iend
And finally on the command line:
touch tmp/restart.txt
Once you go to your pow site, the byebug server should be started. On the command line you can now do:
[bundle exec] byebug -R localhost:3001
I had to piece together information from several different sources to accomplish the above, so I thought I'd include a consolidated guide here for convenience:
- https://github.com/deivid-rodriguez/byebug/pull/29,
- https://github.com/deivid-rodriguez/byebug/pull/36,
- https://github.com/deivid-rodriguez/byebug/issues/31
- http://mines.mouldwarp.com/2012/04/pow-guard-and-rdebug-staying-in-web-app.html
Here are the steps:
In config/environments/development.rb, add:
require 'byebug'#set in your .powconfigif ENV['RUBY_DEBUG_PORT'] Byebug.start_server 'localhost', ENV['RUBY_DEBUG_PORT'].to_ielse Byebug.start_server 'localhost'end
Restart Pow and visit yourapp.dev
Run the following:
[bundle exec] byebug -R localhost:<port_you_defined_in_pow_config>
You should see a successful connection to the remote instance.
In your code
remote_byebug
Invoke your code (e.g., by refreshing the page). This will spin up a local byebug server on port 8989. Your code will then 'hang' waiting for a client connection.
Connect to it via the terminal:
byebug -R localhost:8989
Manually configuring the server is no longer necessary as of https://github.com/deivid-rodriguez/byebug/pull/406/files