0

Recently, I uploaded a file into two servers, one is my hosting server and the other is aws EC2 server. However, I'm getting result of the file from my hosting server, but nothing from aws EC2 server.

Hosting server: http://amhappy.net/naverbook.php (getting result normally, even though not completed)

AWS EC2 server : http://awamp.duckdns.org/naverbook.php (getting nothing from this server)

The file "naverbook.php" is all the same file each other.

I'm confused with what's wrong is there. Do I need to install any language or something on AWS EC2 server? I installed apache2,php,mysql,python,curl,phpmyadmin .. I guess that's all.

Here is my file "naverbook.php" below:

<?php
$client_id = "";
$client_secret = "";
$encText = urlencode("유닉스");
$url = "https://openapi.naver.com/v1/search/book.json?query=".$encText; 
$is_post = false;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "X-Naver-Client-Id: ".$client_id;
$headers[] = "X-Naver-Client-Secret: ".$client_secret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "status_code:".$status_code."
";
curl_close ($ch);
if($status_code == 200) {
echo $response;
} else {
echo "Error 내용:".$response;
}
?>

<< This Question has been solved: sudo apt-get install php7.0-curl was the correct answer. Thank you for you all answered to my question.>>

I got a hint from here :

https://stackoverflow.com/questions/32972846/php-script-works-only-in-local-host-not-in-amazon?rq=1
happy life
  • 27
  • 5
  • is security group ok for the ec2 instance ? how do you resolve the domain name to the ec2 instance ? – Frederic Henri Jul 27 '17 at 10:51
  • I changed EC2 ip into static ip first and linked to duckdns.org. And, I added the domain address(awamp.duckdns.org) to the openAPi naver.com as well as amhappy.net. I did nothing on security group for two domains: http://amhappy.net and http://awamp.duckdns.org. Why does one work and the other not? That's why I am confused. – happy life Jul 27 '17 at 11:49
  • Although, I access to aws EC2 server by public IP: http://52.78.217.156/naverbook.php, it doesn't work. Nothing to be seen. Likewies, http://ec2-52-78-217-156.ap-northeast-2.compute.amazonaws.com/naverbook.php does not work. – happy life Jul 27 '17 at 12:00
  • can you check the security group of the instance serving awamp.duckdns.org and it has open port 80 (its not necessarily the same as the other instance, it depends how you created the instance) – Frederic Henri Jul 27 '17 at 12:02
  • What I am confused is that the other file "naverapi.html" does work on same aws EC2 server. http://awamp.duckdns.org/naverapi.html .. <- this file shows result on same aws EC2 server. If there is something wrong on EC2 server or security group, why only a file is not shown the result of it with same address on same server ???? – happy life Jul 27 '17 at 12:08
  • ah ok I did not get that it was serving other files - in this case do you have any error in your server log files ? – Frederic Henri Jul 27 '17 at 12:09
  • When it comes to aws EC2, I don't know how to check server log files. I am very beginner. ok, i'll google it.... try again anyway.... – happy life Jul 27 '17 at 12:12
  • There are a number of log files. Which log file should I refer ??? – happy life Jul 27 '17 at 12:17
  • start with the logs files from apache – Frederic Henri Jul 27 '17 at 12:18
  • Here is my log file: 121.136.148.152 - - [27/Jul/2017:12:06:01 +0000] "GET /naverapi.html HTTP/1.1" 200 1576 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4" – happy life Jul 27 '17 at 12:21
  • nothing for naverbook.php ? – Frederic Henri Jul 27 '17 at 12:22
  • 121.136.148.152 - - [27/Jul/2017:12:04:50 +0000] "GET /naverbook.php HTTP/1.1" 500 186 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4" – happy life Jul 27 '17 at 12:22
  • so it resolved but you have 500 error so the script returns an error - btw remove your secret password or make sure its not the right one – Frederic Henri Jul 27 '17 at 12:25
  • What is btw and secret password? I don't have secret password. – happy life Jul 27 '17 at 12:28
  • `$client_id = "Ah8nEB5mC3cgJbd1gkRg"; $client_secret = "Vo5Yg_VIPh"; ` – Frederic Henri Jul 27 '17 at 12:29
  • I am saying you should not put any password in Stack Overflow questions. – Frederic Henri Jul 27 '17 at 12:38
  • Yes, I removed my password, but the result came out all the same....Woops. Sorry I was mis-understood. Thank you for your help. – happy life Jul 27 '17 at 12:41
  • when you run your code, you need your password but people need not need to know the password so remove when you post the question, only when posting – Frederic Henri Jul 27 '17 at 12:42
  • I found a similar question of mine. I think it would be helpful to me. https://stackoverflow.com/questions/32972846/php-script-works-only-in-local-host-not-in-amazon?rq=1 And I removed my secret password from my source code in Stack Overflow. – happy life Jul 27 '17 at 12:56
  • This question has been solved. sudo apt-get install php7.0-curl was the correct answer. When I installed curl only, it didn't work, but installed php7.0-curl, it's result came out. I got an hint from the question below: stackoverflow.com/questions/32972846/… Thanks again Frédéric Henri for your kindness and your help. – – happy life Jul 27 '17 at 15:06

0 Answers0