【发布时间】:2019-07-16 16:00:00
【问题描述】:
我正在创建一个 PWA 应用程序,它工作正常,但是当我尝试在服务器上上传时,我遇到了错误。在 windows 本地服务器上,一切都很好,即使是通知,我也不知道多少 putty/linux 命令。
检查here我的phpinfo文件。
我正在尝试上传到亚马逊 ec2 服务器。我安装了 apache、php、ssl 和其他必需的东西。以及它的工作文件,除了通知。
当我调用通知文件时,我收到了 503 响应。我安装了作曲家,安装了一切。我使用了this github 库。
据我了解,我坚持使用 gmp 扩展,当我打开 phpinfo() 时,我没有看到 gmp 在那里。我使用sudo yum install php-gmp 安装了gmp,而且我在php.d 中看到一个名为20-gmp.ini 的文件,它包含extension=gmp。还使用sudo apachectl stop、sudo apachectl start 重新启动了 apache 服务器。
但我仍然遇到错误。而且我无法在 phpinfo() 中看到 gmp。
notificationb.php
<?php
require __DIR__ . '/vendor/autoload.php';
use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;
$subscription = Subscription::create(json_decode(file_get_contents('php://input'), true));
print_r($subscription);
$auth = array(
'VAPID' => array(
'subject' => 'https://github.com/Minishlink/web-push-php-example/',
'publicKey' => file_get_contents(__DIR__ . '/scripts/keys/public_key.txt'), // don't forget that your public key also lives in app.js
'privateKey' => file_get_contents(__DIR__ . '/scripts/keys/private_key.txt'), // in the real world, this would be in a secret file
),
);
$webPush = new WebPush($auth);
$res = $webPush->sendNotification(
$subscription,
"Welcome to Kaya. You can book Appointments and many more."
);
foreach ($webPush->flush() as $report) {
$endpoint = $report->getRequest()->getUri()->__toString();
if ($report->isSuccess()) {
echo "[v] Message sent successfully for subscription {$endpoint}.";
} else {
echo "[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}";
}
}
?>
如果您需要任何东西,请在指挥部告诉我。我会在这里更新。
编辑1:我还尝试在php.ini 中添加gmp 扩展名/etc/php.ini,但仍未添加。
我认为我在$subscription = Subscription::create(json_decode(file_get_contents('php://input'), true)); 上遇到了错误
【问题讨论】:
标签: php linux amazon-ec2 gmp