Yii2 console app - cookieValidationKey config errors - php

I have configured the cookieValidationKey inside my backend\config\main.php and frontend\config\main.php and removed it from common\config\main.php. But when I run php yii inside command line. I get this error.
Even before I set it inside to my backend config the error showed up when I used the command line.
$ php yii
Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\console\Request:
:cookieValidationKey'
in D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\base\Component.php:201
Stack trace:
#0 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\BaseYii.php(525): yii\base\Component->__set('cook
ieValidatio...', '9H2hvsco52yQ0N2...')
#1 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\base\Object.php(105): yii\BaseYii::configure(Obje
ct(yii\console\Request), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\di\Container.php(381): ReflectionClass->newInstan
ceArgs(Array)
#4 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('y
ii\\console\\Req...', Array, Array)
#5 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\\con
sole\\Req...', Array, Array)
#6 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\di\ServiceLocator.php(135): yii\BaseYii::createOb
ject(Array)
#7 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\console\Application.php(219): yii\di\ServiceLocat
or->get('request')
#8 D:\web\wamp64\www\html\royall.dev\vendor\yiisoft\yii2\base\Application.php(380): yii\console\Applicatio
n->getRequest()
#9 D:\web\wamp64\www\html\royall.dev\yii(27): yii\base\Application->run()
#10 {main}
Why is this happening? I did not have cookieValidationKey inside my console\config\main.php so it should not Popup this error.
I use windows and wamp-server but I tested it on an Ubuntu server and it's returning the same error.

That's because your console command combined all configs before executing the actual action. There are some config params which are invalid to console actions but useful to web requests. The solution is to remove these params before executing console actions.
Add the following line
unset($config['components']['request']);
before
$application = new yii\console\Application($config);
in file yii.
Because I run web server via vagrant, I didn't test if there's side effect to web app run via yii command.

Related

Magento2 not working after installation in windows

I have installed fresh magento 2.41 in windows with xamp. I have followed this tutorial to install.
After installation I am receiving this error An error has happened during application run. See exception log for details. while I am accessing either homepage or admin page.
I am accessing the magento site from this url http://mystore.magento.com/. If I access from localhost/magento241 it's showing 404 not found.
I tried to clear cache but it didn't worked.
Log Files are here :
1 exception(s):
Exception #0 (Exception): Warning: Use of undefined constant SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES - assumed 'SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\magento241\vendor\magento\framework\Encryption\Adapter\SodiumChachaIetf.php on line 40
Exception #0 (Exception): Warning: Use of undefined constant SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES - assumed 'SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\magento241\vendor\magento\framework\Encryption\Adapter\SodiumChachaIetf.php on line 40
<pre>#1 Magento\Framework\Encryption\Adapter\SodiumChachaIetf->encrypt() called at [vendor\magento\framework\Encryption\Encryptor.php:399]
#2 Magento\Framework\Encryption\Encryptor->encryptWithFastestAvailableAlgorithm() called at [vendor\magento\module-config\App\Config\Type\System.php:339]
#3 Magento\Config\App\Config\Type\System->cacheData() called at [vendor\magento\framework\Cache\LockGuardedCacheLoader.php:137]
#4 Magento\Framework\Cache\LockGuardedCacheLoader->lockedLoadData() called at [vendor\magento\module-config\App\Config\Type\System.php:281]
#5 Magento\Config\App\Config\Type\System->loadDefaultScopeData() called at [vendor\magento\module-config\App\Config\Type\System.php:207]
#6 Magento\Config\App\Config\Type\System->getWithParts() called at [vendor\magento\module-config\App\Config\Type\System.php:181]
#7 Magento\Config\App\Config\Type\System->get() called at [vendor\magento\framework\App\Config.php:132]
#8 Magento\Framework\App\Config->get() called at [vendor\magento\module-backend\App\Config.php:51]
#9 Magento\Backend\App\Config->getValue() called at [vendor\magento\module-backend\App\Area\FrontNameResolver.php:109]
#10 Magento\Backend\App\Area\FrontNameResolver->getFrontName() called at [vendor\magento\module-backend\Helper\Data.php:209]
#11 Magento\Backend\Helper\Data->getAreaFrontName() called at [vendor\magento\module-backend\App\Request\PathInfoProcessor.php:50]
#12 Magento\Backend\App\Request\PathInfoProcessor->process() called at [generated\code\Magento\Backend\App\Request\PathInfoProcessor\Proxy.php:95]
#13 Magento\Backend\App\Request\PathInfoProcessor\Proxy->process() called at [vendor\magento\framework\App\Request\Http.php:148]
#14 Magento\Framework\App\Request\Http->getOriginalPathInfo() called at [vendor\magento\framework\App\Request\Http.php:163]
#15 Magento\Framework\App\Request\Http->getPathInfo() called at [vendor\magento\framework\App\Request\Http.php:213]
#16 Magento\Framework\App\Request\Http->getFrontName() called at [vendor\magento\framework\App\Http.php:111]
#17 Magento\Framework\App\Http->launch() called at [generated\code\Magento\Framework\App\Http\Interceptor.php:23]
#18 Magento\Framework\App\Http\Interceptor->launch() called at [vendor\magento\framework\App\Bootstrap.php:264]
#19 Magento\Framework\App\Bootstrap->run() called at [pub\index.php:30]
</pre>
https://drive.google.com/drive/folders/1OJaik33qhQL-X3X26LhFJBtUrk4bU5Cm?usp=sharing
Please make sure you have installed the sodium PHP extension.
You can check that with php -i | grep -i sodium
On Windows
Add "extension=sodium" to php.ini (no quotes)
Copy php/libsodium.dll to apache/bin/
Restart Apache
This works for me works on Windows.
I changed my php version from 8.0 to 8.1 on my linux (centOS) web hosting and had to add the following line to the relevant php.ini showing in phpinfo():
extension=php_sodium.dll
Once I did this the problem was solved!

