Skip to content

Rails in subdirectory of wordpress

September 22, 2011

I am developing a rails app. the app is not ready so our product manager requires to use wordpress as main page and the application located in subdirectory of wordpress and let uses try the app via wordpress.

Requirement :

Apache with php and passenger.

I am using apache passenger for deploying rails app. Passenger make  Php and Ruby running smoothly in apache web server.

Below is the summary of what I did to make this happened

Create virtualhost

In /etc/apache2/sites-available/ create file call (for simplicity should be your domain name) containing the following code:

<VirtualHost *:80>
DocumentRoot /var/www/wordpress
RailsBaseURI /app
RailsBaseURI /playground
RailsBaseURI /staging

Organise your projects directory

In /var/www directory contains 4 directories as below:

  • wordpress (root directory for wordpress => ).
  • app (main rails app  => ).
  • playground (rails app for playground purpose  => ).
  • staging (rails app for staging purpose => ).

Create symlink

inside /var/www/wordpress create the symlink to app, playground and staging.

ln -s /var/www/app                    /var/www/wordpress/app
ln -s /var/www/playground     /var/www/wordpress/playground
ln -s /var/www/staging            /var/www/wordpress/staging

The syntax is:

ln -s [target_source] [link]

We need symlink because when we access:

then apache will go look for  [webroot]/app where our webroot we configure to be in    /var/www/wordpress/ so it will look for /var/www/wordpress/app

then the operating system serves /var/www/app instead because /var/www/wordpress/app is linked to /var/www/app


In case we enable SEO in wordpress then we need to tell apache to escape wordpress every request url starting with app, playground, staging

in /var/www/wordpress  modify .htaccess file as bellow

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !app*
RewriteCond %{REQUEST_FILENAME} !playground*
RewriteCond %{REQUEST_FILENAME} !staging*
RewriteRule . /index.php [L]

In case if you are working on local machine you need to create hosts. in /etc/ edit hosts file and append the following content to it

where :

  • is your computer ip. you can check you computer ip with ifconfig command.
  • is your domain name

Tell apache that you want to enable your virtualhost

run the following command  a2ensite

where :

  • a2ensite (apache2 enable site ) is the apache utility to enable your virtualhost.
  • is the filename of virtual host you created previously in /etc/apache2/sites-available

Reload apache

sudo /etc/init.d/apache2 reload


Open up your browser and type : should be served by wordpress rails app.

Done !!!

One Comment
  1. Thanks for the share!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: