Friday, 3 February 2017

php - Set up yii2 basic application on server



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



index.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


Answer



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.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...