I get: -bas...">

How to run curl at shell command line in PHP?

If I try to run this inside a script:

<?php exec("curl http://ww.google.com") ?> 

I get:

 -bash-3.2$ php test.php sh: /curl: No such file or directory 

using shell_exec:

 PHP Warning: shell_exec(): Cannot execute using backquotes in Safe Mode... 

How to run curl on a shell command line?

These errors occur on Linux, it works on my Mac.

+4
source share
3 answers

The problem is that PHP safe mode is enabled, and it is better to use the full path to run cURL (thanks ghostJago and amosrivera). Running the script with the following command fixed the problem:

 php -dsafe_mode=Off test.php 

I do not want to change php.ini , but it could also be a solution.

shell_exec reports a safe mode problem, but exec just tells you the wrong message, I hope I tried both exec and shell_exec .

+5
source

Disable safe mode in php.ini file. Also check if you have curl.

 safe_mode = Off 
+3
source

at the command prompt, do the following:

 which curl 

This will give you the absolute path to the curl program.

Then double check that safe_mode = Off is in your php.ini.

When you do, change your code to:

 <?php exec("path/you/got/from/which/curl http://www.google.com") ?> 
0
source

All Articles