为 GCM (Linode) 设置 Apache 服务器 (ubuntu 12.04)

Setting up an Apache Server (ubuntu 12.04) for GCM (Linode)

我最近更换了服务器,我的 Google 云消息代码不再有效。我没有太多的服务器经验,我试图在整个互联网上寻找合适的解决方案,但没有成功。

我有一个 GoDaddy 服务器(可用),我已经设置并切换到 linode 服务器上的 lamp 堆栈。我一定是在服务器配置中遗漏了一些东西,因为发送 gcm 的代码在 godaddy 上有效,但在 apache linode 服务器上不起作用。

注册 ID 没有问题,但无法发送 gcm 消息。我使用 php 脚本发送它们,我知道这不是问题所在。

是否需要设置任何设置才能使 Google 云消息传递正常工作?

访问日志:

###.###.###.### - - [23/Dec/2015:12:47:40 -0500] "POST /test/test.php HTTP/1.1" 500 372 "-" "Mozilla/5.0 (Macin

错误日志:

empty

我遵循了这些教程:

https://www.linode.com/docs/getting-started

https://www.linode.com/docs/websites/lamp/lamp-on-ubuntu-14-04

https://www.linode.com/docs/databases/mysql/install-mysql-phpmyadmin-on-ubuntu-12-04

https://www.linode.com/docs/security/ssl/ssl-apache2-debian-ubuntu

https://www.linode.com/docs/websites/apache/apache-web-server-ubuntu-12-04

GCM.php

<?php

class GCM { 
function __construct() {

}


public function send_notification($registatoin_ids, $message, $google) { 

    $url = 'https://gcm-http.googleapis.com/gcm/send';

    $fields = array(
        'registration_ids' => $registatoin_ids,
        'data' => $message,
    );

    $headers = array(
        'Authorization: key=' . $google,
        'Content-Type: application/json'
    ); 
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }

    curl_close($ch);
    echo $result;
}

}

?>

test.php

<?php
include_once './gcm.php';

$message = $_POST['msg'];
$reg = $_POST['regid'];
$registation_ids = array();
array_push($registation_ids, $reg);
$googleAPIKey = "GOOGLE_API_KEY";

$gcm = new GCM();
$messages = array("message" => $message, "analyticsId" => "someid");
$result = $gcm->send_notification($registation_ids, $messages, $googleAPIKey);
echo $result;
?>

打开了 php 日志记录,但仍然没有。我仍然只在 linode 服务器上收到 500 内部错误。

我要回答我自己的问题,因为我已经成功了。

我从未安装过 PHP curl。

http://jesselau.com/2013/04/26/how-to-add-curl-to-linode-ubuntu/