【问题标题】:Laravel 5.4 throws 500 error after fresh installLaravel 5.4 全新安装后抛出 500 错误
【发布时间】:2017-11-15 04:55:37
【问题描述】:

信息:

Php version 7.1

已安装所有扩展:

OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension

试运行:

composer dump-autoload
composer clear-cache
artisan clear:cache
 artisan config:Cache

错误日志中的错误:

PHP 解析错误:语法错误,意外的“类”(T_CLASS), 期望标识符 (T_STRING) 或变量 (T_VARIABLE) 或 '{' 或 '$' 在 /home/username/laravel/public/index.php 第 50 行

访问网站时:HTTP ERROR 500

有什么想法吗?

编辑 1:

public/index.php 的内容

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

?>

我是如何安装 laravel 的:

通过 SSH 登录到服务器。 cd /home/username/

// Download composer & install & unistall

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

// Download laravel

/opt/cpanel/ea-php71/root/usr/bin/php /home/username_here/composer.phar create-project --prefer-dist laravel/laravel

// Create soft link

rm -rf public_html
ln -s laravel/public/ public_html


// Change ownership permissions 

chown -R username_here:username_here /home/username_here/laravel
chown -R username_here:username_here /home/username_here/public_html

// Generate a key 

/opt/cpanel/ea-php71/root/usr/bin/php /home/username_here/laravel/artisan key:generate

服务器使用 MultiPHP 管理器,所以为了使用 php 版本 7.1,我必须使用选定的 php 版本 (/opt/cpanel/ea-php71/root/usr/bin/php)

【问题讨论】:

  • 您能否向我们展示您的 index.php 文件的内容并告诉我们您是如何进行全新安装的?
  • @JoffreyCarle 更新
  • 检查你的 php 版本,因为在 $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); ::class方法无法解决,我认为你的php版本> 5.1
  • @VaheGalstyan 通过命令opt/cpanel/ea-php71/root/user/bin/php -v 返回PHP 7.1.5
  • 能不能加var_dump(phpversion());die;在 index.php 文件的第一行并显示结果

标签: php laravel-5.4


【解决方案1】:

我的网络服务器使用我的旧 PHP 版本 5。尝试解决它

sudo a2dismod php5 须藤a2enmod php7.0 sudo service apache2 重启

【讨论】:

    【解决方案2】:

    解决方案是联系我的托管服务提供商并将 PHP 版本更改为 >= 5.6.4。

    【讨论】:

      【解决方案3】:

      您的 index.php 文件有问题

      require __DIR__.'/../bootstrap/autoload.php';
      

      在这一行中,您必须将此引导程序替换为供应商,因为 laravel 5.6 将自动加载文件存储在供应商文件夹中,而不是在引导程序文件夹中

      请删除引导程序并添加供应商并运行composer dump-autoload command,而不是尝试访问:)

      【讨论】:

        猜你喜欢
        • 2017-09-01
        • 2018-04-25
        • 1970-01-01
        • 2017-12-13
        • 1970-01-01
        • 1970-01-01
        • 2019-01-22
        • 2023-04-01
        • 1970-01-01
        相关资源
        最近更新 更多