0

When I go to

http://localhost/api/auth/login

I get what I expect.. some data that lets me log in.

However, when I go to

http://myurl.com/api/auth/login

I just get

{
    "error": {
        "code": 404,
        "message": "Not Found"
    }
}

Currently we have 2 people working on this project, and both of us, when we run it from our local machines, have no issues. We're to the point where we are putting the app on to a hosted server so that we can start testing it outside of our own machines.

The code is identical, and I know this because we use a git repository in which the server is also pulling from.

My machine is a mac, my buddy's is a windows machine, and our host is a linux box. This shouldn't really matter, since all of them should work with mod_rewrite, a requirement for Restler 3.

The only other details I can think of is that the server is hosted by HostMonster, running PHP 5.4.7

Any help would be GREATLY appreciated. Do you need more information?

=== Edit: This is my .htaccess file. Also, the server runs CGI/FastCGI not mod_php

Options -MultiViews
DirectoryIndex index.php
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ index.php [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
    php_flag display_errors Off
</IfModule>

I just googled 'fastcgi mod_rewrite' and none of those links helped :P

JP.
  • 544
  • 5
  • 20
  • Is your `localhost` set to be the `www` root directory? – dbf Oct 28 '12 at 21:46
  • ? Can you elaborate on your question? That shouldn't matter right? Nowhere in my code do I reference 'localhost' But yes, the server's 'localhost' directory is www. I am getting JSON generated by Restler back, so I don't think it's an issue with it calling the scripts, it's an issue with the scripts doing the right thing, I guess. Basically, I expect JSON back, but this page in particular gives me a link to log in using Instagram { pagination:"instagramsurl.com" } Somethinglike that. Again, no issues on my local build, not sure if that helps. – JP. Oct 29 '12 at 00:11
  • Are you sure your host supports mod_rewrite? Sounds like your URL rewrites are not working properly. Are you using heredoc to instruct restler on what URL to map your function to? Try adding index.php to your request, you'll see what I mean. – Kevin Oct 29 '12 at 01:27
  • So I figured out that I'm running CGI/FastCGI instead of Apache 2.0 Handler as the Server API. The rewrites work. Well, at least, they redirect to index.php like their supposed to :P It's just the stuff after it that's not going through. I'll edit with my .htaccess file, and also keep in mind the CGI thing. – JP. Oct 29 '12 at 02:12
  • @J.P. My intuition says that your paths are being relative to the source of the scripts you are using, meaning scripts get included properly from `http://localhost/` due to `/var/www/`, but not when using `http://myurl.com` which could point to `/var/www/myprojekt/version1/etc/` (or any other) directory. And by the looks of your code given as a comment in the answer below, you are indeed using `require_once "../../etc";`. But you solved it, so doesn't matter ;) – dbf Oct 29 '12 at 10:36

1 Answers1

2

When ever you come across such issue first try without url rewriting

instead of

http://myurl.com/api/auth/login

try

http://myurl.com/api/index.php/auth/login

If it works you will know that the issue is with url rewriting

Since you are using CGI/FastCGI make sure you have set

cgi.fix_pathinfo=0

in your php.ini it will make sure that path info is passed to Restler properly so that restler can find the route

If it does not work with index.php in the url, you can try generating and verifying routes.php as explained below

routes.php

Restler looks at all api methods and its doc comments to generate routes accordingly every time we run it on debug mode. When we run it on production mode it captures the information in routes.php and uses it instead of generating routes every time thus improving efficiency.

You can check for the generated routes by initializing restler in production mode and refresh on every call

$r = new Restler(true, true); 

and then check the generated routes.php

If your routes.php contains no routes it will appear as follows

<?php $o = array();

// ** THIS IS AN AUTO GENERATED FILE. DO NOT EDIT MANUALLY ** 
return $o;

If this is your case, it means some how autoloader is failing to load the api class, you can confirm it by manually including the API classes

If it starts to work, please file a bug using github issues stating that the autoloader is failing for your server configuration and give us more detils so that we can reproduce it and fix it.

If it still does not work, please file a bug using github issues mentioning your server configuration and give us any detail that could help so that we can reproduce it and fix it.

Thaks to you, we will also write a trouble shooting guide based on above to help the restler community :)

Arul Kumaran
  • 983
  • 7
  • 23
  • I tried http://myurl.com/api/index.php/auth/login and it gave me the same 404 Restler error (which to me seems like it has redirected to api/index.php as expected, but Restler isn't working the Restler magic properly :P) I also tried uncommenting and setting the cgi.fix_pathinfo=0 That also doesn't seem to fix it :( The site is being hosted by Hostmonster, not sure if that helps any (maybe somebody here is familiar with some restrictions that I am not) – JP. Oct 29 '12 at 06:30
  • Hello Luracast! :) Thanks for helping me out on this. Ok, so I did what you said, and it generated the file in api/cache/routes.php but I don't know what to make of it. The file doesn't even look complete: – JP. Oct 29 '12 at 06:46
  • 1
    Restler looks at all api methods and its doc comments to generate routes accordingly every time we run it on debug mode. When we run it on production mode it captures the information in routes.php and uses it instead of generating routes every time thus improving efficiency. As I see the result there are no routes being added. Some how API classes are not auto loaded properly. Can you try manually including at least one api class? – Arul Kumaran Oct 29 '12 at 07:03
  • Manually adding? My index.php looks like this: addAPIClass('Auth'); $r->addAPIClass('Ballot'); $r->addAPIClass('Categories'); $r->addAPIClass('Duels'); $r->addAPIClass('Users'); $r->handle(); ?> --- apologies for the lack of newlines in comments. – JP. Oct 29 '12 at 07:36
  • 1
    Oh! I manually added an include for "auth.php" and it worked! Why would it require that on this server and not the others? Could it have to do with the CGI/FastCGI ?? – JP. Oct 29 '12 at 07:39
  • It could be due to file/folder permissions on your server are different from localhost – Arul Kumaran Oct 29 '12 at 07:52
  • I marked your answer as the best answer, even though the real answer for me was in the comments. Is that the right way to do this? – JP. Nov 01 '12 at 18:17
  • We have made it right by adding the steps above to the answer itself ;) – Arul Kumaran Nov 02 '12 at 03:43
  • When I try to view the routes, I get a fatal error: ``PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0?`` – user1429980 May 26 '15 at 21:03
  • @JP. your comment helped us find an issue that happens only on Windows machines. Restler 5.0.4 finally solved this issue – Arul Kumaran Jun 20 '21 at 16:10