Friday, June 10, 2016

Installing Passenger

Blacklight ships with a built in web services package called WEBrick. This package allows the app to communicate with the web server. WEBrick is not recommended for a production deployment, so we will use the web services package Passenger instead.

Note: The Passenger website offers a very good installation tutorial. I used the tutorial for my installation. I will go through the steps I followed here, but the Passenger site tutorial is much more detailed. If you are following this tutorial, but are using a slightly different setup, the tutorial offers information for servers and operating systems other than Apache/Cent OS.

Check your kernel version and SELinux status


1. If not already connected to the VPS as the root user, open a Terminal window and connect to the VPS as the root user:

$ ssh root@example.com

Enter the root user's password when prompted and hit Return to log in.

2. Run the following command to check your kernel version:

# uname -r

The response I recieved was

2.6.32-573.22.1.el6.x86_64

Because my kernel is <=2.6.39 I need to make sure SELinux is disabled (This and other scenarios are covered in the Passenger website's tutorial). If your version is >=2.6.39 you don't need to worry about SELinux.

3. To check SELinnux status, run the following command:

# grep SELINUX /etc/selinux/config

The response I received was

# SELINUX= can take one of these three values:
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
SELINUXTYPE=targeted


showing that my SELinux is already disabled. See the Passenger installation tutorial for more on how to disable SELinux.

Enable EPEL


4. The Passenger website installation tutorial has us enable EPEL next, but we already installed and enabled EPEL when we installed Node.js in an earlier step.

Install Passenger


Bluehost has a help document that outlines the installation of Passenger on a VPS. I chose to follow the instructions of that tutorial that are related to Passenger instead of the instructions outlined on the Passenger website's tutorial. I don't know if the Passenger website's instructions work on the Bluehost CentOS VPS or not, but please leave a comment below if you try it and they do/don't work.

5. In Terminal, connect to the VPS as the root user:

# ssh root@example.com

6. Run the following command to install curl-devel:

# yum install curl-devel

When prompted "Is this ok [y/N]:" type the letter "y" and press Enter.

7. In a new Terminal window, connect to the VPS as the single user:

# ssh username@example.com

8. Change directories to the single user's home directory:

# cd /home/username/

9. Run the following command to install the Passenger gem:

# gem install passenger

The installation will take a few minutes. This is what I saw in Terminal during the installation process:

Fetching: passenger-5.0.28.gem (100%)
Building native extensions.  This could take a while...
Successfully installed passenger-5.0.28
Parsing documentation for passenger-5.0.28
Installing ri documentation for passenger-5.0.28
Done installing documentation for passenger after 64 seconds
1 gem installed


10. Next we will install the module that allows passenger to work with the Apache web server. The process takes a few minutes.

I went to my Terminal window in which I was logged in as root user for this step. You might be able to run the command when logged in as the non-root user, but I think I ran into a problem when I tried this which is why I ended up running it as the root user. After connected as root and after changing directories to the home directory of the single user, I started the module installation by running the following command:

# passenger-install-apache2-module

A welcome message will explain what will happen during the installation:

Welcome to the Phusion Passenger Apache 2 module installer, v5.0.28.

This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.


Press Enter to continue to the next step of the installation process. The installation will ask you what languages you are interested in:

--------------------------------------------

Which languages are you interested in?

Use <space> to select.
If the menu doesn't display correctly, press '!'

 ‣ ⬢  Ruby
   ⬢  Python
   ⬢  Node.js
   ⬡  Meteor

--------------------------------------------


I selected the first three (Ruby, Python, and Node.js).

After this, the installation will search the system for all Apache installations. After the check completed, here is the prompt I saw:

Checking whether there are multiple Apache installations...
Multiple Apache installations detected!

You are about to install Phusion Passenger against the following
Apache installation:

  Apache 2.2.31
  apxs2     : /usr/bin/apxs
  Executable: /usr/local/apache/bin/httpd

However, 2 other Apache installation(s) have been found on your system:

  * Apache 2.2.31
    apxs2     : /usr/local/apache.backup/bin/apxs
    Executable: /usr/local/apache/bin/httpd

  * Apache 2.2.31
    apxs2     : /usr/local/apache/bin/apxs
    Executable: /usr/local/apache/bin/httpd

Are you sure you want to install against Apache 2.2.31 (/usr/bin/apxs)? [y/n]:


This step is covered in the Bluehost Passenger installation tutorial, which recommends selecting the (/usr/bin/apxs) option. I confirmed with the installer, which then proceeded with the installation. After many, many lines of text were printed to the Terminal window, I received another prompt:

--------------------------------------------
Almost there!

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /home/username/.rvm/gems/ruby-2.2.4/gems/passenger-5.0.28/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /home/username/.rvm/gems/ruby-2.2.4/gems/passenger-5.0.28
     PassengerDefaultRuby /home/username/.rvm/gems/ruby-2.2.4/wrappers/ruby
   </IfModule>

After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!

Press ENTER when you are done editing.


--------------------------------------------


11. Like the instructions say, we need to add the lines given above (make sure you change "username" to your actual username) to the Apache config file.

The Apache config file I needed to change was located on the server at:

/usr/local/apache/conf/httpd.conf

To edit Apache’s config file, either edit it in a Terminal window with a text editor like vim or do what I did and download it to your desktop with an FTP program (I used Fetch), edit it with a text editor like TextWrangler, and then upload the edited file back to the server.

Check to make sure the following line is in your httpd.conf file:

Include "/usr/local/apache/conf/includes/pre_main_2.conf"

If it isn't go ahead and add it near the top of the file after any initial comment lines and after the following line if it exists:

Include "/usr/local/apache/conf/includes/pre_main_global.conf"

But before and other uncommented lines.

12. Now go to the file at /usr/local/apache/conf/includes/pre_main_2.conf and open it for editing in vim or on your local desktop.

13. Paste the text supplied by the Passenger module installation into the pre_main_2.conf file:

# BELOW WAS ADDED AFTER PASSENGER WAS INSTALLED AGAINST
# Apache 2.2.31
# apxs2      : /usr/bin/apxs
# Executable: /usr/local/apache/bin/httpd


LoadModule passenger_module /home/username/.rvm/gems/ruby-2.2.4/gems/passenger-5.0.28/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/username/.rvm/gems/ruby-2.2.4/gems/passenger-5.0.28
PassengerDefaultRuby /home/username/.rvm/gems/ruby-2.2.4/wrappers/ruby
</IfModule>


14. Save the file and upload it back to the /usr/local/apache/conf/includes/ directory on the server.

15. Go to the Terminal window in which the Passenger module installation is in progress and press Enter to continue with the installation.

16. The installation will attempt to validate the installation of the module and its communication with Apache. Hopefully you will see:

Validating installation...

 * Checking whether this Passenger install is in PATH... ✓
 * Checking whether there are no other Passenger installations... ✓
 * Checking whether Apache is installed... ✓
 * Checking whether the Passenger module is correctly configured in Apache... ✓

Everything looks good. :-)