Deploy error with Laravel project on Shared Hosting (Uncaught RuntimeException: A facade root has not been set)

I'm deploying a laravel project into production enviroment on a shared host using FTP following this tutorial except the creation of the symbolic link beacuse I'm not using the local storage but ran into "Uncaught RuntimeException: A facade root has not been set" error.
Aditional info:
I tried with a new laravel project with the command composer create-project laravel/laravel project_name 9 and deployed without run it in my computer and got the same error, then I tested it on my computer and worked fine.
The host was configured to follow these route: /web/content, where is displayed the public files. I followed the tutorial routing and created a folder with project's name with all files except the public folder contents as showed in the tutorial but I got the error, so I thought that the structure was giving me the error so I rename the laravel public folder to content and now all files are inside in /web and still getting the error.
Server info: Linux/Apache/PHP-8
Development enviroment: Windows 10/XAMPP/PHP-8.1
For development testing I use php artisan serve rather than XAMPP
I've deployed the project in my personal Heroku and all is working fine, as an additional test, I've deployed the project via XAMPP on my computer following the same structure in the point 2 and works fine.
Checking the logs I got this:
Server Logs
[17-Jul-2022 18:40:36 America/Chicago] PHP Fatal error: Uncaught RuntimeException: A facade root has not been set. in /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:334
Stack trace:
#0 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/RegisterErrorViewPaths.php(18): Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac...', Array)
#1 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(626): Illuminate\Foundation\Exceptions\RegisterErrorViewPaths->__invoke()
#2 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(607): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths()
#3 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(538): Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\Exception\HttpException))
#4 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(444): Illuminate\Foundation\Exceptions\Handler->prepareResponse(Object(Illuminate\Http\Request), Object(Symfony\Component\HttpKernel\Exception\HttpException))
#5 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(363): Illuminate\Foundation\Exceptions\Handler->renderExceptionResponse(Object(Illuminate\Http\Request), Object(ParseError))
#6 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(427): Illuminate\Foundation\Exceptions\Handler->render(Object(Illuminate\Http\Request), Object(ParseError))
#7 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(115): Illuminate\Foundation\Http\Kernel->renderException(Object(Illuminate\Http\Request), Object(ParseError))
#8 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/content/index.php(51): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#9 {main}
thrown in /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 334
Laravel Logs
[2022-07-17 18:40:36] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [] is not defined. at /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:207)
[stacktrace]
#0 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(132): Illuminate\\Log\\LogManager->resolve(NULL, NULL)
#1 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(119): Illuminate\\Log\\LogManager->get(NULL)
#2 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(636): Illuminate\\Log\\LogManager->driver()
#3 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(275): Illuminate\\Log\\LogManager->error('syntax error, u...', Array)
#4 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(415): Illuminate\\Foundation\\Exceptions\\Handler->report(Object(ParseError))
#5 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(113): Illuminate\\Foundation\\Http\\Kernel->reportException(Object(ParseError))
#6 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/content/index.php(51): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#7 {main}
"}
[2022-07-17 18:40:36] laravel.ERROR: syntax error, unexpected token ")" {"exception":"[object] (ParseError(code: 0): syntax error, unexpected token \")\" at /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/symfony/finder/Finder.php:588)
[stacktrace]
#0 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/composer/ClassLoader.php(428): Composer\\Autoload\\includeFile('/mnt/stor2-wc1-...')
#1 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php(88): Composer\\Autoload\\ClassLoader->loadClass('Symfony\\\\Compone...')
#2 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php(65): Illuminate\\Foundation\\Bootstrap\\LoadConfiguration->getConfigurationFiles(Object(Illuminate\\Foundation\\Application))
#3 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php(39): Illuminate\\Foundation\\Bootstrap\\LoadConfiguration->loadConfigurationFiles(Object(Illuminate\\Foundation\\Application), Object(Illuminate\\Config\\Repository))
#4 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(239): Illuminate\\Foundation\\Bootstrap\\LoadConfiguration->bootstrap(Object(Illuminate\\Foundation\\Application))
#5 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(153): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#6 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(137): Illuminate\\Foundation\\Http\\Kernel->bootstrap()
#7 /mnt/stor2-wc1-dfw1/406060/2039643domain/web/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#8 /mnt/stor2-wc1-dfw1/406060/2039643/domain/web/content/index.php(51): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#9 {main}
"}
UPDATE
By curiosity, tried with Laravel 8 and all work fine, but with Laravel 9 don't and by project's requirements, I'm not allowed to downgrade the Laravel version.
Well I couldn't manage to solve the problem on Laravel 9, so the solution was to downgrade to Laravel 8, maybe the problem is the configuration on the host server.

Domain is currently unable to handle this request on a Laravel project

Whenever I try to access my app online I get the following error.
[the-domain] is currently unable to handle this request.
I'm currently lost and don't even know what the problem is I've replicated my local environment on my server and the problem still persists, probably something I'm missing.
Here is my current config.
Laravel 5.7
PHP 7.2.9
Heres the stack trace form laravel.log:
[2018-09-30 12:18:28] staging.ERROR: syntax error, unexpected '|', expecting variable (T_VARIABLE) {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\F$
[stacktrace]
#0 /var/www/avanzi/vendor/composer/ClassLoader.php(322): Composer\\Autoload\\includeFile('/var/www/invite...')
#1 [internal function]: Composer\\Autoload\\ClassLoader->loadClass('Illuminate\\\\Supp...')
#2 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(22): spl_autoload_call('Illuminate\\\\Supp...')
#3 /var/www/avanzi/vendor/composer/ClassLoader.php(444): include('/var/www/invite...')
#4 /var/www/avanzi/vendor/composer/ClassLoader.php(322): Composer\\Autoload\\includeFile('/var/www/invite...')
#5 [internal function]: Composer\\Autoload\\ClassLoader->loadClass('Illuminate\\\\Data...')
#6 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Database/DatabaseServiceProvider.php(35): spl_autoload_call('Illuminate\\\\Data...')
#7 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(572): Illuminate\\Database\\DatabaseServiceProvider->register()
#8 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(75): Illuminate\\Foundation\\Application->register(Object(Illumin$
#9 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(548): Illuminate\\Foundation\\ProviderRepository->load(Array)
#10 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(17): Illuminate\\Foundation\\Application->registerConfi$
#11 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(206): Illuminate\\Foundation\\Bootstrap\\RegisterProviders->bootstrap(O$
#12 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(162): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#13 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(146): Illuminate\\Foundation\\Http\\Kernel->bootstrap()
#14 /var/www/avanzi/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Ob$
#15 /var/www/avanzi/public/index.php(58): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#16 {main}
"}
NB: This works perfectly fine in my local environment with the same PHP and Laravel version.
So I finally got it figured out for my use case.
I had the right PHP version installed but haven't enabled the extensions required by Laravel yet, so to fix this I had to go to the php.ini file for my currently installed and active PHP version and enable those extensions, here is a list of the required PHP extensions for a Laravel 5.7 project.
PHP >= 7.1.3
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension
Ctype PHP Extension
JSON PHP Extension
With all these extensions installed your PHP configuration should be good to go.

Laravel Lumen PHPUnits [ReflectionException] Class command.laracasts.seed does not exist

I'm running a PHP project based on Laravel Lumen
Whenever I run my test suite (CodeCeption framework), I run the artisan command $this->artisan("db:Seed"); at the begining of each test (in the setup method) and I get the following error:
[ReflectionException] Class command.laracasts.seed does not exist
#1 /app/vendor/illuminate/container/Container.php:753
#2 /app/vendor/illuminate/container/Container.php:631
#3 /app/vendor/illuminate/container/Container.php:586
#4 /app/vendor/laravel/lumen-framework/src/Application.php:230
#5 /app/vendor/illuminate/console/Application.php:228
#6 /app/vendor/illuminate/console/Application.php:242
#7 /app/vendor/illuminate/support/ServiceProvider.php:267
#8 /app/vendor/illuminate/console/Application.php:147
#9 /app/vendor/illuminate/console/Application.php:70
#10 /app/vendor/laravel/lumen-framework/src/Console/Kernel.php:165
For information I don't get the error if I run one test class at a time, I only get it when I run a test suite.

Installation and using elasticsearch php client on Windows Xampp

I'm downloaded the elasticsearch-5.1.1.zip from the https://www.elastic.co/downloads/elasticsearch
Then download the Elastica A PHP client for elasticsearch via composer with this command
composer require ruflin/elastica:dev-master
Now i want to open and make a test. When i run this command
bin\elasticsearch.bat
i get this error: The syntax of the command is incorrect.
On the other side if i try to use Elastica A PHP client i get some errors like this:
Fatal error: Uncaught Elastica\Exception\Connection\HttpException:
Couldn't connect to host, Elasticsearch down? in
E:\xampp\htdocs\el\vendor\ruflin\elastica\lib\Elastica\Transport\Http.php:180
Stack trace: #0
E:\xampp\htdocs\el\vendor\ruflin\elastica\lib\Elastica\Request.php(171):
Elastica\Transport\Http->exec(Object(Elastica\Request), Array) #1
E:\xampp\htdocs\el\vendor\ruflin\elastica\lib\Elastica\Client.php(662):
Elastica\Request->send() #2
E:\xampp\htdocs\el\vendor\ruflin\elastica\lib\Elastica\Client.php(673):
Elastica\Client->request('twitter/', 'DELETE', Array, Array) #3
E:\xampp\htdocs\el\vendor\ruflin\elastica\lib\Elastica\Index.php(531):
Elastica\Client->request('twitter/', 'DELETE', Array, Array) #4
E:\xampp\htdocs\el\vendor\ruflin\elastica\lib\Elastica\Index.php(165):
Elastica\Index->request('twitter/', 'DELETE') #5
E:\xampp\htdocs\el\vendor\ruflin\elastica\lib\Elastica\Index.php(258):
Elastica\Index->delete() #6 E:\xampp\htdocs\el\index.php(40):
Elastica\Index->create(Array, true) #7 {main} thrown in
E:\xampp\htdocs\el\vendor\ruflin\elastica\lib\Elastica\Transport\Http.php
on line 180
My question is How can i work with elasticsearch-5.1? Where am i do wrong?
Regards.
https://www.elastic.co/guide/en/elasticsearch/reference/master/windows.html#windows
At the note said, you're missing JDK8 or later

Categories