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 mysite.com (for simplicity mysite.com should be your domain name) containing the following code:
<VirtualHost *:80>
ServerName mysite.com
DocumentRoot /var/www/wordpress
RailsBaseURI /app
RailsBaseURI /playground
RailsBaseURI /staging
</VirtualHost>
Organise your projects directory
In /var/www directory contains 4 directories as below:
- wordpress (root directory for wordpress => mysite.com ).
- app (main rails app => mysite.com/app ).
- playground (rails app for playground purpose => mysite.com/playground ).
- staging (rails app for staging purpose => mysite.com/staging ).
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: http://mysite.com/app
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]
</IfModule>
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
192.168.1.100 mysite.com
where :
- 192.168.1.100 is your computer ip. you can check you computer ip with ifconfig command.
- mysite.com is your domain name
Tell apache that you want to enable your virtualhost
run the following command a2ensite mysite.com
where :
- a2ensite (apache2 enable site ) is the apache utility to enable your virtualhost.
- mysite.com 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 :
http://mysite.com should be served by wordpress
http://mysite.com/app rails app.
Done !!!
Thanks for the share!
ReplyDeleteHellen