Skip to content
Advertisement

XAMPP server 404 Page Not Found

I am trying to reuse a php file for aa assignment. So the following line in index.php

require '.././library/Slim/Slim.php';

gives me the error message:

404 Page Not Found

The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our homepage at the link below.

the folder library is one step backward relative to the file index.php. The file is present and I believe the path is correct because when I change the line to

require '.././library/Slim/Slim2.php'; //file Slim2.php not present

I get this error message instead

Warning: require(.././library/Slim/Slim.php2): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/Julio/Temperature/api/index.php on line 6

Fatal error: require(): Failed opening required ‘.././library/Slim/Slim.php2′ (include_path=’.:/Applications/XAMPP/xamppfiles/lib/php’) in /Applications/XAMPP/xamppfiles/htdocs/Julio/Temperature/api/index.php on line 6

What’s wrong? Using a MAC

Advertisement

Answer

To expand on my comment, the error message you are receiving is one passed by Slim because it does not recognise the endpoint you are hitting.

So for example if you created your new Slim App instance with:

$app = new SlimApp;

$app->get('/', function ($request, $response, $args) {
    // Logic for the root path here.
}

The above is not the best way to go about doing it, really you want to extract routes to their own file.

The full Slim documentation can be found here: http://www.slimframework.com/docs/

Edit: Just noticed you are using Slim2, my above examples are in Slim3 so there are some differences, however the solution to your current 404 should be the same. You need to create a route to handle the page you want to view and ensure you have your front controller set up correctly.

Edit2: Quickly wrote out the below to see if I could help you out anymore, pretty busy at the moment so I don’t have enough time to go into this is any more detail. You should also be aware the below example set up is done in Slim3, and is very basic. There will be more optimal ways of setting up your folder structure, etc but this should give you a starting point. The main thing I would advise is to study some Slim Projects and the Slim documentation itself to get a good grasp of how the micro-framework works.

|- public
  |- index.php
  |- .htaccess
|- src
  |- ProjectName
    |- Routes
      |- example.php
    |- bootstrap.php
|- vendor

index.php

<?php 
// Pull in our bootstrap file.
require_once '../src/ProjectName/bootstrap.php';
$app->run();

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteCond %{REQUEST_FILENAME}% !-d
RewriteRule ^ index.php [QSA,L]

bootstrap.php

<?php 
require_once '../vendor/autoload.php';
$app = new SlimApp();
require_once 'Routes.php';

example.php

$app->get('/example/{name}', function ($request, $response, $args) {
    echo 'Hello ' . $args['name'];
}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement