在服务器上设置 yii2 基本应用程序

Set up yii2 basic application on server

我有一个 yii2 基本模板在本地工作正常,但是当我在服务器上上传文件时它不工作。

index.php

<?php

// comment out the following two lines when deployed to production
//defined('YII_DEBUG') or define('YII_DEBUG', true);
//defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/web.php');

(new yii\web\Application($config))->run();

当我打开 URL http://iicose.com/mlm/web/index.php 时出现以下错误

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/iicose/public_html/mlm/index.php on line 12

Parse error: syntax error, unexpected T_STRING in /home/iicose/public_html/mlm/index.php on line 12

我发现这是因为在删除加载的文件时使用了 __DIR__。但是我还必须根据它在供应商目录中的任何地方进行更改,我认为这不是一个好习惯。

谁能告诉我解决这个问题的方法。

编辑: 这个问题是重复的 Unexpected character in input: '\' (ASCII=92) state=1

您似乎在生产服务器上使用旧版本的 PHP(不支持命名空间)。检查 this related question.

Yii 2 requires 至少 PHP 5.4,因此您必须至少在开发和生产服务器上安装此版本才能使其正常工作。