{"id":558,"date":"2015-03-27T23:02:16","date_gmt":"2015-03-27T21:02:16","guid":{"rendered":"https:\/\/kari.world.ikari.fi\/?p=558"},"modified":"2015-03-27T23:02:16","modified_gmt":"2015-03-27T21:02:16","slug":"cameras-action-setup-passenger-to-apache2","status":"publish","type":"post","link":"https:\/\/kari.world.ikari.fi\/?p=558","title":{"rendered":"Cameras, action: setup passenger to apache2"},"content":{"rendered":"<p>Our guidance sources shall be today:<\/p>\n<ul>\n<li><a href=\"http:\/\/software.opensuse.org\/download.html?project=OBS%3AServer%3AUnstable&#038;package=rubygem-passenger\">Install package OBS:Server:Unstable \/ rubygem-passenger<\/a><\/li>\n<li><a href=\"https:\/\/www.phusionpassenger.com\/documentation\/Users%20guide%20Apache.html\">Phusion Passenger users guide, Apache version<\/a><\/li>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-setup-a-rails-4-app-with-apache-and-passenger-on-centos-6\">How To Setup a Rails 4 App With Apache and Passenger on CentOS 6<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/6162196\/setting-up-rails-app-on-apache-with-passenger-rails-doesnt-seem-to-load\">Setting up Rails app on Apache with passenger &#8211; Rails doesn&#8217;t seem to load<\/a><\/li>\n<\/ul>\n<p>Now, when having all interesting source material in hand lets proceed with install<\/p>\n<p><strong>Step 1<\/strong>: Install passenger and various relevant development libraries<\/p>\n<pre>\nzypper addrepo http:\/\/download.opensuse.org\/repositories\/OBS:Server:Unstable\/openSUSE_13.2\/OBS:Server:Unstable.repo\nzypper refresh\nzypper install rubygem-passenger\nzypper install apache2-devel\nzypper install curl-devel\nzypper install ruby-devel\nzypper install pcre-devel\n<\/pre>\n<p><strong>Step 2<\/strong>: Configure passenger<\/p>\n<pre class=\"lang:bash decode:true \" >\npassenger-install-apache2-module\n...\n<\/pre>\n<p>This will compile bunch of stuff and eventually (hopefully give following info)<\/p>\n<pre>\n--------------------------------------------\nAlmost there!\n\nPlease edit your Apache configuration file, and add these lines:\n\n   LoadModule passenger_module \/usr\/lib64\/ruby\/gems\/2.1.0\/gems\/passenger-4.0.53\/buildout\/apache2\/mod_passenger.so\n   <IfModule mod_passenger.c>\n     PassengerRoot \/usr\/lib64\/ruby\/gems\/2.1.0\/gems\/passenger-4.0.53\n     PassengerDefaultRuby \/usr\/bin\/ruby.ruby2.1\n   <\/IfModule>\n\nAfter you restart Apache, you are ready to deploy any number of web\napplications on Apache, with a minimum amount of configuration!\n\nPress ENTER to continue.\n\n--------------------------------------------\n\nDeploying a web application: an example\n\nSuppose you have a web application in \/somewhere. Add a virtual host to your\nApache configuration file and set its DocumentRoot to \/somewhere\/public:\n\n   <VirtualHost *:80>\n      ServerName www.yourhost.com\n      # !!! Be sure to point DocumentRoot to 'public'!\n      DocumentRoot \/somewhere\/public\n      <Directory \/somewhere\/public>\n         # This relaxes Apache security settings.\n         AllowOverride all\n         # MultiViews must be turned off.\n         Options -MultiViews\n         # Uncomment this if you're on Apache >= 2.4:\n         #Require all granted\n      <\/Directory>\n   <\/VirtualHost>\n\nAnd that's it! You may also want to check the Users Guide for security and\noptimization tips, troubleshooting and other useful information:\n\n  \/usr\/lib64\/ruby\/gems\/2.1.0\/gems\/passenger-4.0.53\/doc\/Users guide Apache.html\n  https:\/\/www.phusionpassenger.com\/documentation\/Users%20guide%20Apache.html\n\nEnjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)\nhttps:\/\/www.phusionpassenger.com\n\nPhusion Passenger is a trademark of Hongli Lai & Ninh Bui.\n<\/pre>\n<p>Lets ignore for a while instructions about apache2 configuration, and see what got so far.<\/p>\n<p><strong>Step 3<\/strong>: Try if apache2 still starts<\/p>\n<pre>\n# need to create this dir; it's seemingly not autocreated\nmkdir \/run\/passenger\nservice apache2 restart\nservice apache2 status\nless \/var\/log\/apache2\/error_log\n<\/pre>\n<p>Okey, at this point error_log contains various errors from passenger but apache2 itself is still running (and luckily so, since otherwise writing this blog post would become challenging since we are doing changes in server hosting this blog).<\/p>\n<p><strong>Step 4<\/strong>: Setup new virtual host config<\/p>\n<pre>\nemacs \/etc\/apache2\/vhosts.d\/host.kari.dy.fi.conf\n<\/pre>\n<p>\/etc\/apache2\/vhosts.d\/host.kari.dy.fi.conf<\/p>\n<pre>\n<VirtualHost *:80>\n  ServerName host.kari.dy.fi\n  # !!! Be sure to point DocumentRoot to 'public'!\n  DocumentRoot \/home\/www\/virtual\/host.kari.dy.fi\/public\n\n  # if not specified, the global error log is used\n  ErrorLog \/var\/log\/apache2\/host.kari.dy.fi-error_log\n  CustomLog \/var\/log\/apache2\/host.kari.dy.fi-access_log combined\n\n  <Directory \/home\/www\/virtual\/host.kari.dy.fi\/public>\n    # This relaxes Apache security settings.\n    AllowOverride all\n    # MultiViews must be turned off.\n    Options -MultiViews\n    # Uncomment this if you're on Apache >= 2.4:\n    Require all granted\n  <\/Directory>\n<\/VirtualHost>\n<\/pre>\n<p><strong>Step 5<\/strong>: Setup virtual server<\/p>\n<pre>\ncd \/home\/www\/virtual\ngit clone https:\/\/github.com\/kikonen\/host host.kari.dy.fi\ncd host.kari.dy.fi\nbundle\n<\/pre>\n<p>okey&#8230; lets cross fingers and restart apache2 yet&#8217;another time.<\/p>\n<p><strong>Step 6<\/strong>: Try if apache2 still starts<\/p>\n<pre>\nservice apache2 restart\nservice apache2 status\nless \/var\/log\/apache2\/error_log\nls -l \/var\/log\/apache2\/host.kari.dy.fi-*\n<\/pre>\n<p>If we are lucky, then passenger is starting up, and new virtual host is also configured up.<\/p>\n<p><strong>Step 7<\/strong>: Lets try it out in web browser<\/p>\n<pre>\nhttp:\/\/host.kari.dy.fi\/\n<\/pre>\n<p>Okey, not good, getting in web browser<\/p>\n<pre>\ncannot load such file -- phusion_passenger (LoadError)\n  \/usr\/lib64\/ruby\/2.1.0\/rubygems\/core_ext\/kernel_require.rb:55:in `require'\n  \/usr\/lib64\/ruby\/2.1.0\/rubygems\/core_ext\/kernel_require.rb:55:in `require'\n  \/usr\/lib64\/passenger\/4.0.53\/\/helper-scripts\/rack-preloader.rb:73:in `init_passenger'\n  \/usr\/lib64\/passenger\/4.0.53\/\/helper-scripts\/rack-preloader.rb:157:in `<module:App>'\n  \/usr\/lib64\/passenger\/4.0.53\/\/helper-scripts\/rack-preloader.rb:29:in `<module:PhusionPassenger>'\n  \/usr\/lib64\/passenger\/4.0.53\/\/helper-scripts\/rack-preloader.rb:28:in `<main>'\n<\/pre>\n<p>Lets start troubleshooting that. Even if we are getting this error, it indicates already that we are getting somewhere, since error is pointing into Passenger, so at least something is working.<\/p>\n<p>Searching for help,<\/p>\n<ul>\n<li>http:\/\/stackoverflow.com\/questions\/27058601\/passenger-load-error-cannot-load-such-file-phusion-passenger-loaderror<\/li>\n<li>http:\/\/stackoverflow.com\/questions\/27058601\/passenger-load-error-cannot-load-such-file-phusion-passenger-loaderror<\/li>\n<\/ul>\n<p><strong>Step 8<\/strong>: Fiddle with config files<br \/>\nThis might be totally redundant, but lets&#8217; try it anyway.<\/p>\n<p>\/etc\/apache2\/http.conf.local;<\/p>\n<pre>\n<IfModule passenger_module>\n  PassengerRoot \/usr\/lib64\/ruby\/gems\/2.1.0\/gems\/passenger-4.0.53\n  PassengerDefaultRuby \/usr\/bin\/ruby.ruby2.1\n<\/IfModule>\n<\/pre>\n<p><strong>Step 9<\/strong>: What about running passenger manually?<\/p>\n<pre>\n# start passenger manually\npassenger start\n# That triggers \"Compiling Phusion Passenger...\"\n# => sounds promising\n# => also irrelevant since that is just passenger standalone, so waste of time\n\nservice apache2 restart\n<\/pre>\n<p>In the end, it appears that trouble came from the user for which gems were installed. I.e. &#8221;passenger&#8221; gem needs to be installed for correct ruby version in the environment of the user used to run rails server application in virtual host. If not so, passenger will just promptly fail.<\/p>\n<p><strong>TODO<\/strong>: Need to cleanup gem setup logic, and perhaps see if it&#8217;s possible setup passenger to run using rvm, so that it wouldn&#8217;t depend from the globally installed ruby version. I.e. I would rather use ruby version, which can be updated without dependency into one deployed via Linux package manager.<\/p>\n<p>After fixing gem issue, rails seems to boot, but fails with error page. However, this is good thing, since some clear progress is done in this journey.<\/p>\n<p>However, next problem is easy familiar error; just need to setup secret_key for production<\/p>\n<pre>\n*** Exception RuntimeError in Rack application object (Missing `secret_token` and `secret_key_base` for 'prod\\\n   uction' environment, set these values in `config\/secrets.yml`)\n<\/pre>\n<p>&#8230;. and after fixing that small mistake, our rails server popups into aliveness. Neat!<\/p>\n<p><strong>Mission completed<\/strong><br \/>\n<a href=\"http:\/\/host.kari.dy.fi\">Host Rails Server<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our guidance sources shall be today: Install package OBS:Server:Unstable \/ rubygem-passenger Phusion Passenger users guide, Apache version How To Setup a Rails 4 App With Apache and Passenger on CentOS 6 Setting up Rails app on Apache with passenger &#8211; Rails doesn&#8217;t seem to load Now, when having all interesting source material in hand lets&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,31,13,14,23],"tags":[],"class_list":["post-558","post","type-post","status-publish","format-standard","hentry","category-development","category-linux","category-rails","category-reference","category-web"],"_links":{"self":[{"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=\/wp\/v2\/posts\/558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=558"}],"version-history":[{"count":0,"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=\/wp\/v2\/posts\/558\/revisions"}],"wp:attachment":[{"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kari.world.ikari.fi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}