# nginx Passenger Shell Logins && Associated Errors



## daBee (Aug 22, 2018)

Hi folks.  I hope this is the proper place for this thread.  

I have an nginx/Passenger/Sinatra situation.  I've sent over a website to my server, and nginx has no user set.  I've been told NOT to run it as `root`, but that's been highly disputed and it's never a clear answer.  So because of this, nginx runs as `nobody`.  Here's the environment:


```
PWD=/usr/local/www/mydomain
        HOME=/nonexistent
        SHELL=/usr/sbin/nologin
        LOGNAME=nobody
        USER=nobody
        PASSENGER_APP_ENV=production
        NODE_ENV=production
        WSGI_ENV=production
        RACK_ENV=production
        RAILS_ENV=production
        NODE_PATH=/usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/nodejs_supportlib
        PYTHONUNBUFFERED=1
        PASSENGER_SPAWN_WORK_DIR=/tmp/passenger.spawn.teejIw5vJy
        IN_PASSENGER=1
        SERVER_SOFTWARE=nginx/1.14.0 Phusion_Passenger/5.3.4
        PASSENGER_USE_FEEDBACK_FD=true
        PATH=/sbin:/bin:/usr/sbin:/usr/bin
        RC_PID=17467
```

Because `/usr/local/bin/bash` is not in the `$PATH`, it can't find `bash` and the process fails.  

So my questions:

1.  Am I supposed to run this as my admin user?  If not, how should nginx be run to get the proper login script?

2.  Can I change the `nobody` user login somehow to see `bash`?

3.  Is there any other question I should be asking?  

Appreciate the guidance.  Cheers


----------



## SirDice (Aug 22, 2018)

daBee said:


> Am I supposed to run this as my admin user?


Run what? And what's the "admin" user?



> If not, how should nginx be run to get the proper login script?


Why do you think nginx needs one?



daBee said:


> Is there any other question I should be asking?


Yes, what _exactly_ are you trying to do? You only posted some basic information but never actually mentioned what the problem is.

You may have been working on this problem for some time but keep in mind that we cannot see what you are doing.


----------



## daBee (Aug 22, 2018)

Run nginx.  I am the admin user.  I can run nginx as me.  Something tells me I'm not supposed to. 

This whole process needs to see bash, and it's not in the `nobody` user's path. 

The problem is that `nginx` can't see `bash`:


```
env: bash: No such file or directory
```

So this takes me back to a question I've had for some time.  Who do I run [cmd[nginx[/cmd] as?  That changes its login and associated path, which either sees `bash` or in this case, doesn't.


----------



## SirDice (Aug 22, 2018)

daBee said:


> Run nginx.


As root: `service nginx start`



> I am the admin user.


That concept doesn't really exists. There's root and there are user accounts.



> I can run nginx as me. Something tells me I'm not supposed to.


That's correct. As root: `service nginx start`



daBee said:


> This whole process needs to see bash, and it's not in the nobody user's path.


nginx certainly doesn't require it.

```
dice@armitage:~ % ps -aux | grep nginx
root       667   0.0  0.0   11544      0  -  IWs  -           0:00.00 nginx: master process /usr/local/sbin/nginx
www        668   0.0  0.0   13592    952  -  S    12Aug18     0:02.64 nginx: worker process (nginx)
www        669   0.0  0.0   13592    908  -  S    12Aug18     0:10.73 nginx: worker process (nginx)
www        670   0.0  0.0   13592    920  -  S    12Aug18     0:43.71 nginx: worker process (nginx)
www        671   0.0  0.0   13592   1984  -  S    12Aug18     0:57.81 nginx: worker process (nginx)
dice      6265   0.0  0.1    6660   2080  6  S+   16:07       0:00.00 grep nginx
dice@armitage:~ % whereis bash
bash: /usr/ports/shells/bash
dice@armitage:~ % bash
bash: Command not found.
dice@armitage:~ %
```

Note that, on FreeBSD nginx should run on the www user account, not nobody.



> I've been told NOT to run it as root, but that's been highly disputed and it's never a clear answer.


It's not disputed, only misunderstood. You should _start_ the service as root, because root is the _only_ account that can open ports below 1024. However, as soon as that port has been opened nginx _drops_ its privileges to a limited account, typically www. So it _runs_ on a limited account.


----------



## daBee (Aug 22, 2018)

