1

I have a yii2 basic template working fine in local, but when I uploaded files on server it is not working.

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();

when I open URL http://iicose.com/mlm/web/index.php it gave me following error

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

I figured out that it is causing because of using __DIR__ when I removed this the file loaded. But further I have to change everywhere in the vendor directory according to it which I think is not a good practice.

Can someone tell me a fix to this.

EDIT: This question is duplicate of Unexpected character in input: '\' (ASCII=92) state=1

Community
  • 1
  • 1
ankitr
  • 5,992
  • 7
  • 47
  • 66
  • 1
    What's the PHP version on production server? Seems like it's older version without namescaces support. Check this question. http://stackoverflow.com/questions/17156251/unexpected-character-in-input-ascii-92-state-1 – arogachev Feb 06 '15 at 05:20
  • @arogachev Great help. I have PHP version >5.3.0 thats why its happening. If there is a way to solve this issue without changing PHP version (if possible). – ankitr Feb 06 '15 at 05:41
  • Did you mean lower than `5.3.0` on production server? Yii 2 requires PHP 5.4, so you must have at least this version on both development and production servers to get it working. – arogachev Feb 06 '15 at 05:46
  • Glad to help, I issued that as an answer. – arogachev Feb 07 '15 at 08:00

1 Answers1

1

Seems like you are using older version of PHP (without namescaces support) on production server. Check this related question.

Yii 2 requires at least PHP 5.4, so you must have at least this version on both development and production servers to get it working.

Community
  • 1
  • 1
arogachev
  • 33,150
  • 7
  • 114
  • 117