Search code examples
phplinuxamazon-ec2gmp

POST https://kayaindia.in/kaya/sendNotificationB.php 500 (Internal Server Error)


I an creating a PWA app and its working fine, but when I tried to upload on server I stuck on error. On windows local server, everything is fine even notifications, and I dont know much putty/linux commands.

check here my phpinfo file.

I am tring to upload to amazon ec2 server. I installed apache, php, ssl and other required things. And its working file except notifications.

When I call my notification file, I got 503 response. I installed composer, installed everything. I used this github library.

As I understand, I stuck on gmp extension, When I open phpinfo() I didnt see gmp over there. I installed gmp using sudo yum install php-gmp and also I see a file in php.d named as 20-gmp.ini and it included extension=gmp. Also restarted apache server using sudo apachectl stop, sudo apachectl start.

But still I am getting error. And I coudnt see gmp in phpinfo().

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()}";
    }
}

?>

If you need any thing, let me know in command. I will update here.

Edit 1: Also I tried to add gmp extension in php.ini in /etc/php.ini but still not added.

I think I am getting error on $subscription = Subscription::create(json_decode(file_get_contents('php://input'), true));


Solution

  • I know I am commenting my own question, As I was searching this answer for 3-4 days I think I should share this info with everyone.

    The issue is, In linux, PHP have different-different configuration files. The main configuration file is php.ini. And it include other extensions after loading this file and override mail file. These additional configuration are located in /etc/php.d/ (in my case, which is common for mostly).

    So just restarting apache server in not enough. We need to also restart php-fpm.

    To restart php-fpm: sudo service php-fpm restart And then restart apache: sudo apachectn restart

    You can check more here