Include PHP folder in Rails application?

I need to run some scripts written in PHP in a Rails application through some ajax JS calls. I have a problem with cross domains where my scripts are active on localhost / scripts and my application is active on localhost: 3000 / myapplication. Ajax requests to localhost return a cross-domain error.

I managed to implement the jsonp workaround and it works fine, but I would ideally want to access the php file from the rails folders. I read that you can configure the Apache server to include PHP in the folder within the framework. I am running Apache2 on Linux.

Attempted solution I am not 100% sure where to find the .htaccess file, so I just made it in the directory (public / php-scripts). Not sure if this works though ...

Attempt 2: I cannot configure my server correctly: I installed all the components for passengers and changed my file like this: / 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 go to myservername / and myservername / myapp and get a forbidden message

+6
source share
2 answers

You tried the passenger using apache.

This will help you.

http://www.abletech.co.nz/blog/serving-php-from-a-rails-app-with-passenger

Key

consists in disabling the Passenger for a specific route.

It works for me

Put these lines in / etc / apache 2 / sites-available / default or / etc / apache 2 / httpd.conf (I am not an expert in server configuration, so solve one, I had it 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> 
+12
source

Here is my configuration for nginx server with php-fpm.

You need to add "disabled_enabled off"; in the php location block, so all php files inside / public will work fine.

 server { listen 80; server_name www.rails-site.com; root /var/www/rails_site/public; access_log logs/www.rails-site.com.log combined; passenger_enabled on; passenger_min_instances 10; rails_env production; client_max_body_size 150M; location ~ \.php$ { passenger_enabled off; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 
0
source

Source: https://habr.com/ru/post/919968/


All Articles