404 New Install

Im having issues getting the routes to work. I just did new install of Slim Skeleton

when I go to localhost/newsite/public/users/1 I get 404.

Any suggestions on what to check?

I get no Apache errors. mod_rewrite looks to be good.
.htaccess seems to working fine

statusCode 404
error
type “RESOURCE_NOT_FOUND”
description “Not found.”

This is going to depend a lot on how you’ve configured your site, but I would expect that it’s available on http://localhost/users/1

Have you configured your routes to require a trailing slash?

Does it work if you try the site’s homepage?

What does the route pattern look like?

my apache public html dir is located /var/www/html

slim is located in /var/www/html/newsite

I have not “configured” anything.

I just did a composer install of slim skeleton

Which webserver are you using and how was it configured? Which skeleton are you using? The “official” Slim Skeleton doesn’t contain that route, so a 404 would be expected.

This is on a Linux Mint 19 machine.
Apache2 PHP7+

I have previously got Slim 4 beta going a LM17 machine. I will check my Apache settings against that. Im assuming it is a host path error.

The slim skeleton aside, on a fresh LM19 lamp stack install, composer, slim4, psr7. Did not work for me either. Still a 404.

As far as the slim-skeleton, in the app/routes.php has this:

return function (App $app) {
$container = $app->getContainer();

$app->group('/users', function (Group $group) use ($container) {
    $group->get('', ListUsersAction::class);
    $group->get('/{id}', ViewUserAction::class);
});

Looks like /users or /users/1 would work? Returns “Bill Gates” no?

If your routing script is located at /var/www/html/newsite then your Apache public HTML directory should be /var/www/html/newsite/public rather than /var/www/html (that’s what the name public is meant to imply) and the URL should be http://localhost/users/1 rather than http://localhost/newsite/public/users/1.

If you want something different, you need to tweak your configuration quite a lot. Perhaps you can put your files in a completely different location and make /var/www/html/newsite a symlink to wherever public is, or you can create an Apache Alias. In either case, I’m not sure whether Slim itself needs specific configuration.

I will work with adding a new vhost to Apache to see if that works. The odd thing is that from the machine that works, to the machine that does not, I do not see any difference in Apache config files.

I suggest a simple test to understand where the problem is
in skeleton public dir run the following command from bash

php -S localhost:8080 -t .

than click the link you should see your home page or an error msg
HTH

The problem I was having is solved here. Apache configuration. I did not have much luck with RewriteBase, but then again I did not give it much attention. I just changed the route parameter and it worked fine.

May you share Apache config? I’ve same problem here when doing new install

The Apache config located /etc/apache2 apache2.conf is only slightly changed. Your root public www directory changes from AllowOverride None to AllowOverride All

Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory

then you must go into the slim skeleton to /app/routes.php and change the path to reflect your directory structure.

$app->group(’/users’ … became $app->group(’/newsite/public/users’

$app->group('/newsite/public/users', function (Group $group) use ($container) {
    $group->get('', ListUsersAction::class);
    $group->get('/{id}', ViewUserAction::class);
})

http://localhost/newsite/public/users should display JSON result.

For production purposes you would need to configure Apache vhost. Having a long route path for every route is not preferable.

There is a library that helps to solve the basePath issue for Apache.

Feedback is welcome :slight_smile:

Hello,

You can use that $app->setBasePath(‘xxx’);