If so, you have successfully installed the module.

17. Before moving forward, restart Apache at the command line with the following command:

# service httpd restart

18. To check the installation after restarting Apache, run the following command:

# /home/username/.rvm/gems/ruby-2.2.4/wrappers/ruby /home/username/.rvm/gems/ruby-2.2.4/gems/passenger-5.0.28/bin/passenger-config validate-install --validate-apache2 --invoked-from-installer

You should see the same four validation checks as before.

19. One final check is to see if Apache has started the Passenger core processes. Run the following command in Terminal to check this:

# /home/username/.rvm/gems/ruby-2.2.4/gems/passenger-5.0.28/bin/passenger-memory-stats

Depending on your installation location, your passenger-memory-stats file may be in a different location. If so, you may have to do a search for the passenger-memory-stats file and then use its full correct path to run the command.

If the command runs successfully, you will a response that contains a section with following header and one or more rows under the header:

----- Passenger processes -----
PID    VMSize    Private  Name
-------------------------------


Troubleshooting


If the module installation did not work, you will probably receive error messages that help point to the problem. After addressing any errors you may have received, you can try running the module installer again.

If you need to completely uninstall Passenger and start from scratch, you can run the following command:

# gem uninstall passenger



Previous post: Installing Solr

Next post: Creating the new Rails app on the web server

1 comment:

  1. Really nice blog post.provided a helpful information.I hope that you will post more updates like this Ruby on Rails Online Training

    ReplyDelete