Laravel Artisan command for soap call "Class 'SoapClient' not found" - php

I have an artisan command where I do a soap call.
So I use the SoapClient
use SoapClient;
When I test run my command from an url like this:
Route::get('test-command', function() {
Artisan::call('updateRegisterLogs');
});
Everything works great!
Now when I try to run it with artisan on my linux server to test the command to create a cronjob I get the following error:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'SoapClient' not found
The weird thing is I even get this error when I try a simple php artisan to see a list of all my commands.
Why does my artisan break from this? My code works fine but artisan doesn't.

The PHP version and also the CLI ini file could be different from the web one and when running command with artisan you are using the php cli.
Check with
php -r "echo phpinfo();"
If your php cli has soap enabled.

Related

Laravel Artisan error: Target class does not exist

Once our Laravel app is deployed to hosting (AWS Elastic Beanstalk) it's impossible to run php artisan from the ssh command prompt. Every time results in the following error:
In Container.php line 879:
Target class [request] does not exist.
In Container.php line 877:
Class "request" does not exist
Even just running php artisan without any parameters results in the same error. Locally everything is fine.
Strangely AWS runs certain bash php artisan commands as part of postdeploy hooks which work fine during deployment (eg. artisan config:cache). They work fine, but even if I disable that bash script and try to run those commands manually via ssh after deploy, I get the same error. Very confusing.
It's as if there's something happening after deployment that's breaking php artisan.
We're running PHP 8.0.18 and Laravel 9.0.1. I've tried composer dump-autoload, but I still get the same error while that's running.
Where would be the right place to start looking for the cause of this error message?

Can't run Laravel Envoy with exec (works in command line but doesn't with Artisan::call)

I have an envoy script which I am triggering within Laravel Command.
php artisan proxy:update
public function handle() {
exec("envoy run update");
}
If I run this on command line as php artisan proxy:update, it works.
However if I run this inside my Laravel app as Artisan::call('proxy:configure'); it doesn't work.
In console whoami = vagrant; likewise in my command exec('whoami') is also vagrant.
If I change it to
$out = shell_exec('envoy run update');
dd($out);
In command-line it shows the output, but with Artisan::call(), it returns empty string.
What might be the issue for being able to use exec() with artisan command?
As far as I understand, php-fpm was blocking it. I tried using Symfony's Process instead of exec() and I was getting "terminated". Then I moved Artisan::call() to Artisan::queue() and it worked. I'd be happy to know if anyone has any other explanations.
Update:
I created a queue that is run by deployer user which has sudo privileges (normally www-data run my queues). Now it works perfectly.

Error while running artisan command from controller

while running below artisan command from controller works fine
Artisan::call('backup:run');
but why this is not working
Artisan::call('backup:run --only-db');
it throws error The command "backup:run --only-db" does not exist.
through CLI it works fine
php artisan backup:db --only-db
I believe what you wanted to do is.
Artisan::call('backup:run',['--only-db'=>true]);

Artisan make:controller Doesn't work and no error

I'm using Laravel 5.3.0 and it's running on a local server with Manjaro. I access the project folder trough ssh and I'm also using artisan trough SSH.
Everything runs fine, I run the server trough terminal:
php artisan serve --host 192.168.0.10 --port 80
And can acess the project trough browser.
But when I run this command:
php artisan make:controller ContatoController
or
artisan make:controller ContatoController
Nothing happens, it get's stuck, no message error after minutes. No controller is created.
Does anyone know how to solve this?
Here's what happened:
I was running artisan server and after that (on the same terminal) I was running the make:controller command.
The solution was:
1- Open linux terminal, run artisan server;
2- Open another terminal (or split window if you'r using Terminator) and use all commands you want.

Can't use shell_exec for laravel artisan command in live server

I am using shell_exec command to run my artisan commands in the background. But when I run shell_exec in production server.
The route code as follows
Route::get('/test/exec', function () {
echo shell_exec('php ../artisan migrate:status 2>&1; echo $?');
});
it throws me error as follows.
PHP Fatal error: Cannot redeclare class Illuminate\Support\Traits\Macroable in /var/www/production/bootstrap/cache/compiled.php on line 6109 255
But when I run the same command in my local I got the output.
Laravel versin - 5.1.46
php version - PHP 5.5.9
os version - ubuntu
14.04
These are same on both servers. Where things went wrong. Please, some one helps me with this.
For this error try to run the following commands:
php artisan clear-compiled
php artisan optimize
this should regenerate compiled.php file.
As for executing artisan commands from within your code there are better ways than using shell_exec - for example using Laravel build in support for programmatically executing commands
The error
% Cannot redeclare class %
also occurs when you inject a class that has the same name as the one you are actively editing/modifying.
In your case, please make sure that you have not injected a class with the name "Macroable" elsewhere. If you have, make sure that the namespace is unique.

Categories