Welcome! Log In Create A New Profile

Advanced

NGINX and Slim PHP framework

Ben
October 22, 2016 06:38AM
Hi,

nginx/1.10.0 & PHP 7.0.8

I'm struggling to get NGINX to work with the Slim PHP framework for paths.

The base index.php works fine (e.g. http://example.com works), however
if I try a framework path (e.g. http://example.com/hello/test), NGINX
sends me what Firefox seems to call a "DMS file" (if I download and open
it, it displays the source code from the PHP file).

My NGINX config looks as follows:

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/bobs/public;
index index.php;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args =404;
}
location ~ ^(.+\.php)(.*)$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}

And my SLIM index.php :

<?php
require '../vendor/autoload.php';

// instantiate the App object
$app = new \Slim\App();

// Add route callbacks
$app->get('/', function ($request, $response, $args) {
return $response->withStatus(200)->write('Hello World!');
});
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");

return $response;
});

// Run application
$app->run();
?>

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

NGINX and Slim PHP framework

Ben October 22, 2016 06:38AM

Re: NGINX and Slim PHP framework

Edho Arief October 22, 2016 06:44AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 211
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready