Background:
I have my web app running on unbuntu 18.04 + Apache & Passenger. I am using ruby 2.5 and rails 5.2. Right now the the project is running in development env.
Not sure if more info is needed so please ask. Thanks for anyone who can help. I am considering switching to NGINX and using ruby gem cap.
Question:
I am trying to configure Passenger to run my rails app in Production, but I can only make it run in development env. When I try to make changes for production env, it just stops working...
after changes I am running
sudo apache2ctl restart
sudo service apache2 restart
My .conf file
<VirtualHost *:80>
ServerName dev1.example.net
#ServerAlias dev1.example.net
#ServerAdmin webmaster#localhost
DocumentRoot /home/augustus/dev/xxx/public
RailsEnv development
PassengerRuby /home/augustus/.rbenv/versions/2.5.0/bin/ruby
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/augustus/dev/xxx/public >
# Allow from all
AllowOverride all
Options -MultiViews
# Options FollowSymLinks
Require all granted
</Directory>
:What I have tried
I am setting the RailEnv to 'production'
I have also reinstalled the repo completely
I read over other stack overflow post's about this. I am not having issues getting it running, but just putting it in production. When I visit the webpage (www.example.com), it gives me the "we're sorry, but something went wrong"..
the most helpful link was
OS X: Development & Production Deployment for RoR with Apache and Passenger
&& passenger dox
https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/digital_ocean/apache/oss/bionic/deploy_app.html
Related
I’m using Apache 2.4 and Rails 5 on Mac Sierra. I did
brew install passenger
and then I created this file
localhost:apache2 davea$ cat /etc/apache2/other/passenger.conf
LoadModule passenger_module /usr/local/opt/passenger/libexec/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/opt/passenger/libexec/src/ruby_supportlib/phusion_passenger/locations.ini
PassengerDefaultRuby /usr/bin/ruby
But after restarting Apache
sudo apachectl restart
and then starting my Rails server (which runs on port 3000), I visit the local url on my machine
https://mylocalurl.com/
and I’m still seeing my Apache page, not my Rails page. What else am I missing that would connect Apache to Rails?
You need to configure a virtualhost in apache and then Passenger will start your rails app for you (you don't start your rails server when using apache integration).
At a minimum you need to point the apache virtualhost's document root to the public directory in your rails app.
<VirtualHost *:80>
ServerName yourserver.com
DocumentRoot /path/to/myapp/public
<Directory /path/to/myapp/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
Further reading:
https://www.phusionpassenger.com/library/config/apache/intro.html
https://www.phusionpassenger.com/library/config/apache/reference/
I would like to deploy a Ruby on Rails application on the web, and for that matter I have used/deployed the following tools:
Capistrano, to deploy the app files to the target location
The Phusion Passenger module for Apache
I have enabled the Passenger module through sudo a2enmod passenger. I have also installed the passenger gem through the gem installer, and added it to the Gemfile of my rails app.
I have then created an Apache virtual host for the app 'myapp'.
myapp.conf
Alias /myapp /var/www/myapp/current/public
<VirtualHost *:80>
DocumentRoot /var/www/myapp/current/public
SetEnv SECRET_KEY_BASE 592da***************************************
<Directory /var/www/myapp/current/public>
PassengerEnabled on
PassengerResolveSymlinksInDocumentRoot on
PassengerAppRoot /var/www/myapp/current
PassengerAppType rack
PassengerStartupFile config.ru
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
The virtual host work, but when I access the URL in a web browser, it shows the files index in /var/www/myapp/current/public instead of the actual app. The reason for this seems to be that passenger is not started, but I can't figure out why. I have tried to tweak the myapp.conf file to help apache and passenger detect the app, but without success.
Could anyone help me fix this? Thanks in advance.
Additional info: the app is deployed on a Raspberry Pi 3 with Raspbian Jessie as OS.
Try this .This is for sub uri deployment.Error is because PassengerRuby path has not been mentioned. Also go through this link
https://www.phusionpassenger.com/library/deploy/apache/deploy/ruby/.
Alias /myapp /var/www/myapp/current/public
<VirtualHost *:80>
SetEnv SECRET_KEY_BASE 592da***************************************
PassengerRuby /path-to-ruby /* replace this with your ruby path
<Location /myapp>
PassengerBaseURI /myapp
PassengerAppRoot /var/www/myapp/current
PassengerEnabled on
</Location>
<Directory /var/www/myapp/current/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
I am using the Google Cloud Engine ruby stack, which uses RVM and Passenger on Debian 7. After following the Passenger configuration manual, I am only seeing a directory of the app's files when I navigate to the server root.
Here's the /etc/apache2/apache2.conf
<VirtualHost *:80>
ServerName http://130.211.149.208
DocumentRoot /var/www/myapp
<Directory /var/www/myapp>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
</VirtualHost>
Figured it out. The problem was /var/www/myapp should be /var/www/myapp/public
I've looked all google results, and non of them helps:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /var/www/site/example.com/current/public
<Directory /var/www/site/example.com/current/public>
Options -Multiviews
Allow from all
</Directory>
</VirtualHost>
and as you can see, the app is deployed into:
/var/www/site/example.com/current/public
though Capistrano, where my app don't have an index page, but rails suppose to use the root I setup in the route file instead
But when I enter the url of, it only shows the public directory with its
As for the logs:
NO log in the rails log directory
No log for all the apache
I later found the issue is I shouldn't sudo passenger-install-apache2-module, I should rvmsudo passenger-install-apache2-module
It is annoying since there is no hint from either passenger or apache telling that the passenger seems wasn't running, even the apache config has included passegner module and restart ok
Hi I'm running Passenger/mongo/Rails 3.2 (no activerecord or mysql) with a Capistrano deploy script.
I'm trying to get my app to run in production mode on my linux server.
In my apache config file i have the following...
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example.com/current/public
ErrorLog /srv/www/example.com/current/log/error.log
CustomLog /srv/www/example.com/current/log/access.log combined
PassengerDefaultUser www-data
<Directory /srv/www/test.example.com/current/public>
AllowOverride all
Options -MultiViews
</Directory>
RailsEnv production
</VirtualHost>
EDIT: In my environment.rb file I no longer have the following...
RAILS_ENV="production"
RAILS_ENV.freeze
In my Capistrano deploy.rb I have the following...
set :rails_env, "production"
EDIT: But when I deploy via capistrano or do a sudo service apache2 restart. It says apache restarts but the server never comes up when i access the url.
Seems like an unusual problem. I have deployed many applications with similar or identical stacks without incident.
Try this:
Please remove any custom code (related to this issue) from your environment.rb file.
Remove the rails_env variable from your deploy file
Make sure to leave "RailsEnv production" inside your Apache virtual host config
SSH into the server and restart Apache manually
I will check in the morning, but I believe that restart task for mod_rails is no good, I think I have hooked in a manual Apache restart after the deploy. Not sure why, think it has something to do with the fact that "current_path" is only a symlink or perhaps "PassengerMinInstances" is preventing a new passenger thread from spawning with the modified code. All speculation.
For Rails 3.x apps that come with a config.ru file you should be using the RackEnv parameter in your VirtualHost configuration:
RackEnv production
You really should not be force-setting RAILS_ENV inside of environment.rb. That's bound to cause all kinds of problems.
On my production environment (application name conflux), I have RailsEnv production inside the tag.
<Directory /var/www/conflux/current/public>
RailsEnv production
PassengerAppRoot /var/www/conflux/current
Allow from all
#Turn off MultiViews, which is incompatable with Passenger.
Options -MultiViews
</Directory>
I agree not to set RAILS_ENV inside environment.rb. For one thing, RAILS_ENV is a constant, and I think if it is used (and before Rails 3) it is set before entering the environments. So, it may already be set, and as a constant, will not change.
I also am not sure that RAILS_ENV is used in Rails 3 any more.
Have you tried pre-compiling the assets, Once precompiled, the assets are placed in public folder and then only you will be able to run it successfully in production mode. try this rake assets:precompile if it is jruby then jruby -S rake assets:precompile.
If the server is in production mode, asset pipeline and asset server needs to be set to "TRUE" in production.rb
I assume that this is the permissions settings for your directory
<Directory /srv/www/**test.example.com/**current/public>
AllowOverride all
Options -MultiViews
</Directory>
In which case, wouldn't this have to be the same as your document root setting
DocumentRoot /srv/www/**example.com**/current/public
Not that familiar with Capistrano or apache, but i've always thought these would need to be the same.