helping php and ruby on rails coexist - php

I have a RoR app running on a server using Apache as the web server. I also have an instnace of moodle, an LMS based on PHP running. I have placed the web root of moodle inside the RoR space and for the most part it is working ok.
Inside moodle, if I go to sitename.com/moodle/my RoR intercepts that request and reports that it cannot find the page. If I go to sitename.com/moodle/my/index.php it works fine.
I tried creating a new virtual server but adding a second server running on 443 didnt work (the RoR based site is all under ssl).
Does anyone know of a way to tell RoR to ignore the moodle dir or get RoR to automatically detect and append the index.php to the path.

Me to had a same issue below is the apache2 config for the same kind of issue as describe below.
Example folder is the rails application folder and "/en/blog" are the folder path in public folder of rails application in which i had a wordpress install so below configuration allow's apache to turn off passenger for a request made to "http:/example.com/en/blog" so this request is not process by passenger and this request is service as a normal php request so i was able to have a wordpress blog and a rails application running on same server.
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/example/public
#RailsEnv production
<Directory /var/www/example/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
<Location /en/blog>
PassengerEnabled off
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /en/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /en/blog/index.php [L]
</IfModule>
</Location>

Related

How to get rid of index.php in url with Wordpress Rest API

I have correctly setup my site locally and everything works. However, when I deployed that to a blank EC2 instance, I see that wp-json (Rest API) does not work. It works only when I put an index.php in between. In other words
This works locally:
http://localhost/wordpress/wp-json
But I need to have this on the EC2 server to make it work.
http://A.B.C.D/wordpress/index.php/wp-json
On the server, I have installed apache2 and I have not messed up with the configs yet. I am familiar with wordpress but I not so much familiar with config tweaks on apache. I have also gone thru thousands of previously posted questions, but none of them seem to answer my problem.
First, you need to have by a2enmod rewrite in your terminal.
Then in your Apache Configuration file, make sure you have the following:
<Directory #Wordpress directory here#>
Options Indexes FollowSymLinks
AllowOverride All #allows .htaccess directives in the next step
Require all granted
</Directory>
Then make sure you have the following content in your root .htaccess file:
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L]

Apache rewrite not working on custom extension

I'm working on a PHP web app which will route every incoming request to the index.php same as WordPress or Joomla.
Following .htaccess is used to implement the feature.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
It is working on Wamp server [Windows] and IIS but when I migrate the app to the Ubuntu 16.04.02 [Apache 2.4.18, php7.0.18, Google Cloud Engine], it stops working for some custom extension file. It still working on normal php files thought.
I created a folder called service to put the web service php files and named the files as ****.svc.php and used with ****.svc url. It was working fine before but it is not on the Ubuntu and shown the following error.
Not Found
The requested URL /service/retrieve_opened_rs.svc was not found on this server.
Apache/2.4.18 (Ubuntu) Server at ******* Port 80
I believe this is the configuration issue but I still cannot figure out how to fix after 3 days. Please help me. Thanks in advance.
You probably have the Multiviews option enabled. This never behaves well along with rewrite rules, especially with "double" extensions like .svc.php
Add this at the top of your .htaccess file and that should take care of it:
Options -Multiviews
You might have to tweak your AllowOverride directive (from the main Apache conf) if you don't have the rights to modify Options from an .htaccess file.

Is apache serving only one application or are the PHP sessions being shared?

I am having trouble understanding what's happening in my scenario. Either apache is always serving the first virtual hosts files or the php sessions are being shared.
I'm attempting to create a DEV/QA environment on the same server and I'm using the Symfony2 framework (thankfully prod is on a standalone and is not affected by this). The reason I am not using the Symfony front controllers is because I'm using php deployer to deploy my verticals. I've created 2 directories:
/var/www/html/app1
/var/www/html/app2
and 2 virtual hosts:
app.domain:80 points to app1
app.domain:8080 points to app2
and 2 databases:
app_dev: blank
app_qa: copy of prod
App1 is my DEV where I can break things and I have full debug information showing. App2 is my QA where I have users test things.
Here is the behavior I observe after I restart apache:
If I browse to DEV after the apache restart I see data/code from DEV and everything works fine. Now if I open QA (whether in the same browser or another different browser) I still see the same data from DEV. Now if I restart apache again and browse to QA first this time I see data/code from QA. If I then open DEV it's still QA.
Why is that happening and how can I prevent this. I don't know if it's my apache configuration or if it's because the php sessions are being shared between the two hosts.
Virtual Host configurations:
App1:80
DocumentRoot /var/www/html/app1/current/web
ServerName app1.domain
<Directory "/var/www/html/app1/current/web">
AllowOverride None
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
App2:8080
DocumentRoot /var/www/html/app2/current/web
ServerName app2.domain
<Directory "/var/www/html/app2/current/web">
AllowOverride None
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
Usually, when you open use session_start(), you will generate a unique session_id to the client if they do not have any session_id before. The session_id is store in the client cookie. By default, PHP stores the session data in the file.
Each cookie value has different scope. Some cookie value can share across subdomain, some cookies only work on specified directory.
I suspected that you set your session scope to work across subdomain so app2.domain and app1.domain session are shared.
You can change the scope of your session here.

How enable mode_rewrite in windows server 2008 r2 (with php installed)

i have windows server 2008(r2) and i installed php and mysql using with Web Platform Installer in that windows.
it seems everything is ok about php and mysql.
now i want to install http://www.phpfreechat.net/ in my server.
after installation i got this error :
mod_rewrite must be enabled server side and correctly configured. "RewriteBase" could be adjusted in server/.htaccess file.
as you know .htaccess file is for linux servers.
what this error mean and how can i fix it?
i think in my server php is working under iis and there is no appache in my serevr, so how can i bypass that error?
i changed the wwwroot permission to EveryOne with no help.
also when i open wwwroot with cuteftp i can not find any permission by right click on every file (properties)
EDIT:
there are some folders in that project like client - server - etc
in server folder .htaccess is like this :
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /path/to/phpfreechat/server
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<Limit OPTIONS GET POST PUT DELETE>
Order allow,deny
Allow from all
</Limit>
thanks in advance
mod_rewrite is for Apache servers. Here you can see how to use rewrite rules for IIS using the URL Rewriting Module.
You should really read this document on how to create new rewrite rules. I don't know whether it supports .htaccess or not, but I don't think so. Just follow the official documentation.

Remove the path part to access my website

I got a rather easy problem. How do I remove the path to my website called domain.com?
I've got a lampp server where I put one folder called "domain" in the htdocs folder and to access my website I need to write domain.com/domain instead of just domain.com. And when I write domain.com I come to the usual xampp website
There are a few options, but the easiest is probably using some URL rewriting given your current setup.
mod_rewrite in .htaccess
In your htdocs folder create a .htaccess file:
RewriteEngine On
RewriteBase /
# If the URL does not already exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# or directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/$1 [QSA,L,NC]
Virtual hosting with Apache
You could also edit your VirtualHost container in the Apache configuration to change the directory as well. If you are running XAMPP then I have previously written about using virtual hosts with it on my blog.
For example:
<VirtualHost *:80>
ServerAdmin name#domain.com
DocumentRoot c:\xampp\simonholywell.com\pub
ServerName simonholywell.localhost
<Directory c:\xampp\simonholywell.com\pub>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
A development server for teams (or individuals)
I have also written a large article on setting up a development or staging server for a team as well, which would be good reading if you are setting up such a system. It allows you to simply add a folder on the server and it is immediately available as a subdomain without any further configuration. This is something called mass virtual hosting.
You need to add a virtual host, check the apache name based virtual host documentation. If you're running on windows you could follow this guide, if you're on linux/unix you could try the following guide

Categories