Phusion Passenger (mod_rails or mod_rack ) makes execution of Ruby web applications more easier on Apache webserver. It requires no maintenance from our part and minimal port management. It was designed keeping in mind performance, stability and security.
Here I am explaining more about deploying this module on Linux servers using cPanel as the control panel.
Currently in cPanel, by default, the Ruby On Rails(RoR) applications are using Mongrel webserver. By Phusion Passenger, we can use Apache itself for RoR applications, instead of redirecting the application to Mongrel.
We can install Phusion Passenger using different methods. An Easy way is to use gem to install Phusion Passenger in two simple steps. Make sure that RoR is already installed on your cPanel server using ‘/scripts/installruby‘.
Step 1: #gem install passenger Step 2: #passenger-install-apache2-module
In the second step, while installing ‘passenger-install-apache2-module’, I ran into two errors. The errors and corresponding solutions are given below.
Error 1: Apache 2 development headers were not detected by the script.
Checking for required software... * GNU C++ compiler... found at /usr/bin/g++ * Ruby development headers... found * OpenSSL support for Ruby... found * RubyGems... found * Rake... found at /usr/bin/rake * Apache 2... found at /usr/local/apache/bin/httpd * Apache 2 development headers... missing..(some error here)
Solution: Here the script is checking for apxs installation path. On a cPanel server, the default path is ‘/usr/local/apache/bin/apxs‘. But the script was looking for ‘/usr/sbin/apxs’. To solve this, I created a symbolic link from ‘/usr/sbin/apxs‘ to ‘/usr/local/apache/bin/apxs‘.
Error 2: Another error that came up was:
/usr/local/apache/include/apr_file_info.h:200: error: 'apr_ino_t' does not name a type ..."
Solution: There were two installation of apr on the server. One by default and one by cPanel. The passenger script was taking binary path from one installation and include files from other. I moved the default installation on the server to a backup folder and created a symbolic link from default installation’s include directory to apr include directory of cPanel. The command for this is given below:
#ln -s /usr/local/apache/include/ /usr/include/apr-1
After completing the ‘passenger-install-apache2-module’ step successfully, add the corresponding Modules to Apache configuration file.
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger- 2.0.2/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2 PassengerRuby /usr/bin/ruby
Save and restart Apache.
#/usr/local/cpanel/bin/apache_conf_distiller --update #/usr/local/cpanel/bin/build_apache_conf #/etc/init.d/httpd restart.
Deploying RoR application:
Suppose, we have a RoR application in “/home/username/testapp”. Follow the steps given below to redirect the main domain to this application.
Step 1: By default the Document root of this domain will be /home/username/public_html/. Create a symbolic link from /home/username/public_html/ to the RoR application’s public directory, /home/username/testapp/public/.
-bash-3.2# ln -s /home/username/testapp/public/ /home/username/public_html
Step 2: Then add the following rule in the virtual host entry of the domain.
Note : If you want to redirect a subdirectory under public_html like http://domainname/rails to the RoR’s application, change the symbolic link accordingly and specify the rule in the domain’s virtualhost entry as:
It is not recommended to edit the virtual host entry directly. You can add this rule in the include file mentioned in the virtual host entry of the domain.
By default these include files will be commented in the configuration file. We have to manually create directories corresponding to this include file.
Directories up-to /usr/local/apache/conf/ were already there in the server. I created new sub-directories from ‘userdata’ to ‘domain_name’. Under the directory /usr/local/apache/conf/userdata/std/2/username/domain_name/, you can create any file with .conf extension. I created the file rails.conf to add the “RailsBaseURI” rule.
-bash-3.2# ll /usr/local/apache/conf/userdata/std/2/username/domain_name/ total 4 -rw-r--r-- 1 root root 15 Jul 31 04:05 rails.conf
Step 3: After that, execute the below command,
#/scripts/ensure_vhost_includes --user=username (Use cpanel username of that domain)
Step 4: You can restart the RoR application by restarting Apache or using the command,
#touch /path_to_application/tmp/restart.txt In this case, #touch /home//username/testapp/tmp/restart.txt
The domain will now work fine using this new mod_rails installation. 🙂 Make sure that you are not starting or restarting this application from cPanel >> Ruby On Rails option. It will switch to Mongrel webserver.
You can check Apache error log file itself for errors.
Although cPanel is not using this module (mod_rails) with Easyapache script and in their Ruby Ob Rails interface. By following this method, we can use this module on a cPanel server with much ease.
Phusion Passenger conflicts with some Apache modules like mod_rewrite and mod_alias. They may be installed together with mod_passenger and used outside virtual hosts that contain a Rails application. Phusion Passenger recommend not to use their features inside virtual hosts that contain a Rails application. Rewrite rules are mainly used to accelerate caching of pages. Phusion Passenger supports page caching without mod_rewrite. So there is no need to worry about this.
About the author
Anusha M.K has been working with Bobcares for more than one and half years. She specializes on Linux and Windows server administration using variety of control panels. She is an expert in Ruby On Rails technology especially its configurations and deployment in Linux servers.