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 can I run curl as shell command line?
Those errors are happening on Linux, on my mac works.
The curl command transfers data to or from a network server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). It is designed to work without user interaction, so it is ideal for use in a shell script.
The shell_exec() function is an inbuilt function in PHP which is used to execute the commands via shell and return the complete output as a string. The shell_exec is an alias for the backtick operator, for those used to *nix.
Uses of cURL in PHPcURL is a PHP extension that allows you to use the URL syntax to receive and submit data. cURL makes it simple to connect between various websites and domains. Obtaining a copy of a website's material. Submission of forms automatically, authentication and cookie use.
The issue is that PHP
safe mode is on 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 issue:
php -dsafe_mode=Off test.php
I do not want to change the php.ini
but it could be a solution too.
shell_exec
tells the safe mode problem, but exec
just tell you an wrong message, hopefully I tried both exec
and shell_exec
.
Disable safe mode
in your php.ini file. Also check if you do have curl installed.
safe_mode = Off
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With