nginx is running.  That's not the question.  It's currently running as `nobody`.  That's why it can't see bash.

I've been told many times not to run nginx as `root`.

What you posted is your user account's view of bash, which is obviously visible.  You're missing the point that nginx is indeed running, but as a user that can't see bash.

So I should enter `user: root` in the nginx.conf?  Seeing that I want port 80 and 443 open, I guess I have to. I'll post the results.


----------



## SirDice (Aug 22, 2018)

daBee said:


> I've been told many times not to run nginx as root.


And that is correct. However, you must _start_ it as root or else it will not be able to open port 80 (or any other port below 1024). And in your case nginx is _running_ as nobody.



daBee said:


> So I should enter  user: root in the nginx.conf?


This is exactly what you should *NEVER* do!


----------



## daBee (Aug 22, 2018)

OK, I am officially confused.  I thought those two things were the very same.  nginx.conf is what I know how to configure.


----------



## kpa (Aug 22, 2018)

The NGINX service starts as root because that's the only way to bind a socket on port 80, that port being restricted <1024 numbered port. After the creation of the listening socket has been done the service drops the root privileges and drops to the privileges of the user specified with the user: directive in nginx.conf and continues to run with the restricted privileges until the service is restarted.

Clear enough? These techniques are the cornerstone of service security and you better learn them well if you intend to run a web server that is fully exposed to the internet.


----------



## daBee (Aug 23, 2018)

Documentation is usually appropriate in cases like these.  The predictable anchor of the tech world.  Second it still doesn't answer the original question, now that it's taken a tangent.  Since there is no `user` in nginx.conf, that's what I'm asking.  Like I have said before, I've been told to run it as root, then not run it as root.  There is no definitive answer.  

It's very clear.  I've never contested it.  But also still not a solution.  Is that not understood?  I need a user in there that gets access to bash in its path.  Nobody seems to have an answer.


----------



## SirDice (Aug 23, 2018)

daBee said:


> Like I have said before, I've been told to run it as root, then not run it as root.


No, you simply don't understand the difference between _starting_ and _running_. You _start_ nginx as root with `service nginx start`. It _runs_ on whatever account is set in nginx.conf, which defaults to www on FreeBSD. I really can't make this difference any clearer. 


> There is no definitive answer.


There _is_ a definitive answer, you only fail to understand it.



daBee said:


> I need a user in there that gets access to bash in its path.


Why? Neither nginx or Passenger requires that. 



> Nobody seems to have an answer.


Because you still haven't told us _exactly_ what you are doing and keep referring back to nginx, which doesn't require bash at all. And so we're stuck on a XY problem.


----------



## kpa (Aug 23, 2018)

Whatever you do don't put user: root in your configuration file, that's a recipe for disaster if the server is exposed to the internet. As for the user needing to execute something on request, you could have already done some googling on your own:

https://stackoverflow.com/questions/22891148/nginx-how-to-run-a-shell-script-on-every-request

Don't take this too personally, we are trying to help you but at the same time we are trying to make you think of what you're doing. Nothing is more dangerous than someone who just blindly follows instructions off the net somewhere and doesn't think what the steps actually do.


----------



## daBee (Aug 23, 2018)

SirDice said:


> No, you simply don't understand the difference between _starting_ and _running_. You _start_ nginx as root with `service nginx start`. It _runs_ on whatever account is set in nginx.conf, which defaults to www on FreeBSD. I really can't make this difference any clearer.
> 
> There _is_ a definitive answer, you only fail to understand it.
> 
> ...



Yes, I do.  You have explained it clearly.  I'm not contesting what you're saying about starting/running.  It's the first time I've actually seen anything along those lines of root=>user.  

So here is the complete scenario.  I was thinking it was the user directive, but maybe it's not.  Hopefully this will explain why I was looking at the user, due to the current errors.  

FreeBSD + nginx + Passenger + Sinatra.  nginx has started and is running.  That's the way I get the error message.  The site isn't running, nginx is.  The site doesn't even start.  Here is the "What happened?":


```
The Phusion Passenger application server tried to start the web application through a Passenger-internal helper tool called the "wrapper". But Passenger was unable to execute that helper tool because it encountered an internal error.
The stdout/stderr output of the subprocess so far is:
env: bash: No such file or directory
```

Under the "How do I solve this?":


