PHP脚本仅在本地主机上起作用,而不在Amazon中起作用? [英] PHP script works only in local host,not in Amazon?
问题描述
我是一个非常初学者,因此请原谅我。
I am a very beginner so forgive me if its too basic .
我已经使用 MAMP
并且我有一个 index.php
文件,该文件通过 Twilio
打电话给我,而且我的工作很棒,总是能收到电话:
I have set a localhost using MAMP
and i have a index.php
file that call me via Twilio
, and its working great i get calls always:
<?php
$id = "ACxx15d26xxxxxxxxx454424bxxexx3f";
$token = "79fb4xxxf93c8exxxxxxxda6bxxxxe9 ";
$url = "https://api.twilio.com/2010-04-01/Accounts/$id/Calls.json";
$CallURL = "http://www.someweb.com";
$from = "+97223721333";
$to = "+971111111111"; // twilio trial verified number
$body = "Its all going to work!";
$data = array (
'From' => $from,
'To' => $to,
'Body' => $body,
'Url' => $CallURL,
);
$post = http_build_query($data);
$x = curl_init($url );
curl_setopt($x, CURLOPT_GET, true);
curl_setopt($x, CURLOPT_RETURNTRANSFER, true);
curl_setopt($x, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($x, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($x, CURLOPT_USERPWD, "$id:$token");
curl_setopt($x, CURLOPT_POSTFIELDS, $post);
$y = curl_exec($x);
curl_close($x);
var_dump($post);
var_dump($y);
?>
然后我设置了 Amazon服务器EC2
,并且我在其中放置了一些文件( filezilla
),该文件也可以工作(我可以在浏览器中加载图像,并且可以工作)。
Then i have set an Amazon server EC2
, and i have put a few files in there (filezilla
) which worked also(i can load images in the browser-and it works).
然后我尝试将此文件放入服务器中,发生了两件事。
Then i have tried to put this file in the server, well there are 2 things happened.
- 我将其作为
index.php
放置,然后浏览那里,我可以看到空白页面,什么也没发生。 -
当我将其放置为
index.html
并在那里浏览时,我得到了此文本(不是Json,所以我不知道它是什么),我也没有也接到电话:
- when i put it as
index.php
, and browse there , i could see a blank page and nothing happened . when i put it as
index.html
and browse there , i have got this text ("which is not Json,so i dont know what it is) , and i didn't get the call also :
$ from,'To'=> $到'Body'=> $ body,); $ post =
http_build_query($ data); $ x = curl_init($ url); curl_setopt($ x,
CURLOPT_POST,true); curl_setopt( $ x,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ x,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ x,
CURLOPT_HTTPAUTH,CURLAUTH_BAS我知道了); curl_setopt($ x,CURLOPT_USERPWD,
$ id:$ token); curl_setopt($ x,CURLOPT_POSTFIELDS,$ post); $ y =
curl_exec($ x); curl_close($ x); var_dump($ post); var_dump($ y); * /
// twillio call $ id = ACa015xx662d50dxxx454424b70xxxxxx; $ token =
79fb4b00efxxc8exxxf772da6bxxxxxx; //仅在之后:在网站
$ url = https:/ /api.twilio.com/2010-04-01/Accounts/ $ id / Calls.json;
$ CallURL = http://www.somewebsite.com ; $ from = +97223721333; $ to =
+ 971111111111; // twilio试用验证的数字$ body =所有
都将起作用!; $ data = array('From'=> $ from,'To'=> $ to,'Body'
=> $ body,'Url'=> $ CallURL,); $ post = http_build_query($ data); $ x = curl_init($ url); curl_setopt($ x,CURLOPT_GET,true); curl_setopt($ x,
CURLOPT_RETURNTRANSFER,true); curl_setopt($ x,CURLOPT_SSL_VERIFYPEER,
false); curl_setopt($ x,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
curl_setopt($ x,CURLOPT_USERPWD, $ id:$ token); curl_setopt($ x,
CURLOPT_POSTFIELDS,$ post); $ y = curl_exec($ x); curl_close($ x);
var_dump($ post); var_dump($ y); ?>
$from, 'To' => $to, 'Body' => $body, ); $post = http_build_query($data); $x = curl_init($url ); curl_setopt($x, CURLOPT_POST, true); curl_setopt($x, CURLOPT_RETURNTRANSFER, true); curl_setopt($x, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($x, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($x, CURLOPT_USERPWD, "$id:$token"); curl_setopt($x, CURLOPT_POSTFIELDS, $post); $y = curl_exec($x); curl_close($x); var_dump($post); var_dump($y); */ //twillio call $id = "ACa015xx662d50dxxx454424b70xxxxxx"; $token = "79fb4b00efxxc8exxxf772da6bxxxxxx "; //only after : in the website $url = "https://api.twilio.com/2010-04-01/Accounts/$id/Calls.json"; $CallURL = "http://www.somewebsite.com"; $from = "+97223721333"; $to = "+ 971111111111"; // twilio trial verified number $body = "Its all going to work!"; $data = array ( 'From' => $from, 'To' => $to, 'Body' => $body, 'Url' => $CallURL, ); $post = http_build_query($data); $x = curl_init($url ); curl_setopt($x, CURLOPT_GET, true); curl_setopt($x, CURLOPT_RETURNTRANSFER, true); curl_setopt($x, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($x, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($x, CURLOPT_USERPWD, "$id:$token"); curl_setopt($x, CURLOPT_POSTFIELDS, $post); $y = curl_exec($x); curl_close($x); var_dump($post); var_dump($y); ?>
所以,将其放在<$ c $之间有什么区别c> .php和.html ?为什么其中一个是空白而另一个对此有响应?
So , whats the different between putting it as .php and .html
? why is one of them is blank and the other has this respond ?
EDIT
我尝试使用以下命令安装curl: sudo apt-get install php5-curl
(有效)
I have tried to install curl with : sudo apt-get install php5-curl
(worked)
然后我已测试过是否通过此链接支持curl:
如何在Amazon EC2免费层上启用cURL扩展
结果是它不受支持。
为什么?我已经安装了它。
then i have tested to see if i have curl supported with this link: How to enable cURL extension on Amazon EC2 free tier result is that its not supported. Why is that ? i have installed it.
推荐答案
首先我必须添加curl sudo apt-get install php5- curl
first i had to add the curl sudo apt-get install php5-curl
然后重新启动apache !!!
But then, to restart the apache !!!
sudo service apache2 restart
不重新启动-不起作用!
No restart- not working !
这篇关于PHP脚本仅在本地主机上起作用,而不在Amazon中起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!