Running Rails applications with Passenger alongside PHP applications - php

I'm setting a server where I will need to run Ruby On Rails 3 applications along with some PHP websites.
The server is a CentOS 5.8 machine running Apache 2.4.3.
The server is for testing and PRE-production, so performance is not an issue.
I'm using Phusion Passenger for the Rails apps, and I've created a bunch of virtual-hosts (with associated folders and DB accounts).
Then, I'm planning to use other v-hosts for PHP.
Is it possible? How should I proceed?
Thank you very much
details:
httpd.conf:
LoadModule passenger_module /app/auser/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /app/auser/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17
PassengerRuby /app/auser/.rvm/wrappers/ruby-1.9.3-p286/ruby
(...)
##
## Virtual hosts
Include conf/extra/httpd-vhosts-phpmyadmin.conf
Include conf/extra/httpd-vhosts-rails01.conf
Include conf/extra/httpd-vhosts-rails02.conf
Include conf/extra/httpd-vhosts-php01.conf
Include conf/extra/httpd-vhosts-php02.conf
....
Passenger-managed v-hosts will be like:
Include conf/extra/httpd-vhosts-rails01.conf
<VirtualHost *:80>
ServerName rails01.lcl
DocumentRoot "/app/auser/apps/rails01/public"
<Directory "/app/auser/apps/rails01/public">
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
PHP-based v-hosts will be like:
Include conf/extra/httpd-vhosts-php01.conf
<VirtualHost *:80>
ServerName php01.lcl
DocumentRoot "/app/auser/apps/php01/public"
<Directory "/app/auser/apps/php01/public">
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Yes, Running Rack/Rails alongside PHP definitely works.

There is a really cool gem called rack-legacy which might be what you are are looking for. It allows you to execute PHP code hosted on your Rails application server through php-cgi.
Rack Legacy tries to provide interaction with legacy environments like PHP and CGI while still getting the Rack portability so you don't need a full Apache/lighttpd stack.
I have used for some experiments, and it seems is possible to have a wordpress running and served with the Rails app server without having to mess up with apache/ngix files.

Related

Trick PHP running behind mod_php and change host and protocol

I'm migrating legacy apps to docker and I need to "trick" php into thinking that it runs on the exact same environment as it used before.
Basically, the app used to run on an apache2 with mod_php and the PHP code does something somewhere that says "If you've been called with HTTP, set the link for the images to http."
My docker image is now accessible locally with http only. But I would like to still fake PHP into thinking that it has been accessed with HTTPS.
I suppose that Apache should rewrite the $_SERVER['HTTPS'] variable but I can't find in the documentation how I could do that.
Here is my current configuration for my app:
<VirtualHost *:8080>
DocumentRoot "/var/www/app"
<Directory /var/www/app>
Require all granted
Order allow,deny
Allow from all
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>

Azure website PHP vhosts

I have a website set up on Azure which I'd like to deploy a PHP site to.
In WAMP I have the following vhosts config:
<VirtualHost *:9898>
ServerAdmin wayne#localhost
ServerName test.somesite.com
DocumentRoot "C:\wamp\www\somesite-ui\www"
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "C:\wamp\www\somesite-ui\www">
AllowOverride All
Order allow,deny
allow from all
</Directory>
# Rewrite configuration
Include "C:\wamp\www\somesite-ui\rewrite.conf"
</VirtualHost>
This is because we're using Atsumi MVC
How can I configure the Azure website to use a similar config?
I am not sure that this answer will help you. But instead of just creating a php web site, you could create a VM first with any operating system, and enable http end points to the vm. Install Apache server on the vm and do the necessary configuration. ( Or you coudld simply install WAMP in it)
azure web sites has the address lite somthing.azuresites.net (not sure)
azure vm will have "somthing.cloudapp.net" so the domain name won't be a much problem for you.
I have written a blog post on How to create a VM on azure. You could use it if you like.

Django/mod_wsgi and PHP as Virtual Hosts on same Apache Server using MAMP

UPDATE: My original question is below, but the code I posted with the question has been edited to the final working solution.
I am trying to run multiple sites on my MAMP development server. Some of the sites are wordpress sites that live in the htdocs in MAMP and some of the sites are django apps that live in a folder titled djangoprojects.
I have been trying to implement the solutions from these stack questions:
multiple django sites with apache & mod_wsgi
How do I run Django and PHP together on one Apache server?
but I have not been successful. I was able to run the django site on apache with the code you see in the first VirtualHost brackets (from the daemon process line onward) but then none of the php sites could be visited.
Help is greatly appreciated. I am new with this and I can't work out the errors.
Here is the code from my httpd.conf:
UPDATE: The code below works. Both the Django App and the PHP applications exist on the localhost server. The PHP related VirtualHost stuff was copied from further up in the MAMP httpd.conf file.
<VirtualHost *:80>
ServerName localhost:80
UseCanonicalName Off
DocumentRoot "/Applications/MAMP/htdocs"
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
<Directory "/Applications/MAMP/htdocs">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess site1 display-name=%{GROUP}
WSGIProcessGroup site1
Alias /media/ /Users/sequoia/djangoprojects/dynamics/media/
<Directory /Users/sequoia/djangoprojects/dynamics/media>
Options ExecCGI
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /dynamics /Users/sequoia/djangoprojects/dynamics/apache/django.wsgi
<Directory /Users/sequoia/djangoprojects/dynamics/apache>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
A couple of problems to start with:
ServerName is mean to specify the host name not a URL path.
You should never set DocumentRoot to be where your Django site source code is.