```
Unfortunately, Passenger does not know how to solve this problem. Please try troubleshooting the problem by studying the error message and the diagnostics reports. You can also consult the Passenger support resources for help.
```

That link points me to Stack Overflow.  Under "Detailed diagnostics", it says under the `Spawn subprocess`, it trips after `Basic init before exec`, `Setup environment` (1 and 2), on `Initialize language runtime`. 

There's another `subprocess` tab, which provides the following: 


```
Stdout and stderr output
env: bash: No such file or directory

User and group
uid=65534(nobody) gid=65534(nobody) groups=65534(nobody)

Ulimits
cpu time               (seconds, -t)  unlimited
file size           (512-blocks, -f)  unlimited
data seg size           (kbytes, -d)  33554432
stack size              (kbytes, -s)  524288
core file size      (512-blocks, -c)  unlimited
max memory size         (kbytes, -m)  unlimited
locked memory           (kbytes, -l)  131072
max user processes              (-u)  19270
open files                      (-n)  461538
virtual mem size        (kbytes, -v)  unlimited
swap limit              (kbytes, -w)  unlimited
socket buffer size       (bytes, -b)  unlimited
pseudo-terminals                (-p)  unlimited
kqueues                         (-k)  unlimited
umtx shared locks               (-o)  unlimited

Environment variables
PWD=/usr/local/www/pneb
HOME=/nonexistent
SHELL=/usr/sbin/nologin
LOGNAME=nobody
USER=nobody
PASSENGER_APP_ENV=production
NODE_ENV=production
WSGI_ENV=production
RACK_ENV=production
RAILS_ENV=production
NODE_PATH=/usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/nodejs_supportlib
PYTHONUNBUFFERED=1
PASSENGER_SPAWN_WORK_DIR=/tmp/passenger.spawn.hedtU73k1W
IN_PASSENGER=1
SERVER_SOFTWARE=nginx/1.14.0 Phusion_Passenger/5.3.4
PASSENGER_USE_FEEDBACK_FD=true
PATH=/sbin:/bin:/usr/sbin:/usr/bin
RC_PID=36315
```

So that's all I got.  *Something* is asking for bash.  Since it's almost universal, and it's not in the `$PATH`, I thought managing the `user` directive might make bash visible.


----------



## SirDice (Aug 23, 2018)

Please post your nginx.conf, I have a feeling you haven't configured the Passenger bit correctly.


----------



## daBee (Aug 23, 2018)

```
user www;
    worker_processes auto;

    error_log /var/log/nginx/error.log info;
    #pid                                            logs/nginx.pid;
    load_module /usr/local/libexec/nginx/ngx_http_passenger_module.so;

    events {
        worker_connections                          1024;
        }


    http {
        index                         index.html index.erb;
        access_log                 /var/log/nginx/access.log;
        passenger_root         /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4;      # passenger-config --ruby-command
        passenger_ruby         /home/rich/.rbenv/shims/ruby;
        passenger_friendly_error_pages on;

        server {
            listen                    80 default_server;
            server_name            pneb.local;
            include                    /usr/local/etc/nginx/mime.types;
            access_log            /var/log/nginx/access_pneb.log;
            error_log                /var/log/nginx/error_pneb.log error;
            error_page 404    /404.html;
            root                        /usr/local/www/pneb/public/;
            passenger_enabled                on;
            passenger_base_uri            /;

            location / {
                    autoindex                       off;
                    try_files                       $uri $uri/ =404;
#               index                           index.html;
                    }

            location = /favicon.ico { access_log off; log_not_found off; }
            location = /robots.txt { access_log off; log_not_found off; }
            sendfile                            off;
            }
        }
```


----------



## SirDice (Aug 23, 2018)

This:

```
passenger_ruby         /home/rich/.rbenv/shims/ruby;
```
Should be:

```
passenger_ruby         /usr/local/bin/ruby24;
```

If, withing the Passenger application, you still have problems with PATH try using passenger_env_var


----------



## daBee (Aug 23, 2018)

OK, why is that, given I'm using `rbenv`?


