搜索

首页  >  问答  >  正文

php - slim+nginx访问报500错

用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();
~    
PHPzPHPz2807 天前774

全部回复(2)我来回复

  • PHPz

    PHPz2017-05-16 13:17:02

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

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

    回复
    0
  • PHP中文网

    PHP中文网2017-05-16 13:17:02

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

    回复
    0
  • 取消回复