Integrate Rails app and PHP on Apache
January 5, 2012
Here is one method of how to integrate a Ruby on Rails application and a PHP application or even just static HTML using Apache webserver. One reason for doing this could be (in this website’s case) that your main website application is Rails but you want to use WordPress or another technology of blog or CMS ‘within’ that site.
This method is assuming you are using Apache and Passenger as your webserver, Passenger is only referenced when you need to stop rails handling that url later.
For example;
example.com/ <-- rails app example.com/blog <-- wordpress blog
To do this;
Create 2 directories, one for the rails app and one for the PHP/other app – this is not strictly necessary but nice to keep things separate. If not using this method then ignore this and the symlink!
/www/path/to/rails_app/public /www/path/to/my_blog
Now go into the rails_app/public directory and create a symbolic link to the other directory.
ln -s /www/path/to/my_blog /www/path/to/rails_app/public/blog ls -la /www/path/to/rails_app/public blog -> /path/to/my_blog
Now edit your httpd.conf, .htaccess – whichever file apache is using for your rails app and add the following and restart httpd:
<Location /blog> PassengerEnabled off </Location>
Now whenever a request for the example.com/blog comes in, passenger does not send to rails, instead looks in the public/blog dir which is actually a sym link to the real dir.
If you are using Capistrano then you can add something like this to your deployment script to automatically create the symlink each deployment.
set :wp_dir, "/path/to/my_blog"
task :buildlinks, :roles => :app do
run "ln -s #{wp_dir} #{current_path}/public/blog"
end
1 comment
Pingback: Website upgrade 2011 | robertomurray.co.uk