2

can we call artisan command using PHP exec or shell_exec or system function?

exec('php artisan list');

I have tried the above command in the controller but it is giving me an error saying 'Could not open input file: artisan' actually, I want to call another artisan command this just for testing

please guide me if am doing anything wrong here

6
  • seems to be something related to your php file permissions. If it's on a dev server, try chmod it to 777 to test. Commented Aug 11, 2021 at 8:53
  • 1
    ok, let me check Commented Aug 11, 2021 at 8:55
  • 3
    In a controller you say? The artisan file is located in the root folder of the project, meaning that you would need to use the relative path or the absolute path in order to reach the artisan file :) Commented Aug 11, 2021 at 8:58
  • good point zeppo, but I think that would say file not found. "Could not" to me seems like a permission issue. Can't test it as I dont have an environment handy right now. Commented Aug 11, 2021 at 9:05
  • True Oliver... I tried using exec('php artisan'); in one of my project and got the error "Could not open input file: artisan". However, when I used the absolute path, it worked fine. @sayyedtabrez, any progress? Commented Aug 11, 2021 at 9:12

1 Answer 1

1

The artisan file is located in the root folder of the project and you are trying to execute it from a controller in a different folder. Try using the absolute path or a relative path:

exec('php /path/to/rootfolder/artisan list');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.