Putting PHP and Rails on the same server - php

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>

Related

How do you configure Symfony 4 to route alongside other XAMPP (Apache) projects?

I'm brand new to Symfony, so this question will undoubtedly come across as noobish. How do you get Symfony to work with XAMPP? I've read the Symfony documentation for configuring Apache, but can't make heads or tails of it.
XAMPP projects are stored in a single /htdocs directory. Each project has its own subfolder and is accessible via the following URL: http://localhost/project_folder. At least, that's how I've been doing it.
My problem is this: Symfony is different in that its root directory is not front-facing. In other words, to actually access a Symfony 4 site, you need to navigate to the /public directory. However, as my local XAMPP (i.e. Apache) server is configured to use a single DocumentRoot (/xampp/htdocs), my Symfony project is inaccessible unless I manually append /public to the URL.
What I want: http://localhost/symfony_project_folder
What I have: http://localhost/symfony_project_folder/public
I do not want to set up an entirely separate local server for a single web application, nor do I want to deal with an entirely different URL structure than what is used by my other projects.
How do I configure Symfony 4 or Apache to properly route to /public in this environment?
Thank you for your help.
Hi there indeed when you create a new symfony project you need to change the document root of the domain in public folder. A good way to work with symfony would be to use docker which helps you out keep projects separated and you can use phpdocker.io to generate a docker configuration very fast to start working with docker.
Anyway here is an example from symfony manual on how to setup a vhost.
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
You can read more about web server configuration here

Zend2 without Virtual Host

I have Zend2 website configured on an Ubuntu machine.
Project Path: /var/www/zf2/
Virtual host configuration:
<VirtualHost *:80>
ServerName zf2.localhost
DocumentRoot /var/www/html/zf2/public
SetENV APPLICATION_ENV "development"
<Directory /var/www/html/zf2/public/>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Accessing "localhost/zf2" list the files in the directory. Is there anyway to access this zend2 website without virtual host i.e with localhost/zf2 ?
I already tried by adding .htacess in /var/www/html/zf2, but it does not budge. Any help will be highly appreciated!
The question isn't very clear, but if you're asking if it's possible for someone to access your ZF site without using the zf2.localhost hostname, then because of the way you have set it up, yes (and you should definitely change this).
By default, Apache on Ubuntu has localhost setup to point at /var/www/html/. So by putting your ZF2 app in a subfolder of that, it will be possible for someone to access your ZF app (including files outside of its document root) via. localhost. This is a potential security hole which you should fix. Simply move your ZF2 app to a different folder that isn't inside /var/www/html (e.g. /var/www/zf2) and you won't have this issue.
Also note that if you are using a reasonably recent version of Ubuntu, you will be running Apache 2.4, and your vhost isn't setup correctly. See the second example here: http://framework.zend.com/manual/current/en/ref/installation.html#apache-setup

PHP Namespace collision with Phalcon, Vagrant, Apache2

