I am having a bit of a strange problem with an artisan command I have setup.
The command is:
cd /var/sites/p/mydomain.co.uk/public_html/ && /usr/bin/php-5.4 artisan property:import
This command works perfectly when run via ssh or on a local machine, but fails to run when set as a CronJob and returns the following error in the Laravel log file.
[2014-06-17 13:50:06] production.ERROR: exception 'InvalidArgumentException' with message 'There are no commands defined in the "property" namespace.' in /var/sites/p/mydomain.co.uk/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php:514
Stack trace:
#0 /var/sites/p/mydomain.co.uk/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(548): Symfony\Component\Console\Application->findNamespace('property')
#1 /var/sites/p/mydomain.co.uk/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(188): Symfony\Component\Console\Application->find('property:import')
#2 /var/sites/p/mydomain.co.uk/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(121): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /var/sites/p/mydomain.co.uk/public_html/artisan(58): Symfony\Component\Console\Application->run()
#4 {main} [] []
I am rather stuck and have no idea why the "property" namespace would not be found when being run as a cron. When running the exact same command via ssh, it works perfectly, when running on a local machine, it works perfectly.
Would there be anything in artisan that is causing it not to load the app/start/artisan.php file when run as a cronjob at all?
Any help would be greatly appreciated. If you need any further details, let me know and I will provide what I can.
Thanks,
Joe
After a long time of checking and speaking with the hosting provider it turned out that running /usr/bin/php-5.4 was running the cgi version of php, changing this to /usr/bin/php-5.4-cli fixed the issue.
This would of course very depending on your hosting providers setup.
Related
I have a laravel command that contains a user entity. I wrote a migration to modify the user table. When running php artisan migrate, I get an error because the user entity does not match the database (because this migration will make those changes).
I suspect that this means that the migrate command's process includes setting up laravel commands. Is there a way I can run php artisan migrate and the laravel command code not run?
I'm running laravel 5.1 and php 7.1.
Edit:
I didn't post any code, because it's not even getting to the migration. Here is the error message (the command was php artisan migrate).
This may be helpful was well. This is in the laravel command class that is causing the error. I can comment it out and the migration runs fine. That would be annoying to do for production though.
$userRepo = $repositoryFactory->getRepository(User::class);
$this->defaultUser = $userRepo->find(3000);
I just thought I should also include part of the stack trace that is in the laravel log file for this error.
#0 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(176): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
#1 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(150): Doctrine\DBAL\DBALException::wrapException(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'An exception oc...')
#2 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(915): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'SELECT t0.user_...', Array)
#3 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(712): Doctrine\DBAL\Connection->executeQuery('SELECT t0.user_...', Array, Array)
#4 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(730): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load(Array, NULL)
#5 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(462): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadById(Array)
#6 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php(154): Doctrine\ORM\EntityManager->find('...', Array, NULL, NULL)
#7 /project-path/Emailer.php(53): Doctrine\ORM\EntityRepository->find(3000)
#8 /project-path/QuoteStaleEmailer.php(25): Emailer->__construct(...)
#9 [internal function]: QuoteStaleEmailer->__construct(...)
#10 /project-path/vendor/laravel/framework/src/Illuminate/Container/Container.php(780): ReflectionClass->newInstanceArgs(Array)
#11 /project-path/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('...', Array)
#12 /project-path/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Servi...', Array)
According to Laravel 8 documentation , before renaming a column/table, ensure that you have installed the doctrine/dbal library via the Composer package manager.
Please run composer require doctrine/dbal to install
I came up with a decent work around. I don't know the correct terms to describe it, but looking at the stack trace, laravel sets up containers during a php artisan command. That includes containers for laravel command.
$this->defaultUser = $userRepo->find(3000) line was in the constructor, which meant it ran when the containers are setup. This causes an error because, the database for the user does not match the app setting for the user (because the migration hasn't run yet).
I moved the line to the getter function instead and set the default user there if it's empty, which isn't used when setting up the containers.
I tried installing laravel-websockets v2 and this error popped up when trying to migrate the tables. you need to install "doctrine/dbal" into your project and then run the migration
run composer require doctrine/dbal
run php artisan migrate
I have a very specific configuration that I have to hold until I can start moving feature from my old PHP 5 application to somewhere else.
I'm trying to tie my testing environment with PhpStorm but I cant figure it out. Since I'm not using Composer, I have to specify phpunit.phar path (which is /usr/local/bin/phpunit - a symlink to /usr/local/bin/phpunit.phar). I keep having this error.
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Cannot create phar '/usr/local/bin/phpunit', file extension (or combination) not recognised or the directory does not exist' in /opt/.phpstorm_helpers/phpunit.php:181
Stack trace:
#0 /opt/.phpstorm_helpers/phpunit.php(181): Phar->__construct('/usr/local/bin/...')
#1 /opt/.phpstorm_helpers/phpunit.php(250): IDE_PHPUnit_Loader::init()
#2 {main}
thrown in /opt/.phpstorm_helpers/phpunit.php on line 181
The setup on my Docker is
PHP 5.5.9 with PHPUnit 4.8.9
My remote Docker PHP interpreter works in PhpStorm, and my PHPUnit works when I run test in bash (using docker exec phpunit) - so it seems that the pieces are working, mostly the glue doesn't work.
Here are my settings
I just ran into this problem with composer and the issue is you need to set up a PHPUnit interpreter in PHPStorm with the autoload.php file.
Open Settings > Languages & Frameworks > PHP > Test Frameworks
Click the Plus + icon to add a Remote Interpreter
Select the CLI interpreter previously defined and use existing path mappings
Select Use Composer Autoloader
Path to script should be /path/to/vendor/autoload.php
Check off Default configuration file and set it to /path/to/phpunit.xml
I also needed to have the following section in my docker-compose.yml:
services:
my-api:
# Other contents omitted
environment:
- PHP_IDE_CONFIG=serverName=my-api.company.com
Where my-api.company.com is the server definition name from Settings > Languages & Frameworks > PHP > Servers
I've got a test suite in yii2 that I would like to run, I have installed composer, codeception, built the test with 'codecept build' and so far so good, everything was smooth as butter until I've issued the command 'codecept run'; it throws an error which by any means I have tried to figured out unfortunately unsuccessfully. I have reinstalled composer, clear the composer cache, rebuilt the project again with codecept build but not success whatsoever.
The error is as follows:
MyApp\tests.functional Tests (4) -----------------------------------------------------------------
- HomeCest: Check open<pre>PHP User Error 'yii\base\ErrorException' with message 'Exception 'yii\base\InvalidParamException' with message 'The file or directory to be published does not exist: /home/user/GIT_MyApp/yii/myapp/vendor/bower/jquery/dist'
in /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php:453
Stack trace:
#0 /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetBundle.php(185): yii\web\AssetManager->publish('/home/angelo/GI...', Array)
#1 /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php(268): yii\web\AssetBundle->publish(Object(yii\web\AssetManager))
#2
/home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php(239): yii\web\AssetManager->loadBundle('yii\\web\\JqueryA...', Array, true)
.....
.....
The weirdest thing though, is that the same project runs fine in another machine (CENT OS). Mine is Kubuntu 16.04. Could it be the machine?
Could someone please tell me what is happening and why this error keeps on coming?
You have to install fxp/composer-asset-plugin with composer globally:
composer global require "fxp/composer-asset-plugin:~1.3.1"
Like here: https://github.com/yiisoft/yii2-app-basic/blob/2.0.12/.travis.yml#L20
I upgraded from Symfony 3.1.5 to 3.2.0 yesterday morning and everything was fine up until an hour or so ago.
Now Symfony throws the following exception upon any type of access, including console commands:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service "session.storage.metadata_bag" has a dependency on a
non-existent parameter "session.metadata.storage_key".
I have tried the following:
Backed out my most recent changes
Deleted var/cache/*
Here is the exception trace:
Exception trace:
() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:100
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php:56
Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:217
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveString() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:187
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:177
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php:39
Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass->process() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:120
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:565
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:484
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:116
Symfony\Component\HttpKernel\Kernel->boot() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:122
Symfony\Component\Console\Application->run() at /Volumes/Data01/Projects/Beck/WWUI/site/bin/console:29
As you can see, it's part of Symfony, and not my code.
I am at a loss.
Has anybody else seen this?
Suggestions?
Edit 1:
Based on Dagon's suggestion that I check session.xml, and seeing that it appears correct, I decided to replace the
<argument>%session.metadata.storage_key%</argument>
tag with
<argument>_sf2_meta</argument>
in session.xml. This resulted in a new, similar error:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service
"64e3c91c625381e3c2c0184cf9ea0c6d5353986d77aa111949ca6fb8b17a8f07_2"
has a dependency on a non-existent parameter "validator.mapping.
cache.prefix".
This isn't really an answer per-se, but is is a fix.
I renamed vendor to vendor-HOLD and then ran composer install. Problem gone.
I did a diff on the old and new session.xml files and found that the definition of the parameter was different. The version causing the error contained:
<parameter string="session.metadata.storage_key">_sf2_meta</parameter>
The newly installed version contained:
<parameter key="session.metadata.storage_key">_sf2_meta</parameter>
instead. Obviously other files were incorrect, as well, based on the experimental edit I did to session.xml. No clue as to what happened, but it's nice that composer install fixed it. Oh, and yes, I deleted vendor-HOLD afterwards.
ZFTool is the maintenance tool for Zend Framework applications. There are several ways to install it. I use it from a PHAR file.
$ mkdir -p /usr/lib/ZendFramework/zftool
$ cd /usr/lib/ZendFramework/zftool
$ wget http://packages.zendframework.com/zftool.phar
$ ln -s /usr/lib/ZendFramework/zftool/zftool.phar /usr/bin/zf
$ chmod 755 /usr/bin/zf
It works, when I execute the tool outside of a ZF application. But now I tried this whithin an application and get this error:
root#devvm:/usr/lib/ZendFramework/test# cd /path/to/application/ root#devvm:/path/to/application# zf PHP Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZFTool) could not be initialized.' in /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:175 Stack trace:
#0 /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('ZFTool')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /path/to/application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /path/to/application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php( in /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 175
Why does it happen? How to avoid this behavior?
It appears you need to install zftool into your project. user2900416 kind of hinted at this, but I think it is more correct to install zftool using composer like so for each project:
composer.phar require zendframework/zftool:dev-master
This solved it for me. It is discussed in an issue here: https://github.com/zendframework/ZFTool/issues/51
Check the case of the module.php file:
Make sure your **M**odule.php file is written with a capital M otherwise the file may not be found. This took me a day to bug test so I really hope I save someone the same trouble!
I got the same problem. This is what I did to fix it with 2 steps:
(1) Download ZFTool zipball as suggested by manual installation at http://framework.zend.com/manual/2.1/en/modules/zendtool.introduction.html.
(2) Unzip the zipball under your application's module/ directory with directory name as ZFTool/.
Then, the Module(ZFTool) has been installed in your application and can be initialized by either invoking
"zftool.phar create module ModuleName"
or
"zf.php create module ModuleName" where zf.php is in the zipball.
It looks REALLY stupid to copy the ZFTool module inside each application but I have spent days in trying to find a better one without any luck.n Hope someone can propose one.