slim+nginx访问报500错

浪人
  • 4
新手上路,请多包涵

用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_VARIABLE) or '{' 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();
~    
回复
阅读 4.3k
3 个回答

index.php文件最后的那个~是怎么回事?

根据错误提示是php文件语法错误。

php文件语法错误,去查看php的error.log看看
或者把php.ini里面的display_errors打开输出错误

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