1

I am trying to use the php fat free framework (aka F3), to quickly build a web application.

In theory (from reading the documentation), it should be a doddle (i.e. easy), however, I have been stuck on a single problem for days, and judging from similar questions here on stackoverflow, it seems I'm not the only one struggling with this issue.

Here are the salient facts:

  • I am using wamp server to run F3.
  • My F3 project resides under /location-to-wamp-folder/www/fatfree-master
  • I have setup a virtual host for Apache under wamp, so http://fatfree-master runs index.php

This is where the trouble begins. When I navigate to http/fatfree-master, I get the error which is the title of this question; namely:

Not Found

HTTP 404 (GET /) C:/wamp/www/fatfree-master/index.php:111 Base->run()

My index.php looks like this:

<?php  // <- surprisingly, I had to add this line to the index.php example provided by F3, was this an oversight or a deliberate design feature?

$f3=require('lib/base.php');

$f3->set('DEBUG',3);
$f3->set('UI','ui/');

....
// custom PHP code defining routes etc ...
....

$f3->run();  // barfs here

Now, I would be the first to admit, that I do not understand the arcane syntax of Apache rewrites, so I have left my .htaccess file as it was (when I downloaded F3).

Here are the contents of my .htaccess (the default file provided by F3):

# Enable rewrite engine and route requests to framework
RewriteEngine On

# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
# RewriteBase /

RewriteRule ^(tmp)\/|\.ini$ - [R=404]

RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

Can anyone explain to me, why I am getting the 404 error, and also how to fix it?

[[Additional Notes]]

I have two routes in my (edited) index.php file. My index.php looks like this now:

<?php

$f3=require('lib/base.php');
$f3->set('AUTOLOAD','app/controllers/');

$f3->set('DEBUG',3);
$f3->set('UI','ui/');

/* Tools */
$f3->route('GET @tools_calculator_dates: /tools/calculator/dates', 'Beer->list');

// Default route
$f3->route('GET /',
    function() {
        echo 'Hello, world!';
    }
);

$f3->run();

When I access / in my browser, I get "Hello, world!" (as expected) When I access /tools/calculator/dates in the browser, I get the following error:

Not Found

HTTP 404 (GET /tools/calculator/dates)

• C:/wamp/www/fatfree-master/index.php:119 Base->run()

Now, I have a class here: /path/to/wamp/www/fatfree-master/app/controllers/beer.php

The contents of the class are:

<?php_
  class Beer
  {
        function list() {
            echo "Beer::list() called!";
        }
  }

Why I am getting the 404 error?.

Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
  • That error was not thrown by Apache. F3 threw that, and so there is an issue with the routing setup... Your `.htaccess` is quite fine... What do your routes look like? – Mike Rockétt Feb 19 '15 at 14:30
  • And regarding their omission of ` – Mike Rockétt Feb 19 '15 at 14:33
  • @MikeAnthony: Thanks for your feedback. Regarding the routing, I also suspected it, so I deleted all my routing code from the index.php file, and left only the two statements (`require()` and `run()`) and I got the same error thrown up at the `$f3->run()` statement. The baffling thing is that there are no errors been generated by php or Apache, so I don't really know where the error is coming from. Since I'm running on windows, it also can't be a file permission problem. In short, I'm stuck... :( – Homunculus Reticulli Feb 19 '15 at 14:38
  • Well it will throw a 404 if you don't specify a route... Which is why I asked what routes you had in the file... – Mike Rockétt Feb 19 '15 at 14:40
  • @MikeAnthony, I see (obvious, now that I think of it!). At the moment, all of my routes delegate to custom classes (which don't exist yet - ala TDD). I will try a simple hello world type function mapped to '/' and see if the results are any different. – Homunculus Reticulli Feb 19 '15 at 14:47
  • @MikeAnthony, please submit your last comment as an answer. I have been a silly boy :). – Homunculus Reticulli Feb 19 '15 at 14:48
  • If you defined `GET /` to a non-existing class, I'm sure it would have specifically stated that the class does not exist. But, then again, I don't know F3 very well, and so can't be sure. Let's see what happens with your tests. – Mike Rockétt Feb 19 '15 at 14:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/71263/discussion-between-homunculus-reticulli-and-mike-anthony). – Homunculus Reticulli Feb 19 '15 at 14:53

2 Answers2

0

The error you're getting is not from Apache, it's from F3.

If you don't specify a route GET /, F3 will throw a 404.

Mike Rockétt
  • 8,947
  • 4
  • 45
  • 81
0

The 404 error could be caused by one of the following reasons:

  1. the route you're calling hasn't been defined
  2. the class or method against which the route has been defined cannot be found
  3. you're running the web app in a subfolder and for some reason, RewriteBase needs to be enabled

Concerning the point #1, see the documentation for details about route declaration.

Concerning the point #2, check out this answer if you're having trouble setting the framework's autoloader (AUTOLOAD variable).

Regarding the point #3: RewriteBase is usually optional when running in a subfolder, but in specific cases (for ex. when mod_userdir is enabled), it needs to be explicitly set.

So in your case, you could try to add the following directive in your .htaccess file, just after RewriteEngine On:

RewriteBase /fatfree-master/
Community
  • 1
  • 1
xfra35
  • 3,833
  • 20
  • 23