Putting Ruby on Rails in Production on Debian with Virtualmin
If you have 512 MB of SWAP or below you need to increase the SWAP
$> sudo dd if=/dev/zero of=/swap bs=1M count=1024
$> sudo mkswap /swap
$> sudo swapon /swap
To make permanent, add this line to /etc/fstab
/swap swap swap sw 0 0
Install Passenger
$> gem install passenger
$> apt-get install apache2-threaded-dev libapr1-dev libaprutil1-dev
$> passenger-install-apache2-module
At the end it will display for you what to add to apache global conf file, in my case :
LoadModule passenger_module /usr/local/lib/ruby/gems/2.1.0/gems/passenger-5.0.30/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /usr/local/lib/ruby/gems/2.1.0/gems/passenger-5.0.30 PassengerDefaultRuby /usr/local/bin/ruby </IfModule>
Also put something similar to this in the virtual host Apache config :
DocumentRoot /home/cbuy/public_html/public RailsEnv production ErrorLog /var/log/virtualmin/community-buy.ca_error_log CustomLog /var/log/virtualmin/community-buy.ca_access_log combined ScriptAlias /cgi-bin/ /home/cbuy/cgi-bin/ ScriptAlias /awstats/ /home/cbuy/cgi-bin/ DirectoryIndex index.html index.htm index.php index.php4 index.php5 <Directory /home/cbuy/public_html/public> allow from all AllowOverride All Options FollowSymLinks -MultiViews Indexes </Directory>
Restart Apache
Troubleshooting
Generic error
Check where you can access the log file with
$> passenger-config --detect-apache2
"We're sorry, but something went wrong."
Edit Apache VirtualHost configuration to run development mode to see the error:
RailsEnv development
Then restart Apache.
"This web application process is being run as user 'nobody' and group 'nogroup' and must be able to access its application root directory"
chown your app dir so that your user can access it. If you use virtualmin that is your domain account user.
[2016-09-07 23:24:59] ERROR RuntimeError: Missing `secret_token` and `secret_key_base` for 'production' environment, set these values in `config/secrets.yml`
/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/application.rb:534:in `validate_secret_key_config!'
/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/application.rb:246:in `env_config'
/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/engine.rb:514:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/application.rb:165:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
/usr/local/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/usr/local/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/usr/local/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Problem: Only accessible on localhost
Solution: RAILS_ENV=production rails server -b 0.0.0.0
Problem
Forbidden
You don't have permission to access / on this server.
Solution
You might have uploaded files as root or such that is not accessible by the Apache/passenger.
chown -R <user>:<user> /home/<user>/public_html
Problem : It doesnt work
Solution
RAILS_ENV=production bundle exec rake assets:precompile
config.serve_static_assets = true
Recent Comments