cPanel, RoR Passenger and PHP in bed together

I spent quite a lot of time pulling my hair out over this one but finally was able to massage cpanel so that our ruby on rails site which uses mod_rails / passenger would ignore a specific directory that we wanted to run a PHP app ( Drupal ) in. You CAN run php by default but you have to go to the script explicitly – i.e. going to /drupal/index.php was ok but /drupal/ threw and error. So the problem was two fold – figuring out how to tell passenger to ignore that entire directory and then how to get this configured in cpanel in the ‘proper’ way.

At first I got bogged down trying to get it to work with some url rewrites in the .htaccess file. It seemed logical but it didn’t work because passenger does it’s thing before .htaccess even kicks in. Besides, the best approach is to bypass passenger completely for that directory – better for optimizing and is really more true to what we were trying to setup.

After digging I discovered the ‘PassengerEnabled’ directive! I know RTFM. Just set PassengerEnabled off for that directory and we’re golden.

Now how to fit it into cpanel but just for this domain? Not as simple as it sounds. Editing the httpd.conf is of course NOT the right solution. Cpanel does expose some parts of the apache configuration in the admin but it’s not vhost specific so again it would affect all sites when I just wanted to change one. RTFM again and you’ll see there are some manual ways to insert things directly into the vhost. You have to manually create a series of directories (the userdata one at the top of the chain is not there by default) and put an override file named anything.conf in the right place.

In my setup i created the file override.conf here:

/usr/local/apache/conf/userdata/std/<vhost account number>/<cpanel user name>/<domain name>/override.conf

And put this in it (/drupal is the folder i want to run php in).

<Location /blog>
PassengerEnabled off

And now one more hitch…

Running /scripts/verify_vhost_includes like it says to in the cpanel docs said that my vhost file had an error!!! It said PassengerEnabled was not a valid directive. I ended up just giving it a shot anyways and was pleased to find that it worked just fine! I suspect that cpanel just doesn’t know this directive becuase it is specific to passenger. So you run:

/scripts/ensure_vhost_includes --user=<cpanel user name>

to rebuild the vhosts file for this user and restarts apache and voila!


About The Author

1 Comment

Thomas » 19 Aug 2012 » Reply

I am trying to get this type of thing working on my server but it isn’t working right. I followed and did everything you have done with no success.

The verify script says it is okay. I rebuild it successfully but the RoR script still says the page you were looking for doesn’t exist.

I am using Rails 3.1.3 and ruby 1.8.7.

I had it working at one time ( a couple months ago, starting work on this site again ) I am not sure what could have changed in that time to mess this up.

And put this in it (/drupal is the folder i want to run php in).

PassengerEnabled off

You say you want /drupal to run php, but location /blog.
I assume that’s just a typo? Does not need to be the absolute path?

Thank you for this article. It does help at least point me in the right direction!

Have your say!

Have your say!


Name *

Email *

Tips + Updates + Goodies

Join our mailing list, and get updates on how to better your web ninja skills.