```
passenger-config was invoked through the following Ruby interpreter:
  Command: /usr/local/bin/ruby24
  Version: ruby 2.4.4p296 (2018-03-28 revision 63013) [amd64-freebsd11]
  To use in Apache: PassengerRuby /usr/local/bin/ruby24
  To use in Nginx : passenger_ruby /usr/local/bin/ruby24
  To use with Standalone: /usr/local/bin/ruby24 /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/bin/passenger start

The following Ruby interpreter was found first in $PATH:
  Command: /home/rich/.rbenv/shims/ruby
  Version: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-freebsd11.1]
  To use in Apache: PassengerRuby /home/rich/.rbenv/shims/ruby
  To use in Nginx : passenger_ruby /home/rich/.rbenv/shims/ruby
  To use with Standalone: /home/rich/.rbenv/shims/ruby /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/bin/passenger start
```


----------



## daBee (Aug 23, 2018)

Different `ruby`, throws an error:


```
cannot load such file -- bundler/setup (LoadError)
  /usr/local/lib/ruby/site_ruby/2.4/rubygems/core_ext/kernel_require.rb:59:in `require'
  /usr/local/lib/ruby/site_ruby/2.4/rubygems/core_ext/kernel_require.rb:59:in `require'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:363:in `activate_gem'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:221:in `block in run_load_path_setup_code'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:527:in `running_bundler'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:220:in `run_load_path_setup_code'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:91:in `preload_app'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:189:in `block in <module:App>'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:380:in `run_block_and_record_step_progress'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:188:in `<module:App>'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
  /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:29:in `<main>'
```

Edit:  I should add that it got past the "Preparation work" as reported before.  This is now a `Web application` issue.


----------



## SirDice (Aug 23, 2018)

You will need to have the appropriate rubygem-* ports/packages installed. It looks like your application is missing one or more.


----------



## daBee (Aug 23, 2018)

Not sure what could be missing.  


```
ruby-2.4.4_2,1                 Object-oriented interpreted scripting language
ruby-build-20180601            Compile and install different ruby versions
ruby24-gems-2.7.6              Package management framework for the Ruby language
rubygem-passenger-apache-5.3.4 Modules for running Ruby on Rails and Rack applications
rubygem-rack-2.0.5,3           Rack, a Ruby Webserver Interface
rubygem-rack16-1.6.10          Rack, a Ruby Webserver Interface
rubygem-rake-12.3.1            Ruby Make
```


----------



## SirDice (Aug 23, 2018)

Which gems you need is going to depend on your application. Also note that you have rubygem-passenger-apache installed, which is the Passenger plugin for Apache. For nginx it should be rubygem-passenger-nginx.


----------



## daBee (Aug 23, 2018)

Those gems are installed in the .rbenv gemset.  You've said the ruby I need is ruby24.  Also, it doesn't seem rubygem-passenger installs rubygem-passenger-nginx:


```
[Thu Aug 23 09:04:54 rich@neb /usr/ports] make search key=rubygem-passenger-nginx
Port:    rubygem-passenger-nginx-5.3.4
Path:    /usr/ports/www/rubygem-passenger
Info:    Modules for running Ruby on Rails and Rack applications
Maint:    osa@FreeBSD.org
B-deps:    apr-1.6.3.1.6.1_1 ca_root_nss-3.38 curl-7.61.0_1 db5-5.3.28_7 expat-2.2.5 gdbm-1.13_1 gettext-runtime-0.19.8.1_1 indexinfo-0.3.1 libedit-3.1.20170329_2,1 libffi-3.2.1_2 libiconv-1.14_11 libnghttp2-1.32.0 libunwind-20170615 libuv-1.23.0 libyaml-0.1.6_2 ncurses-6.1.20180728 readline-7.0.3_1 ruby-2.4.4_2,1 ruby24-gems-2.7.7 rubygem-rack-2.0.5,3 rubygem-rake-12.3.1
R-deps:    apr-1.6.3.1.6.1_1 ca_root_nss-3.38 curl-7.61.0_1 db5-5.3.28_7 expat-2.2.5 gdbm-1.13_1 gettext-runtime-0.19.8.1_1 indexinfo-0.3.1 libedit-3.1.20170329_2,1 libffi-3.2.1_2 libiconv-1.14_11 libnghttp2-1.32.0 libunwind-20170615 libuv-1.23.0 libyaml-0.1.6_2 ncurses-6.1.20180728 readline-7.0.3_1 ruby-2.4.4_2,1 ruby24-gems-2.7.7 rubygem-rack-2.0.5,3 rubygem-rake-12.3.1
WWW:    http://www.phusionpassenger.com/
```

