Configure Slim Framework and Apache 2

1

Hello, good afternoon.

Recently I hired linux hosting. My site uses the Slim Framework, but I am not getting access to its routes when it is in production, but at localhost xampp, it was working normally.

Slim Routes for testing (not getting into any)

$app->group("/teste", function() {
    $this->get("/", function(Request $request, Response $response, $args = []) {
        return $response->write("deu");
    });

    $this->get("/:nome", function(Request $request, Response $response, $args = []) {
        return $response->write("deu ".$args['nome']);
    });
});

My question is whether .htaccess is correct.

Located in public_html / slim / library /

Here is the index.php (from the slim) and the .htaccess file

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

I tested different .htaccess codes sometimes giving error 404 and others error 500. Currently as above code, it gives error 500.

What if I need to create an httpd.conf file and enable AllowOverride All. And how can I do that?

You can see in the image with the project directory, the / etc / folder only has 2 files and a subfolder with the site name, which is empty too.

Could anyone help me?

link

    
asked by anonymous 09.01.2017 / 18:10

1 answer

1

First:

You can use routes without Rewrite URL .

According to the documentation, you can access as follows:

<?php
$app = new \Slim\Slim();
$app->get('/index.php/foo', function () {
    echo "Foo!";
});
$app->run();

If the route file is inside a folder called blog :

<?php
$app = new \Slim\Slim();
$app->get('/blog/index.php/foo', function () {
    echo "Foo!";
});
$app->run();

However, the team that developed the micro framework encourages the use of mod rewrite. That way .htaccess should be in same folder than index.php :

/path/www.mysite.com/
    public_html/ <-- Document root!
        .htaccess
        index.php <-- I instantiate Slim here!
    lib/
        Slim/ <-- I store Slim lib files here!

Your code is right according to the documentation specifications (it's the same!).

However, here is another example according to the "First Application Walkthrough" tutorial " in> :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

If the ero comes up with PHP 5.5. *, then the solution can be uncomment the following line in link :

LoadModule rewrite_module modules/mod_rewrite.so

The solution may still be in add

RewriteBase /raizdosite/

to your project.

You can also search the Apache log for the cause of the error.

    
09.01.2017 / 18:29