Ruby Grape + Passenger + Apache - ruby

I am trying to setup by API server with
grape
passenger
apache2
I installed the gem "passenger" and ran
passenger-install-apache2-module
Placed the following in my "virtual host" configuration
ServerName api.website.com
LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-5.0.6/buildout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-5.0.6
PassengerDefaultRuby /usr/bin/ruby1.9.1
DocumentRoot /var/www/html/lib/api
But when I restarted the server and tried accessing it via the browser, I just see the folder listing.
What do I need to do different ?

I figured it out. I looked at how Sinatra was being deployed. I had to point the DocumentRoot to a folder "public" (or anything else). Although this folder had to exist in the same directory where my config.ru exists. And then all just worked.
My folder structure looks like this
/app
|- apis.rb
|- config.ru
\- public
virtualhost.conf
DocumentRoot ...../app/public
My solution seems to work. Although would love some explanation to it though :) Anyone has any insight into this ?
Thanks !

You have to point Passenger to a public dir because this allows it to first serve static files from that directory, and if no files were found request the app to process the request. This gives clear semantics for serving static files and performance gains.
request to /img.gif
public/img.gif exists => send it to user
----
request to /users.json
public/users.json doesnt exist =>
send request to app in public/..
So you have to point it to public dir even if you don't have anything in it

Related

Install Laravel on dedicated server's subfolder

So I am having an issue with pushing a Laravel app to production on a dedicated server's subfolder.
Server is run on Apache.
Url I want to push my app would be subdomain.domain.com/project
The structure of my dedicated server is
.cpanel
...
-laravel
-app
-vendor
-...
-public_ftp
-public_html
-folder
-contents of laravels public directory
-ssl
I know that in order not to expose my hidden files I am required to install it in a root directory, but this is not an option because I will be having multiple projects running under subdomain.domain.com/project-1, subdomain.domain.com/project-2 and etc... and all will have a separate laravel installation.
I need a hand in order to achieve that, can anyone give me some advice?
Managed to do it myself, the problem was when i was creating a symlink, so instead i just moved contents of my public directory to public_html/project-1/ and changed index.php path to /../../laravel/
The thing was that I have done it originally but I didnt expect that permissions for storage need to be manually set, that solved my issue and laravel works.
ALWAYS CHECK ERROR LOGS :)
You can place your separate folders in your subdomain with no problem.
The important thing is that you need to point the browser to public/ folder under your laravel projects.
You can create a .htaccess file with the command below in root folder of each project and perform a redirect.
Place the following command in your .htaccess file:
RedirectMatch ^/$ /public/

Cannot get site loaded with Apache on Mac