Same `pkg info` post re-installation of this pkg.  The commits say `nginx` is indeed updated, however I can't see it.  

https://www.freshports.org/www/rubygem-passenger/


----------



## SirDice (Aug 23, 2018)

The rubygem-passenger uses FLAVOR to switch between Apache and nginx. The resulting package is called rubygem-passenger-apache or rubygem-passenger-nginx depending on which FLAVOR you chose. The list you posted in #19 shows rubygem-passenger-apache.


----------



## daBee (Aug 23, 2018)

OK, updated using `sudo make FLAVOR=nginx install clean`:


```
ruby-2.4.4_2,1                 Object-oriented interpreted scripting language
ruby-build-20180601            Compile and install different ruby versions
ruby24-gems-2.7.6              Package management framework for the Ruby language
rubygem-passenger-nginx-5.3.4  Modules for running Ruby on Rails and Rack applications
rubygem-rack-2.0.5,3           Rack, a Ruby Webserver Interface
rubygem-rack16-1.6.10          Rack, a Ruby Webserver Interface
rubygem-rake-12.3.1            Ruby Make
```

Still the same error, seeing that it's now requiring `ruby24` instead of my `rbenv ruby`:

`cannot load such file -- bundler/setup (LoadError)`


----------



## SirDice (Aug 23, 2018)

I suspect this is a Ruby on Rails application? Or something else? Rails applications would need www/rubygem-rails4 or www/rubygem-rails5 too.

Just to give you an example of a Rails5 application:

