# Hybrid website? php and rails

**URL:** <https://www.ruby-forum.com/t/hybrid-website-php-and-rails/71272>\
**Category:** Rails\
**Created:** [October 6, 2006, 4:04pm UTC](https://www.ruby-forum.com/t/hybrid-website-php-and-rails/71272 "2006-10-06T16:04:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [October 6, 2006, 4:04pm UTC](https://www.ruby-forum.com/t/hybrid-website-php-and-rails/71272/1 "2006-10-06T16:04:57Z")

</div>

i am writing a new app in rails that i need to run on an existing  
domain…

the problem is, there are a few subdirectories on that domain that run a  
few old (but necessary) php scripts and a few other things that still  
need to be accessible…

is it possible to set up apache so that i can run my rails app using  
mod-proxy, but still retain access to the old directories in  
~/public\_html ?

the only thing i would do is make sure that there is no directory name  
overlap in the system…

for example… i couldn’t have /scripts in both apps… which is fine…

i would appreciate any help in getting this set up…

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [October 6, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/hybrid-website-php-and-rails/71272/2 "2006-10-06T16:48:14Z")

</div>

I am currently working on porting an old PHP application to Rails.  
Except it was decided not to do it all in one fell swoop but over  
time, so I have to get the old PHP app and the new Rails app to play  
together.

In short, yes, it is quite possible but you gotta know how to use  
mod\_rewrite and other apache config bits. In my case though, I’m using  
litespeed, so it’s a different setup.

The way I have it setup is basically having the PHP app sitting there  
and anything that falls through be handled by Rails. It wasn’t that  
hard to setup. What was harder was (somewhat) harder was getting  
sessions to work together and other things like that.

Hope it helps,  
-carl

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [October 6, 2006, 4:56pm UTC](https://www.ruby-forum.com/t/hybrid-website-php-and-rails/71272/3 "2006-10-06T16:56:17Z")

</div>

Sergio R. wrote:

> the only thing i would do is make sure that there is no directory name  
> overlap in the system…
> 
> for example… i couldn’t have /scripts in both apps… which is fine…
> 
> i would appreciate any help in getting this set up…
> 
> thanks!

Read more about mod\_rewrite in Apache.  
This solve your problem.

## – Davis [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) Impact Media

C: +55 45 9928 0815  
B: [http://impactmedia.com.br/blog/](http://impactmedia.com.br/blog/)

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [October 6, 2006, 5:11pm UTC](https://www.ruby-forum.com/t/hybrid-website-php-and-rails/71272/4 "2006-10-06T17:11:09Z")

</div>

> > 
> 
> Read more about mod\_rewrite in Apache.  
> This solve your problem.

thanks, guys…

i will check this out…

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [October 6, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/hybrid-website-php-and-rails/71272/5 "2006-10-06T17:14:22Z")

</div>

> i am writing a new app in rails that i need to run on an existing  
> domain…
> 
> the problem is, there are a few subdirectories on that domain that run a  
> few old (but necessary) php scripts and a few other things that still  
> need to be accessible…
> 
> is it possible to set up apache so that i can run my rails app using  
> mod-proxy, but still retain access to the old directories in  
> ~/public\_html ?

Yes.

> the only thing i would do is make sure that there is no directory name  
> overlap in the system…
> 
> for example… i couldn’t have /scripts in both apps… which is fine…
> 
> i would appreciate any help in getting this set up…

This is what we use and it works fine. (apache2/mongrel)

\<VirtualHost \*:80\>

```
ServerName myserver.com
DocumentRoot /path/to/my/app/public

<Directory "/path/to/my/app/public">
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

<Proxy balancer://mongrel_cluster>
  BalancerMember http://127.0.0.1:8805
</Proxy>

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} \.php
RewriteRule ^(.*)$ $1 [QSA,L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [QSA,L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.php -f
RewriteRule ^(.*)$ $1/index.php [QSA,L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)[^/]$ $1/ [QSA,L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} 

```

[P,QSA,L]

```
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

php_value include_path /path/to/my/app/php:/usr/local/lib/php:.
php_value auto_prepend_file /path/to/my/app/php/auto_prepend.php

# this not only blocks access to .svn directories, but makes it 

```

appear  
# as though they aren’t even there, not just that they are forbidden  
\<DirectoryMatch “^/.\*/.svn/”\>  
ErrorDocument 403 /404.html  
Order allow,deny  
Deny from all  
Satisfy All