I have this strange problem that I can best describe as "namespace leakage". I have setup a vagrant box running Apache2 with VHosts setup to replicate the production server in terms of domains & sub domains. I have edited my local machine's hosts file accordingly, and my VHosts work fine.
I have also created a skeleton/base app coded with PhalconPHP. It's a multi modular app with all the generic features I require to develop my apps (actually redevelop a load of very old, outdated apps). The skeleton app works fine.
The problem I have is that if I go to app1.dev in my browser, it works. Then if I go to app2.dev, app2 is clearly trying to load some components - views etc from app1 and is giving errors. However, close the browser and try again by going to app2.dev and it now works fine. Then go to app1.dev and that is now broken and trying to load components from app2! I managed to track this odd behaviour down to namespace collision.
It has to be namespace collision because my apps are all based on the skeleton app and use it's name spaces, which are obviously the same for generic parts of the app - modules such as App\backend, App\frontend etc. If on a broken app, I navigate in my browser to a part of that app that is unique, and therefore has a unique namespace, it works fine because there is no collision! Also a couple of apps are coded with Codeigniter3 which does not use namespaces, and those apps do not have this issue. It only effects the Phalcon apps with namespaces.
I will add that each app uses .htaccess to direct requests to the front controller located in public/ directory.
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
I wondered if the .htaccess was the issue, but I think I've ruled that out. It is doing what it is supposed to do.
Here's an example of one of my VHost settups in apache - they all follow this pattern.
<VirtualHost *:80>
ServerName app1.dev
ServerAlias www.app1.dev
DocumentRoot /vagrant/www/app1
<Directory "/vagrant/www/app1">
Options Indexes Followsymlinks
AllowOverride All
Order allow,deny
Allow from All
Require all granted
</Directory>
</VirtualHost>
Changing all the namespaces throughout every app would be a pretty major job, and I don't think that should be necessary. I don't think this should be an issue on the production server as that uses CloudLinux/Centos & WHM, but it is a bit of a worry!
Clearly namespaces should not collide across different document routes and VHosts right? What am I missing?
I have solved similar problem in Apache using different local IP's for every app:
/etc/hosts
127.1.0.1 edu.l
127.1.1.1 tech.l
...
/etc/apache2/sites-available/001-blogs.conf
<VirtualHost edu.l:80>
ServerName edu.l
ServerAdmin webmaster#localhost
DocumentRoot /var/www/blog/edu
ErrorLog ${APACHE_LOG_DIR}/edu.error.log
CustomLog ${APACHE_LOG_DIR}/edu.access.log combined
</VirtualHost>
<VirtualHost tech.l:80>
ServerName tech.l
ServerAdmin webmaster#localhost
DocumentRoot /var/www/blog/tech
ErrorLog ${APACHE_LOG_DIR}/tech.error.log
CustomLog ${APACHE_LOG_DIR}/tech.access.log combined
</VirtualHost>
...
You can ommit configuring names in hosts ans use IP's in .conf tho.
It works because if you define few apps on same IP and port, Apache seems to remember directory it is working on and mismatching files.

Adding a new hard drive to xampp

I am running xampp as an intranet server using 'virtualhost' for 15 'sites' inside our network and things are working fine with 3 exceptions. First problem is my biggest-my 2TB drive is full and I need to add another drive to the server to call up data - how can I do this?
Here are 2 virtual domains from the vhosts file - the 3rd example is what i need to accomplish.
<VirtualHost 172.16.106.162:80>
ServerName clubcal.iserver
ServerAlias www.clubcal.iserver
DocumentRoot "F:/xampp/htdocs/clubcal"
</VirtualHost>
<VirtualHost 172.16.106.163:80>
ServerName digiport.iserver
ServerAlias www.digiport.iserver
DocumentRoot "F:/xampp/htdocs/digiport"
</VirtualHost>
This is an example of what I need to do:
<VirtualHost 172.16.106.164:80>
ServerName tzone.iserver
ServerAlias www.tzone.iserver
DocumentRoot "G:/public_html/tzone"
</VirtualHost>
This xampp server is a separate Windows7 (64bit) system in our network with windows Active Directory resolving DNS issues inside our VLAN (I will downgrade it to 32bit this weekend).
My hosts file resolves ip#'s to domain names in the server, the NIC is assigned with multiple IP #'s so it does work everywhere on our VLAN.
Any insight will be much appreciated.
If you want to sort of "span" the drive, Windows has this handy feature (similar to linux's symlinking) called mklink which you can create a folder in the current directory that is just a symbolic link to the drive. Quick and easy way to span it. I am not sure of any downsides to do doing this, other than if the drive letter changes (if external drive).
That way you should not have to add or change any of your paths in the config etc. Not sure if that is what you were looking for, but hopefully it helps.
Also, did you try your 3rd config you pasted? Did it not work? From what I can see, as long as permissions are fine it should work that way.
Perhaps an issue with permissions in the network?
Not sure if it makes a difference, but maybe worth trying to add this to your 3d cfg:
<Directory "G:/public_html/tzone">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>

Running Rails applications with Passenger alongside PHP applications

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.

Categories