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.
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
I solved it. It was pretty simple. It doesn't enough to restart xampp. I also had to quit xampp and re enter
Related
Windows 10 just released Anniversary Update today. Now you can use Ubuntu flavored bash command from Linux subsystem.
The question is: How to execute Windows10's Bash command from PHP?
I tried
<?php
exec('bash',$out1,$result1);
exec('ls -l',$out2,$result2);
var_dump($out1);
var_dump($result1);
var_dump($out2);
var_dump($result2);
It doesn't work. All $out are empty array, and both $results are 1.
Any idea?
Just found out that I can run web server directly from subsystem.
e.g.
$ sudo apt-get install apache2
$ sudo service apache2 start
Then put all web contents inside subsystem's directory located at %localappdata%\Lxss\rootfs
At this point I can execute bash script however I want.
You can not. Ubuntu on Windows is implemented as a different subsystem directly below the Windows Kernel. So it runs separate to normal Windows processes and can not interact with them. (At least that is how I understand it). But maybe you just have to use C:\Windows\System32\bash.exe as the command.
Bash is not meant to be used to run a server but you can run PHP-CLI on bash without an issue.
Instead of running the PHP script in Windows and then accessing bash it would be easier to create a command to run the PHP script directly in bash.
So you would run `bash.exe -c "php path/to/php-script.php"
https://blogs.msdn.microsoft.com/commandline/2016/10/19/interop-between-windows-and-bash/
on my local machine I execute the following:
exec('sudo nohup '.PHP_BINDIR.'/php '.ROOT.'/index.php controller=imports action=import id=12 > /dev/null 2>&1 &');
where "ROOT" is a constant with the complete path.
Everything works fine and the script is executed asyncronously with no problems.
When I run the same script on production environment (a bitnami LAMP stack running on AWS) instead: if I run it directly from the terminal it works, when I run it from php it doesn't.
I have nothing in the apache error_log and if I run it with shell_exec the returned value is NULL.
If I try to execute a different script from php (like exec('whoami')) it works, so I don't think is a permissions thing.
I also tried replacing php command with php-cli, nothing changes.
Hope someone can help.
Thanks in advance.
I've installed git-ftp onto my CentOS Server so that I can do deployments from an activeCollab installation running the ac_gitolite module.
Everything installed fine and the app lives at
/usr/local/bin/git-ftp
When I log into the server via ssh I can run git-ftp commands without the full path, but when attempting to use PHP to run commands with exec ie:
exec ("git-ftp --version 2>&1", $output);
I receive the following error:
sh: git-ftp: command not found
Is there an environment path I need to specify somewhere specifically for PHP, or what am I doing wrong?
The two options discussed in "command not found - error in exec() command" are:
One easy solution would be to put the full path of the git-ftp executable.
The other is to add git-ftp to the php server user's PATH.
I have trouble running wget through php exec or system functions. The configuration is with MAMP.
I successfully run basic commands like ('whoami', 'pwd', etc.).
I even changed the apache user to the root user and still nothing. In the error log it output "wget: command not found".
I can run with the terminal and it works fine. The wget is installed through Macports.
What should I do?
Regards!
From a terminal, run which wget, and use the full path in the call to exec/system.
I would like to ask if I can run a php without having installed a web server. Do I have to use the php like CGI and run my page via command line? And if so, what are the steps that I do I have to choose through the installation of php? I mean the preferences as CGI and the components after that step?
I installed the php 5.3.3 but is seems not working, I get several message that the php5ts.dll is missing and when I put that file in my ext folder other error messages appear. Are there any configuration files or steps that I have to use?
(is php 5.3.3 suitable for doing something like this?)
If I have to have a web server installed how can I run my php code through the command line?
You should normally be able to run a php file (after a successful installation) just by running this command:
$ /path/to/php myfile.php // unix way
C:\php\php.exe myfile.php // windows way
You can read more about running PHP in CLI mode here.
It's worth adding that PHP from version 5.4 onwards is able to run a web server on its own. You can do it by running this code in a folder which you want to serve the pages from:
$ php -S localhost:8000
You can read more about running a PHP in a Web Server mode here.
For windows system you should be able to run php by following below steps:
Download php version you want to use and put it in c:\php.
append ;c:\php to your system path using cmd or gui.
call $ php -S localhost:8000 command in a folder which you want to serve the pages from.
PHP is a normal sripting language similar to bash or python or perl. So a script with shebang works, at least on linux.
Example PHP file:
#!/usr/bin/env php
<?php
echo("Hello World!\n")
?>
How to run it:
$ chmod 755 hello.php # do this only once
$ ./hello.php
You can use these kind of programs to emulate an apache web server and run PHP on your computer:
http://www.wampserver.com/en/
http://www.apachefriends.org/en/xampp.html