luyadev / luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.
https://luya.io
MIT License
811 stars 205 forks source link

Run luya command on shared hosting via php shell #1856

Closed Saraylu closed 5 years ago

Saraylu commented 6 years ago

I use p0wny-shell for executing luya commands lik luya import & . . . in Shared Hosting

Received error: Uncaught yii\base\InvalidConfigException: Unable to determine the entry script file path. in /home/x/public_html/vendor/yiisoft/yii2/web/Request.php

[20-Sep-2018 23:00:56 UTC] PHP Fatal error:  Uncaught yii\base\InvalidConfigException: Unable to determine the entry script file path. in /home/x/public_html/vendor/yiisoft/yii2/web/Request.php:850
Stack trace:
#0 /home/x/public_html/vendor/yiisoft/yii2/web/Request.php(801): yii\web\Request->getScriptFile()
#1 /home/x/public_html/vendor/yiisoft/yii2/web/Request.php(773): yii\web\Request->getScriptUrl()
#2 /home/x/public_html/configs/env-local.php(17): yii\web\Request->getBaseUrl()
#3 /home/x/public_html/configs/env.php(8): require('/home/x/...')
#4 /home/x/public_html/vendor/luyadev/luya-core/base/Boot.php(136): require('/home/x/...')
#5 /home/x/public_html/vendor/luyadev/luya-core/base/Boot.php(175): luya\base\Boot->getConfigArray()
#6 /home/x/public_html/vendor/luyadev/luya-core/bin/luya(35): luya\base\Boot->applicationConsole()
#7 {main}
  thrown in /home/x/public_html/vendor/yiisoft/yii2/web/Request.php on line 850

luya-core/bin/luya:

#!/usr/bin/env php
<?php

// loaders array
$loaders = [
    'vendor/autoload.php',
    __DIR__ . '/../vendor/autoload.php',
    __DIR__ . '/../../vendor/autoload.php',
    __DIR__ . '/../../../autoload.php',
];

// find vendor if exists
foreach ($loaders as $file) {
    if (file_exists($file)) {
        require($file);
        $vendor = pathinfo($file, PATHINFO_DIRNAME);
    }
}

$boot = new \luya\Boot();
//$boot->configFile = 'configs/env.php';
$boot->configFile = __DIR__.'/../../../../configs/env.php';

$boot->setBaseYiiFile($vendor . '/yiisoft/yii2/Yii.php');
$boot->applicationConsole();
nadar commented 6 years ago

I never used p0wny shell, so i am not sure if or why this encounters this exception. Maybe this emulates a web proccess instead of a cgi process - not sure. What would: php_sapi_name() return inside this p0wny shell? Maybe this wont work in this case: https://github.com/luyadev/luya/blob/master/core/base/Boot.php#L70-L83

Saraylu commented 6 years ago

Notice: It looks like luya is using the same config for web and console. This is wrong, and should probably be reported as a bug to luya.


These results obtained through p0wny shell

var_dump(php_sapi_name()); Result: string(8) "cgi-fcgi"

php -v Result:

PHP 7.2.10 (cgi-fcgi) (built: Sep 14 2018 02:50:38)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.2.4, Copyright (c) 2002-2018, by ionCube Ltd.
    with SourceGuardian v11.2, Copyright (c) 2000-2018, by SourceGuardian Ltd.
Saraylu commented 6 years ago

Also already I have been debugged the boot.php code and in line 136 the error occurs .

nadar commented 6 years ago

I agree - i am going to fix this. if console application is requested, the sapi name should be used, this is only used if you want the application to decide by yourself with $boot->run()

nadar commented 6 years ago

try to install dev-master of luya core and check if it works now.

Saraylu commented 6 years ago

After updating only luya-core to dev-master on localhost, I replaced vendor/luyadev/luya-core directory from localhost to shared hosting.

Result: Error: Unable to determine the entry script file path. without any error_log

p0wny@shell:…/public_html/web# ../vendor/bin/luya

This is Yii version 2.0.15.1.

The following commands are available:

- asset                        Allows you to combine and compress your JavaScript and CSS files.
    asset/compress (default)   Combines and compresses the asset files according to the given configuration.
    asset/template             Creates template of configuration file for [[actionCompress]].

- cache                        Allows you to flush cache.
    cache/flush                Flushes given cache components.
    cache/flush-all            Flushes all caches registered in the system.
    cache/flush-schema         Clears DB schema cache for a given connection component.
    cache/index (default)      Lists the caches that can be flushed.

- fixture                      Manages fixture data loading and unloading.
    fixture/load (default)     Loads the specified fixture data.
    fixture/unload             Unloads the specified fixtures.

- health                       Health/Status informations about the Application itself.
    health/index (default)     Create all required directories an check whether they are writeable or not.
    health/mailer              Test Mail-Component (Use --verbose=1 to enable smtp debug output)

- help                         Provides help information about console commands.
    help/index (default)       Displays available commands or the detailed information
    help/list                  List all available controllers and actions in machine readable format.
    help/list-action-options   List all available options for the $action in machine readable format.
    help/usage                 Displays usage information for $action.

