PHP and cURL work fine in a non-webfacing directory in my amazon EC2 micro install, 12.04.2 LTS (GNU/Linux 3.2.0-40-virtual x86_64).
I'm able to run some scripts on the command line using cURL:
#!/usr/bin/php
$command = '/absolute/path/to/running/process';
$url = 'http://example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 400);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
$resp = json_decode(curl_exec($ch), 1);
$data1 = round($resp["data1"], 6);
$data2 = round ($resp["data2"], 2);
curl_close($ch);
$c = array(
'var1' => trim(shell_exec($command)),
'var2' => trim(shell_exec($command)),
'var3' => trim(shell_exec($command)),
'var4' => number_format($data1, 6, '.', ''),
'var5' => number_format($data2, 0, '.', ',')
);
var_dump($c);
This works fine.
However, as soon as I put this same script in the web facing directory (I remove #!/usr/bin/php
obviously), the page loads (I can type echo 'Hello World!'
at the very top and see the text on a browser from a remote machine), but the page is entirely blank and adding echo
statements after curl
results in nothing. If I comment out the curl
function calls and try to simply execute the command, it seems to not work (The entire array of values is populated with NULL
or 0
.).
- What's going on with PHP? Why won't cURL run in the /var/www/ folder but runs fine everywhere else? I'm storing information to a database using cURL to get some JSON from public APIs.
- Why can't I use
shell_exec
to run a script as I normally could using PHP on the command line? - Errors aren't showing up in PHP even though
error_reporting(E_ALL)
is set. I can't find a log of errors by using locate to finderror_log
orphp.err
, which I thought were the default names for the php error log.
I feel like these two issues may be related, but I can't figure out why, maybe permissions? Something I noticed was that I cannot create or modify files in this directory without using the sudo
command, which isn't usual.
Another note: phpinfo() says nothing about cURL, but it works on the command line. I'm not sure why.