1

Trying to execute aws cli commands with php shell_exec on local server (for tests). I'm using xampp, windows operating system, Laravel and php, I installed aws cli on windows.

Windows cmd recognizes the aws commands, but when I try to execute the aws command with shell_exec i get an error: "aws is not recognized as an internal or external command".

Tried this simple script:

$exec = shell_exec('aws --version');

$exec return null.

Appreciate any help.

1
  • It probably isn't found in the path. Try referencing aws via the full path. Commented Jan 1, 2020 at 23:49

2 Answers 2

1

if you can't run the command directly in shell_exec(), then what you can do is make a batch file with the command and place it on the root of your website. Then, just run:

<?php echo exec("script.bat"); ?>

also, make sure to put any environment variables needed and recommend to use full path for the aws executable

Sign up to request clarification or add additional context in comments.

2 Comments

I created this bat file: cmd /k "aws --version" when I run it on windows cmd it returns the expected response. But then I run it with exec function like this: $ecec= exec('C:\awsbat\first_simple_batch.bat'); $exec returns the php local path: "C:\\xampp\\htdocs\\php_project\\public>" How can I display the output?
can you replace aws with the full path of the aws command as I mentioned above
0

I solved it. It was pretty simple. It doesn't enough to restart xampp. I also had to quit xampp and re enter

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.