NGINX and Slim PHP framework
Ben
ben+nginx at list-subs.com
Sat Oct 22 10:37:50 UTC 2016
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();
?>
More information about the nginx
mailing list