```
dice@wintermute:~ % pkg version -vR | grep rubygem
rubygem-actioncable5-5.1.6         =   up-to-date with remote
rubygem-actionmailer5-5.1.6        =   up-to-date with remote
rubygem-actionpack5-5.1.6          =   up-to-date with remote
rubygem-actionview5-5.1.6          =   up-to-date with remote
rubygem-activejob5-5.1.6           =   up-to-date with remote
rubygem-activemodel5-5.1.6         =   up-to-date with remote
rubygem-activerecord5-5.1.6        =   up-to-date with remote
rubygem-activesupport5-5.1.6       =   up-to-date with remote
rubygem-addressable-2.5.2          =   up-to-date with remote
rubygem-arel8-8.0.0,1              =   up-to-date with remote
rubygem-bindex-0.5.0               =   up-to-date with remote
rubygem-builder-3.2.3              =   up-to-date with remote
rubygem-bundler-1.16.3             =   up-to-date with remote
rubygem-byebug-10.0.2              =   up-to-date with remote
rubygem-capybara-2.18.0            =   up-to-date with remote
rubygem-childprocess-0.9.0         =   up-to-date with remote
rubygem-coffee-rails-rails5-4.2.2  =   up-to-date with remote
rubygem-coffee-script-2.4.1        =   up-to-date with remote
rubygem-coffee-script-source-1.12.2 =   up-to-date with remote
rubygem-colored-1.2                =   up-to-date with remote
rubygem-concurrent-ruby-1.0.5      =   up-to-date with remote
rubygem-crass-1.0.4                =   up-to-date with remote
rubygem-cri-2.11.0                 =   up-to-date with remote
rubygem-erubi-1.7.1                =   up-to-date with remote
rubygem-execjs-2.7.0               =   up-to-date with remote
rubygem-faraday-0.15.2             =   up-to-date with remote
rubygem-faraday_middleware-0.12.2  =   up-to-date with remote
rubygem-fast_gettext-1.7.0         =   up-to-date with remote
rubygem-ffi-1.9.25                 =   up-to-date with remote
rubygem-gettext-3.2.6              =   up-to-date with remote
rubygem-gettext-setup-0.30         =   up-to-date with remote
rubygem-globalid-rails5-0.4.1      =   up-to-date with remote
rubygem-hiera-3.4.3                =   up-to-date with remote
rubygem-hocon-1.2.5                =   up-to-date with remote
rubygem-i18n-1.1.0,2               =   up-to-date with remote
rubygem-jbuilder-rails5-2.7.0      =   up-to-date with remote
rubygem-jquery-rails-rails5-4.3.3  =   up-to-date with remote
rubygem-json_pure-2.1.0            =   up-to-date with remote
rubygem-locale-2.1.2               =   up-to-date with remote
rubygem-log4r-1.1.10               =   up-to-date with remote
rubygem-loofah-2.2.2               =   up-to-date with remote
rubygem-mail-2.7.0,2               =   up-to-date with remote
rubygem-method_source-0.9.0        =   up-to-date with remote
rubygem-mini_mime-1.0.0            =   up-to-date with remote
rubygem-minitar-0.6.1              =   up-to-date with remote
rubygem-minitest-5.11.3            =   up-to-date with remote
rubygem-multi_json-1.13.1          =   up-to-date with remote
rubygem-multipart-post-2.0.0       =   up-to-date with remote
rubygem-nio4r-2.3.1                =   up-to-date with remote
rubygem-nokogiri-1.8.2             =   up-to-date with remote
rubygem-passenger-apache-5.3.4     =   up-to-date with remote
rubygem-pg-1.0.0                   =   up-to-date with remote
rubygem-pkg-config-1.3.1           =   up-to-date with remote
rubygem-public_suffix-3.0.2_1      =   up-to-date with remote
rubygem-puma-3.12.0                =   up-to-date with remote
rubygem-puppet-lint-2.3.6          =   up-to-date with remote
rubygem-puppet_forge-2.2.9_1       =   up-to-date with remote
rubygem-r10k-2.6.2_1               =   up-to-date with remote
rubygem-rack-2.0.5,3               =   up-to-date with remote
rubygem-rack-test-0.8.3            =   up-to-date with remote
rubygem-rack16-1.6.10              =   up-to-date with remote
rubygem-rails-deprecated_sanitizer-rails5-1.0.3 =   up-to-date with remote
rubygem-rails-dom-testing-rails5-2.0.3 =   up-to-date with remote
rubygem-rails-html-sanitizer-1.0.4 =   up-to-date with remote
rubygem-rails5-5.1.6               =   up-to-date with remote
rubygem-railties5-5.1.6            =   up-to-date with remote
rubygem-rake-12.3.1                =   up-to-date with remote
rubygem-rb-fsevent-0.10.3          =   up-to-date with remote
rubygem-rb-inotify-0.9.10          =   up-to-date with remote
rubygem-ruby-augeas-0.5.0_2        =   up-to-date with remote
rubygem-rubyzip-1.2.1              =   up-to-date with remote
rubygem-sass-3.5.7                 =   up-to-date with remote
rubygem-sass-listen-4.0.0          =   up-to-date with remote
rubygem-sass-rails-rails5-5.0.7    =   up-to-date with remote
rubygem-selenium-webdriver-3.14.0  =   up-to-date with remote
rubygem-semantic_puppet-1.0.2      =   up-to-date with remote
rubygem-spring-rails5-2.0.2        =   up-to-date with remote
rubygem-sprockets-rails-rails5-3.2.1 =   up-to-date with remote
rubygem-sprockets3-3.7.2           =   up-to-date with remote
rubygem-sqlite3-1.3.13             =   up-to-date with remote
rubygem-text-1.3.1                 =   up-to-date with remote
rubygem-thor-0.20.0                =   up-to-date with remote
rubygem-thread_safe-0.3.6          =   up-to-date with remote
rubygem-tilt-2.0.8                 =   up-to-date with remote
rubygem-turbolinks-rails5-5.1.1    =   up-to-date with remote
rubygem-turbolinks-source-5.1.0    =   up-to-date with remote
rubygem-tzinfo-1.2.5               =   up-to-date with remote
rubygem-uglifier-4.1.18            =   up-to-date with remote
rubygem-web-console-3.6.2          =   up-to-date with remote
rubygem-websocket-driver-0.7.0     =   up-to-date with remote
rubygem-websocket-extensions-0.1.3 =   up-to-date with remote
rubygem-xpath-3.1.0                =   up-to-date with remote
```
The only difference is that I use Apache.


----------



## daBee (Aug 23, 2018)

Just had a look at the gems inside `ruby24`.  The Gemfile relies on the `rbenv` version.


```
[Thu Aug 23 12:16:25 rich@neb /usr/local/lib/ruby/gems/2.4/gems] ll
total 52
drwxr-xr-x   6 root  wheel   7 Aug 23 12:04 .
drwxr-xr-x   8 root  wheel   8 Aug 20 14:59 ..
lrwxr-xr-x   1 root  wheel  15 Aug 23 12:02 passenger -> passenger-5.3.4
drwxr-xr-x  11 root  wheel  23 Aug 23 12:04 passenger-5.3.4
drwxr-xr-x   7 root  wheel  14 Aug 20 14:59 rack-1.6.10
drwxr-xr-x   7 root  wheel  13 Aug 21 17:32 rack-2.0.5
drwxr-xr-x   6 root  wheel  14 Aug 20 14:59 rake-12.3.1
```


----------



## daBee (Aug 23, 2018)

SirDice said:


> I suspect this is a Ruby on Rails application? Or something else?



Sinatra.  Looking in the ports, it seems I have to install ports AND gems for Sinatra to run properly?


----------



## SirDice (Aug 23, 2018)

Use www/rubygem-sinatra, that will install everything that's required.


----------



## daBee (Aug 24, 2018)

Ya it's still tripping up on the `ruby` versions.


```
passenger_ruby                          /usr/local/bin/ruby24;
#        passenger_ruby                          /home/rich/.rbenv/shims/ruby;
```

The second one is the `ruby` I want to be using, the first is the `ruby` you said I should be using.  It isn't managed by `rbenv` at all, so it has no gems nor `Gemfile`.  Is this an issue with this new `FLAVORS` layer?  It's taken away the ability to provide a `Gemfile`, or a chosen version for that matter.


```
Error: The application encountered the following error: cannot load such file -- bundler/setup (LoadError)
    /usr/local/lib/ruby/site_ruby/2.4/rubygems/core_ext/kernel_require.rb:59:in `require'
    /usr/local/lib/ruby/site_ruby/2.4/rubygems/core_ext/kernel_require.rb:59:in `require'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:363:in `activate_gem'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:221:in `block in run_load_path_setup_code'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:527:in `running_bundler'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:220:in `run_load_path_setup_code'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:91:in `preload_app'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:189:in `block in <module:App>'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:380:in `run_block_and_record_step_progress'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:188:in `<module:App>'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
    /usr/local/lib/ruby/gems/2.4/gems/passenger-5.3.4/src/helper-scripts/rack-preloader.rb:29:in `<main>'
```


----------



## SirDice (Aug 24, 2018)

I've found it best to use Gems provided by ports/packages. Using `rbenv` might be a quick and easy solution for a local install but if you have to push it out to a bunch of webservers it'll quickly become an unmanageable mess.

Looking at your previous posts, if you really want to use Ruby 2.5 instead of 2.4 you can switch the default Ruby version by adding to /etc/make.conf:

```
DEFAULT_VERSIONS+= ruby=2.5
```
But you will have to (re)build all things Ruby from ports.


----------



## daBee (Aug 24, 2018)

So even bundler should be discarded.  So how can I add Gems, given I have a list of them?  It's strange that this Passenger install has taken control of a ruby installation.  Seems things have changed in the past year.


----------



## SirDice (Aug 28, 2018)

There are a lot of rubygem-* ports.


----------



## daBee (Aug 28, 2018)

So it was nginx that was calling for bash.  I was instructed to shove that path inside the nginx startup.  

`PATH=$PATH:/usr/local/bin` inside /usr/local/etc/rc.d/nginx did the trick.  But that revealed I have two Passengers. 


```
You are currently validating against Phusion Passenger 5.3.4, located in:

     /usr/local/lib/ruby/gems/2.5/gems/passenger-5.3.4/bin/passenger

   Besides this Passenger installation, the following other
   Passenger installations have also been detected:

     /usr/local/bin/passenger

   Please uninstall these other Passenger installations to avoid
   confusion or conflicts.
```

The latter is apparently the one I need to delete, but I can't tell how it got there.  `pkg info` only shows the rubygem-passenger-nginx port installed.

`ruby-2.5.1_3,1                 Object-oriented interpreted scripting language
ruby-build-20180601            Compile and install different ruby versions
ruby25-gems-2.7.7              Package management framework for the Ruby language
rubygem-passenger-nginx-5.3.4  Modules for running Ruby on Rails and Rack applications
rubygem-rack-2.0.5,3           Rack, a Ruby Webserver Interface
rubygem-rake-12.3.1            Ruby Make`

Should I rename that latter Passenger?


----------



## daBee (Aug 28, 2018)

I'll start a new thread.


----------