Putting PHP and Rails on the same server

I am currently working on a website where the core of the website is in PHP. I now want to write a bunch of applications on top of that core, and was hoping to do it in Rails. I saw a couple things online where you could set single folders to be handled by PHP, (example: http://macdiggs.com/2007/06/29/using-php-inside-rails-structure-on-apache/) but I am hoping to do the opposite, have single folders that are handled by Rails, and then the rest is handled by PHP. For example, having ourwebsite.com/blog as a Rails app, but ourwebsite.com and ourwebsite.com/internal are all in PHP. What kind of Apache configurations would let this happen?
(As a bonus, my server is managed by Plesk, so I am concerned about making straight changes to the apache configuration. I have root access, so I can do it, but I am worried that Plesk might get mad)
EDIT: I should also mention, I am using Subdomains as part of my application, so I would really prefer to have something like ourwebsite.com/rails_app. If that is the only option, I can go that route, but I would prefer not to.
If you want the PHP app to be default application and only use Rails for a subdirectory, this Apache configuration should work for you:
DocumentRoot "/path/to/your/php/app/html"
ProxyPass /some_resource http://127.0.0.1:3000/some_resource
Note that your rails application would be running on port 3000 and you will need the ProxyPass Apache module installed.
I am working on a project and its having some blog in php ie wordpress and application in rails. Just configured it an hour before. Might help you.
<VirtualHost *:80>
ServerName abc.com
DocumentRoot /home/me/apps/my_rails_app/current/public
</VirtualHost>
<VirtualHost *:80>
ServerName blog.abc.com
DocumentRoot /home/me/apps/abc/wordpress
<Directory "/home/me/apps/abc/wordpress">
Options +Indexes FollowSymLinks
AllowOverride All
Allow from all
Order allow,deny
</Directory>
</VirtualHost>

Acessing other webapps while one is in document root

I have a Zend Framework project on a local machine, and as recommended its /public subfolder is made a DocumentRoot in httpd.conf. So I access this app simply with http://localhost.
This new requirement makes me unable to access other
web apps in a former webserver root (which contains a few regular php apps and a couple of zend framework apps).
What configuration should I choose to be able to simultaneously access both ZF root-based apps and other apps like PHPMYADMIN?
You'll probably need to use some kind of VirtualHost
You have at least two solutions :
VirtualHosts based on diferent port numbers
For instance, you'd have one site on http://localhost/ (ie, default port = 80)
And another one on http://localhost:8001/
And another one on http://localhost:8802/
And so on
VirtualHosts based on different domain-names
For instance, you'd have on site on http://localhost/
And another one on http://mytestwebsite/
In the second case (the solution I always use), you will have to edit your "hosts" file, so "mytestwebsite" is an alias to your local machine -- which IP address is 127.0.0.1
Under windows, this file is located in C:\WINDOWS\system32\drivers\etc
On Linux, it's in /etc/
You'd have to add a line like these ones :
127.0.0.1 localhost
127.0.0.1 mytestwebsite
Then, in the Apache configuration, you need to create one VirtualHost per site. Something like this, I suppose :
<VirtualHost *>
ServerName mytestwebsite
DocumentRoot /home/squale/developpement/tests
<Directory /home/squale/developpement/tests>
Options Indexes FollowSymLinks MultiViews +SymLinksIfOwnerMatch
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *>
ServerName myothertestwebsite
DocumentRoot /.../myothertestwebsite
<Directory /.../myothertestwebsite>
Options Indexes FollowSymLinks MultiViews +SymLinksIfOwnerMatch
AllowOverride All
</Directory>
</VirtualHost>
(Needs tunning / configuration, of course)
And you'll also probably need some directive like this one :
NameVirtualHost *
Well, this might not be the entire solution (that one depends on your server / applications) ; but I hope these few pointers will help you get to it !
If you need more help, the keyword is "VirtualHost" ;-)
Have fun !
Zend Framework probably uses a .htaccess file. If so, you might use that to add rules to leave the other apps alone. Another option is to use subdomain (eg phpmyadmin.localhost)

Categories