Skip to content

Instantly share code, notes, and snippets.

@kentatogashi
Last active August 29, 2015 14:00
Show Gist options
  • Save kentatogashi/8aac8781f277908659c2 to your computer and use it in GitHub Desktop.
Save kentatogashi/8aac8781f277908659c2 to your computer and use it in GitHub Desktop.

Use apache2 with Passenger

Required

  • CentOS
$ cat /etc/redhat-release 
CentOS release 6.5 (Final)
  • gcc-c++
  • apr-devel
  • apr-util-devel
  • httpd
  • httpd-devel
$ httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Apr  3 2014 23:56:16

If you don't get some modules, do below

$ sudo yum install -y gcc-c++ httpd httpd-devel apr-devel apr-util-devel

Install Passenger

$ gem install --no-rdoc --no-ri passenger
$ passenger --version
Phusion Passenger version 4.0.41

"Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.

Install apache2 module and build

$ cd ~
$ sudo find . -name passenger-install-apache2-module
./.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/passenger-4.0.41/bin/passenger-install-apache2-module
./.rbenv/versions/2.0.0-p451/bin/passenger-install-apache2-module
$ ./.rbenv/versions/2.0.0-p451/bin/passenger-install-apache2-module

Output some lines for deploying web application. And add these to httpd.conf.

Example:

For loading module
LoadModule passenger_module /home/********/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /home/********/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/passenger-4.0.41
     PassengerDefaultRuby /home/********/.rbenv/versions/2.0.0-p451/bin/ruby
   </IfModule>
For deploying web application

Suppose you have a web application in /somewhere. Add a virtual host to your Apache configuration file and set its DocumentRoot to /somewhere/public:

   <VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public    
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>

I actually added these lines to httpd.conf

<VirtualHost *:80>
    ServerName *:80
    RailsEnv development
    PassengerEnabled on
    DocumentRoot /home/togashik/sample_app/app/public
    <Directory /home/togashik/sample_app/app/public>
        AllowOverride all
        Options -MultiViews
    </Directory>
</VirtualHost>

Restart httpd

$ sudo service httpd restart

Error

I got fails below when executing restart httpd

Starting httpd: httpd: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf.d/passenger.conf: Cannot load /home/togashik/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so into server: /home/togashik/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so: cannot open shared object file: Permission denied

So try stopping SELinux and restart httpd

$ sudo setenforce 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment