Configure Slim Framework and Apache 2

Asked

Viewed 1,229 times

1

Hello, good afternoon.

I recently hired a linux hosting service. My site uses the Slim Framework, but I’m not able to access its routes when it’s in production, but in the xampp localhost, it was working normally.

Slim routes for testing (not entering 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 slim) and the . htaccess file

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

tested different codes. htaccess sometimes gave error 404 and other error 500. Currently as above code, gives error 500.

And if you 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 someone help me?

http://oi67.tinypic.com/2aak775.jpg

inserir a descrição da imagem aqui

  • If the problem is with the Rewrite URL you can try using it like this: index.php/teste, for example. That’s what I did.

  • 1

    @Nottherealhemingway hi, where I should put index.php/test?

  • Take a look at my answer.

1 answer

1

First:

You can use the routes no rewrite URL.

According to the documentation, you can access so:

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

If the path 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 the rewrite mod. Thus, the .htaccess must be in the same folder that 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 specifications of the documentation (it is the same!).

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

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

If ero comes up with PHP 5.5. *, then, the solution can be to uncomment the following line into httpd.conf:

LoadModule rewrite_module modules/mod_rewrite.so

The solution may still be in adding

RewriteBase /raizdosite/

to your project.

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

  • o . htaccess and index.php are in the same folder. This code you passed I already tested tb gave the same thing.

  • I can’t see your image. The Mgur is blocked in my work.

  • I tried to use /index.php/test/ in slim ... For example the url meusite.com.br/test/ , did not give tb.

  • http://oi67.tinypic.com/2aak775.jpg try this link. In this case it is to show that there is no httpd.conf file, if you need to create one and enable Allowoverride All.

  • Remove the bar after /index.php/teste/. Use only /index.php/teste. I’ll be able to elaborate better only when I get home at night. I’m sorry!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.