我正在创建一个PWA应用程序,它的工作正常,但当我试图在服务器上传时,我坚持错误。在Windows本地服务器上,一切都很好甚至通知,我不知道很多putty / linux命令。
检查here我的phpinfo文件。
我想上传到amazon ec2服务器。我安装了apache,php,ssl等所需的东西。它的工作文件除了通知。
当我调用我的通知文件时,我得到了503响应。我安装了composer,安装了一切。我用过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。
notification.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
的/etc/php.ini
中添加gmp扩展名但仍未添加。
我想我在$subscription = Subscription::create(json_decode(file_get_contents('php://input'), true));
上遇到错误
我知道我正在评论自己的问题,因为我在3-4天内搜索这个答案,我想我应该与大家分享这些信息。
问题是,在Linux中,PHP有不同的配置文件。主配置文件是php.ini。并且在加载此文件并覆盖邮件文件后包含其他扩展名。这些额外的配置位于/etc/php.d/
(在我的情况下,这在大多数情况下很常见)。
所以只是重启apache服务器还不够。我们还需要重启php-fpm。
要重新启动php-fpm:sudo service php-fpm restart
然后重新启动apache:sudo apachectn restart
你可以查看更多here