- import                       Import controller runs the module defined importer classes.
    import/index (default)     Run the import process.

- message                      Extracts messages to be translated from source files.
    message/config             Creates a configuration file for the "extract" command using command line options specified.
    message/config-template    Creates a configuration file template for the "extract" command.
    message/extract (default)  Extracts messages to be translated from source code.

- migrate                      Database Migration Too.
    migrate/create             @inheritDoc
    migrate/down               Downgrades the application by reverting old migrations.
    migrate/fresh              Truncates the whole database and starts the migration from the beginning.
    migrate/history            Displays the migration history.
    migrate/mark               Modifies the migration history to the specified version.
    migrate/new                Displays the un-applied new migrations.
    migrate/redo               Redoes the last few migrations.
    migrate/to                 Upgrades or downgrades till the specified version.
    migrate/up (default)       Upgrades the application by applying new migrations.

- module                       Command to create a new LUYA Module.
    module/create (default)    Create a new frontend/admin module.

- serve                        Runs PHP built-in web server.
    serve/index (default)      Runs PHP built-in web server.

Status: 500 Internal Server Error
X-Powered-By: PHP/7.2.10
Content-type: text/html; charset=UTF-8

Error: Unable to determine the entry script file path.

But when I changed line 20 of vendor/luyadev/luya-core/bin/luya from $boot->configFile = 'configs/env.php'; to $boot->configFile = __DIR__ . '/../../../../configs/env.php'; Result was:

p0wny@shell:…/public_html/web# ../vendor/bin/luya
Status: 500 Internal Server Error
X-Powered-By: PHP/7.2.10
Content-type: text/html; charset=UTF-8

and this error appeared in vendor/luyadev/luya-core/bin/luya/error_log file:

[21-Sep-2018 23:25:42 UTC] PHP Fatal error:  Uncaught yii\base\InvalidConfigException: Unable to determine the entry script file path. in /home/x/public_html/vendor/yiisoft/yii2/web/Request.php:850
Stack trace:
#0 /home/x/public_html/vendor/yiisoft/yii2/web/Request.php(801): yii\web\Request->getScriptFile()
#1 /home/x/public_html/vendor/yiisoft/yii2/web/Request.php(773): yii\web\Request->getScriptUrl()
#2 /home/x/public_html/configs/env-local.php(17): yii\web\Request->getBaseUrl()
#3 /home/x/public_html/configs/env.php(8): require('/home/x/...')
#4 /home/x/public_html/vendor/luyadev/luya-core/base/Boot.php(179): require('/home/x/...')
#5 /home/x/public_html/vendor/luyadev/luya-core/base/Boot.php(219): luya\base\Boot->getConfigArray()
#6 /home/x/public_html/vendor/luyadev/luya-core/bin/luya(25): luya\base\Boot->applicationConsole()
#7 {main}
  thrown in /home/x/public_html/vendor/yiisoft/yii2/web/Request.php on line 850
Saraylu commented 6 years ago

Notice that i use p0wny-shell on localhost and work with any issue. I guess the problem is from the Shared Hosting side

Saraylu commented 6 years ago

Notice: https://stackoverflow.com/questions/28339509/yii2-unable-to-determine-the-entry-script-file-path-change-php-server-environ


Edit: I'm almost sure that the problem is the Server API(SAPI). On my shared host php_sapi_name() return cgi-fcgi while we need cli. I'm now consulting with Shared Hosting Provider.

Thanks for your efforts

nadar commented 6 years ago

thanks for investigating. The p0wny shell will never run in cli mode, as its running trough the webserver. What does your config look like?

2 /home/x/public_html/configs/env-local.php(17): yii\web\Request->getBaseUrl()

3 /home/x/public_html/configs/env.php(8): require('/home/x/...')

The stack trace looks like it would open web request in env-local.php

Saraylu commented 6 years ago

Solved

yes, the issue was related to SAPI that the p0wny shell works in Fast/CGI mode. On almost Shared Hosting cli SAPI is not available. the only way to run LUYA command line tools is using Cron Jobs that will work in cli mode.

Cron Job example: /usr/local/bin/php /home/x/public_html/vendor/luyadev/luya-core/bin/luya

Very thanks @nadar & all friends to help me :)

nadar commented 5 years ago

But in the last commit, LUYA where not switching config based on SAPI name. So maybe i am gonig to try it as well. Bit if your issue is solved, we can close?

Saraylu commented 5 years ago

But in the last commit, LUYA where not switching config based on SAPI name.

before last commit and after it, my mistake was in debugging, that i changed config path file in vendor/luyadev/luya-core/bin/luya witch caused a the web request: from $boot->configFile = 'configs/env.php'; to $boot->configFile = __DIR__ . '/../../../../configs/env.php';

However I think it's better that when LUYA Command Tool called as a web request, suitable message throw out to end-user like "LUYA Command Tool only works in CLI SAPI"

@nadar my issue was solved, can close it. thanks for help :)