用slim官方的範例創建一個最簡單的slim應用,伺服器用的是nginx報錯了。 php版本是5.6.30
......1", upstream: "fastcgi://127.0.0.1:9000", host: "test.laonianji.net"
2017/02/08 16 :14:14 [error] 26338#0: *6 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_CLASS), expecting identifier (T_STRING) or vLE (T_CLASS), orVA '{ ' or '$' in /data/www/test_laonianji_net/src/vendor/slim/slim/Slim/Container.php on line 149" while reading response header from upstream, client......
#nginx的設定檔用的是官方的,路徑和網域自己修改成正確的了
server {
listen 80;
server_name mydomain;
index index.php;
error_log /data/log/nginx/access/mydomain.error.log;
access_log /data/log/nginx/access/mydomain.acess.log;
root /mypath/src/public;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
}
index.php也是官方的程式碼。
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
~