I need to run some scripts written in PHP in a Rails app through some JS ajax calls. I am having a cross-domains issue where my scripts are active on localhost/scripts and my app is active on localhost:3000/myapplication. Ajax requests to localhost return a cross domain error.
I was able to implement the jsonp workaround, and it works fine but I would ideally like to access the php file from within the rails folders. I read that its possible to configure the apache server to enable PHP on a folder within the framework. I am running Apache2 on Linux.
Attempted solution I'm not 100% sure where to find the .htaccess file, so I just made one in the directory (public/php-scripts). Not sure if that works though...
Attempt 2: I can't seem to configure my server correctly: I installed all the passenger components and modified my file as so: /etc/apache2/sites-available/default
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.1.3
PassengerRuby /usr/bin/ruby1.8
<VirtualHost *:80>
ServerName myservername
DocumentRoot /var/www/myapp/public
<Directory /var/www/myapp/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
And I restarted the server. What am I missing ? I navigate to myservername/ and myservername/myapp and get a Forbidden message
Have you tried passenger with apache.
This should help you.
http://www.abletech.co.nz/blog/serving-php-from-a-rails-app-with-passenger
key to this is to disable the Passenger for a specific route.
This works for me
Put this lines in /etc/apache2/sites-available/default or /etc/apache2/httpd.conf file (I am not an expert at server configuration so decide one, I had this in httpd.conf)
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.1.3
PassengerRuby /usr/bin/ruby1.8
<VirtualHost *:80>
ServerName myservername
DocumentRoot /var/www/myapp/public
<Directory /var/www/myapp/public>
Allow from all
Options -MultiViews
</Directory>
# route for php app im my example /blog
Alias /blog /var/www/blog
<Location /blog>
PassengerEnabled off
</Location>
</VirtualHost>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With