I'm running El Capitan and trying to get my website hosted locally for development with Apache (that came with the OS). I followed the instructions here exactly. I made an anthony.conf file and put the Directory text in there, I replaced the actual directory with /Users/anthony/dev/web/unfinished-asteroids/ and then placed my web files in there. I started apache and navigated for localhost/~anthony but I get the
Not Found: The requested URL /~anthony was not found on this server.
standard 404 error. When I navigate to localhost it works fine and I get the "It works" from the index.html that is located in /Library/WebServer/Documents, I even changed that index.html file and it works fine.
Any ideas why I'm not able to see my website using apache? All I did was download this github repository and place it in my unfinished-asteroids folder, the index.html is at the root.
So it looks like there are a couple of extra steps that you need to do. There isn't really anything too special about apache that comes with OSX, so your standard apache configurations will work. but to get Userdir (~username) working on El Capitan,this is what I had to do
Edit /etc/apache2/httpd.conf
on (or near) line 166, uncomment
loadModule userdir_module libexec/apache2/mod_userdir.so
then on line 493 uncomment
Include /private/etc/apache2/extra/httpd-userdir.conf
then edit file /etc/apache2/extra/httpd-userdir.conf
uncomment line 16
Include /private/etc/apache2/users/*.conf
then in /etc/apache2/users/anthony.conf
<Directory "/Users/anthony/Sites/">
Options Indexes MultiViews
Require all granted
</Directory>
then sudo apachectl restart
That should make http://localhost/~anthony point to your sites directory.
Logs are stored in /var/log/apache2
Now if all you want is web access to say your dev directory you can do something like this.. (don't make any of the changes listed above)
in /etc/apache2/other/ create a file called mydev.conf (name doesn't really matter, save it needs to end in .conf')
and put this in that file
Alias /dev /Users/anthony/dev/
<Directory "/Users/anthony/dev">
Options Indexes MultiViews
Require all granted
</Directory>
and reload apache (sudo apachectl restart)
then you will be able to access your dev folder at http://localhost/dev and should be able to access your page at http://localhost/dev/web/unfinished-asteroids/
you can adjust the paths at will above, just need to make sure that the user or group _www has access to it, and that paths in the alias and the directory match.

Running .rb Ruby file

What is needed to run .rb file in a web browser?
(My first day in ruby)
I have Apache server (I'm coming from PHP) with passenger. Terminal proof:
gundars#linuxr528:~$ apache2ctl -t -D DUMP_MODULES
passenger_module (shared)
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
I also have installed rails etc, Tried to make a quick app with rails and it worked fine.
Now I would like to simply open .rb file in browser, and it is prompting me to save it.
This is how it looks in my browser, the window on right side pops-up after clicking, it asks where to save it.
Entries, concerning Ruby and this file, are:
apache2.conf:
LoadModule passenger_module /home/gundars/.rvm/gems/ruby-1.9.3-p0/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /home/gundars/.rvm/gems/ruby-1.9.3-p0/gems/passenger-3.0.11
PassengerRuby /home/gundars/.rvm/wrappers/ruby-1.9.3-p0/ruby
virtual-hosts.conf
<VirtualHost *:80>
ServerName tictactoe.ruby.dev
DocumentRoot "/localhost/sandbox/RUBY/tictactoe/"
ErrorLog /var/log/rubyonrails2.log
</VirtualHost>
/etc/hosts
127.0.0.1 tictactoe.ruby.dev
So the question - What is needed to run .rb file in a web browser?
I thought it's what passenger was for...
STEPS TO RUN .rb SCRIPTS FROM APACHE:
Edit your apache configuration file (e.g., /etc/httpd/conf/httpd.conf). Update or create an AddHandler setting so that it includes ".rb", e.g.:
AddHandler cgi-script .cgi .rb
Create your ruby script (.rb). Make sure you have a shebang (#!) pointing to your ruby interpreter. Use the "which" command if you're not sure where ruby is.
#!/bin/ruby
puts "Content-type: text/html"
puts
puts "<html>"
puts "<body>"
puts "<h3>Hello</h3>"
Set proper ownership and execute permissions (x) on your .rb file so apache can execute it, e.g.:
-rwxr-x--- 1 apache apache 163 Nov 26 10:55 index.rb
That might be all you have to do. If your script still doesn't execute, the first troubleshooting step I would try is temporarily disabling SELinux (using setenforce 0).
First day? Try a Sinatra tutorial. It's easy to get something up and running quickly and then you can concentrate on learning the language a bit.
Ruby is a server-side language. What you need is for a process to intercept your request, route it to the correct Ruby file, execute it, and send the output to your browser. Luckily, somebody has done this for you, with Rack and Passenger.
Why you would want to do this instead of working within the Rails framework is beyond me.

Ruby app only works when Passenger is "disabled"

I have deployed a Sinatra application on an Ubuntu server using Apache and Passenger. Through some trial and error, I realize the app only works when the passenger module is disabled.
$ a2dismod passenger
After an Apache restart, the app runs as expected.
If I re-enable the module...
$ a2enmod passenger
...I see this warning upon Apache restart:
[warn] module passenger_module is already loaded, skipping
and the app stops working. Apache responds, serving the contents of the vhost's document root, but is not recognized by Passenger.
I'm glad my app works, but I'm not sure how to explain the reversed effect of enabling/disabling the passenger module.
I ran into the same problem: if you follow passenger installing instruction with this version of Apache you may actually tell Apache to load passenger twice.
Before adding the 3 famous lines to your Apache configuration file:
LoadModule passenger_module /usr/…/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p290/ruby
Check the configuration file apache2.conf for lines like these:
# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
If these lines do exists it means that on start your Apache server will include every *.conf and *.load file from /mods-available to /mods-enabled and than load them.
So if you run in the concerning warning message it means you are loading passenger module twice!
You can take advantage of this Apache feature going to /mods-available, looking for passenger.conf and passenger.load files and edit them instead of apache2.conf.
The ‘LoadModule passenger_module’ line goes into passenger.load, while the other 2 ‘PassengerRoot’ and ‘PassengerRuby’ lines go into passenger.conf.
Then restart your server and you’ll be fine.
More about this issue here: http://www.duccioarmenise.net/ruby-on-rails/warn-module-passenger_module-is-already-loaded/
This most likely means you've specified 'LoadModule passenger_module ...' twice. The first entry is somewhere not in passenger.conf, the second entry is in passenger.conf.

Error getting images to show up in Symfony 1.4.8

Note: It was tough deciding whether this belonged here or ServerFault, but it seemed like a programming problem, so if it's out of place, feel free to migrate it.
I downloaded the sandbox of Symfony 1.4.8 and copied the files to my webserver. Unfortunately, when I try to access /symfony/sf_sandbox/web/ (where I installed it), I get the following:
It seems like the images aren't showing. According to the text:
If you see no image in this page, you may need to configure your web server so that it gains access to the symfony_data/web/sf/ directory.
However, when I try to locate the folder referenced above, it does not exist:
sf_sandbox
web
css/
images/
js/
uploads/
frontend_dev.php
index.php
robots.txt
As you can see, there is no sf/ directory under web/. What am I doing wrong?
Note: I am installing this on Ubuntu 10.04 64-bit using Apache.
All the images are located in the Symfony source directory.
I would try creating a symbolic link in the web folder called sf pointed to the following:
lib\vendor\symfony\data\web\sf
It should have access to the needed images at that point.
This is done by indicating the right path in the Alias directive in your apache configuration:
# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080
# This is the configuration for your project
Listen 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
DocumentRoot "/home/sfprojects/jobeet/web"
DirectoryIndex index.php
<Directory "/home/sfprojects/jobeet/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf /home/sfprojects/jobeet/lib/vendor/symfony/data/web/sf
<Directory "/home/sfprojects/jobeet/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Just replace "/home/sfprojects/jobeet" with your project's path and it should work.
This page shows the apache config to set up a new project correctly.
There are also important security notes for your webapp.
Symfony Documentation
All you need to do is copy the whole sf folder to the web folder. In my case i copied c:\wamp\www\jobeet\lib\vendor\symfony\data\web\sf\ to c:\wamp\www\jobeet\web. Hope that makes sense

Resources