搜尋

首頁  >  問答  >  主體

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_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();
~    
PHPzPHPz2753 天前739

全部回覆(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
  • 取消回覆