Saturday, August 22, 2020

Testing CORS localhost policy

 Something, chrome will restrict from displaying videos from third-party links because of the web security. 

Although you can remove restriction from your video hosting provider by adding your actual production domains, you still can't test these videos in your localhost. So How to fix it?


Step 01 - Add localhost as allowed domain inside the dashboard of your video hosting provider

Step 02 - Create a new chrome shortcut and rightClick > Properties section to change the shortcut properties

Step 03 - Add the following to the target field of the shortcut section

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp and click Apply



Note : Always run that created shortcut as administrator and now you will be able to bypass CORS restriction for testing.

Thursday, August 20, 2020

Setting up letsencrypt SSL on ubuntu

 Setting up the best free SSL certificate (letsencrypt) is pretty easy on Ubuntu with lampstack.

Step 01 - If you haven't installed lampstack for webhostings, do it first.

Step 02 - Go to lampstack directory cd /opt/lampstack[v]

Step 03 - Execute ./bncert-tool 

Step 04 - Now follow the instructions


Monday, July 6, 2020

Basic server requirements for a typical laravel app July 06, 2020

1 . Bitnami Lamp stack for linux or XAMPP fpr windows

2 . Cacert file in the php folder
https://curl.haxx.se/ca/cacert.pem

3 . Add extension=mongodb.so (PHP > 7) or extension=mongo.so (PHP < 7) in php/etc/php.ini file
(Note : PHP ver 7.4.7 or newer doesn't require .so extension)

4 . The below command will download and place the required mongodb php driver for Linux which will build and install mongodb.so file under /php/lib/php/extensions

(Linux)
pecl install mongo (PPH version < 7)
pecl install mongodb (PPH version > 7)

(For windowsm download place it manually in the php extension folder)
https://pecl.php.net/package/mongodb

Run apt-get install autoconf if you haven't installed autoconf module yet then run pecl command again

no acceptable C compiler found in $PATH

sudo apt-get update
sudo apt install build-essential
sudo apt install gcc command to install C Compiler and then run pecl command again



5 . php -m to see the loaded php modules and which should include mongodb

Friday, June 28, 2019

Setting up pure callback url for telenor server

Step 01 - Create ubuntu droplet with lampstack
Step 02 - Create a new virtual host file with with your domain
Step 03 - Setup letsencrypt SSL
Step 04 - Create a new folder for your domain name in /var/www/ folder and create a new php file name to redirect to
Step 05 - install curl by typing sudo apt-get install php-curl
Step 06 - Restart apache sudo service apache2 restart
Step 07 - Now Copy paste the following redirection code in your php file

<html>
 <head>

  <title>Subscription callback</title>
 </head>
 <body>
<?php
$newurl = "https://api.yourdomain.com/callback_notification?";
                $parameters = "";
                $count =sizeof($_GET);
                $index = 0;
                foreach($_GET as $key => $value)
                {
                        $parameters = $parameters. $key . "=" . $value;
                        if($index < $count - 1)
                                $parameters = $parameters . "&";

                        $index++;
                }

                $newurl = $newurl . $parameters;

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
                curl_setopt($ch, CURLOPT_URL, $newurl);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

                $data = curl_exec($ch);
                curl_close($ch);
                echo $data;
        ?>
 </body>
</html>

Sunday, July 8, 2018

SSL Error on laravel composer update on windows 10

Options 1
Set git to not use SSL verification
git config --global http.sslVerify false

Options 2
composer config --global disable-tls true
composer config --global secure-http false

Options 3 If the options 1 and 2 is not working

Install OpenSSL

Set back to use SSL verification
git config --global http.sslVerify true

Download the CA bundle from curl and store it somewhere on your file system. Take the path you saved it to and add a line to your php.ini file saying:
openssl.cafile = $path

Tuesday, May 23, 2017

Authentication Failed error on Laravel 5.4

Change db to database in database.php file for connecting with mongodb.

After than clear the cache for configurations
php artisan config:clear

Tuesday, April 4, 2017

Upgrading to laravel 5.4

List of things needed to upgrade to the latest laravel

- Change route files (Now it's included in routes folder -> web)
- use Jenssegers\Mongodb\Eloquent\Model as Eloquent; //Use MongoDB as a model for every Model
- Use latest Jssenger laravel-mongodb plugins
- Use PHP > 5.7
- Install PHP driver from http://pecl.php.net/package/mongodb/1.2.8/windows and also in the php.ini config (If you're using xampp for windows, you likely have to use 32bit version of php driver)

If you're upgrading from previous, use the following command to load the config file again
composer dump-autoload

MongoID class is not available now and have to use the ObjectID Class

use MongoDB\BSON\ObjectID as MongoID;

MongoDate class is not available now and have to use the UTCTime Class

The previous MongoDate is now used as UTCDateTime and hence little conversion is needed to store the right MongoDate now.

 function convert_to_mongo_date($date)  
 {  
   if($date == null || !isset($date))  
     return null;  
   $carbon_date = Carbon::createFromFormat('d/m/Y', $date);  
   try {  
     $mongo_date = new MongoDate(strtotime($carbon_date->toDateString()) * 1000);  
     return $mongo_date;  
   }  
   catch(Exception $e) {  
     Log::info('MongoDate conversion error '.$e);  
     return new MongoDate();  
   }  
 }  
 function convert_to_date_from_sec($date)  
 {  
   if($date == null || !isset($date))  
     return "01/01/1990";  
   try  
   {  
     $secs = $date->toDateTime()->format('U.u');  
     return date('d/m/Y', $secs);  
   }  
   catch(Exception $e)  
   {  
     return "01/01/1990";  
   }  
 }  

strtotime function changed to the following for filter dates


     $fromDate = new MongoDate( strtotime('-1 month' ));  
     $currentDate = new MongoDate( strtotime('+1 day' ));  

You need to put extra array while doing aggregations


  $user_signups_raw = DB::collection('users')->raw(function($collection) use($fromDate, $currentDate)  
     {  
       return $collection->aggregate  
       (  
         array  
         (  
           array  
           (  
             '$match' => array  
             (  
               'created_at' => array( '$gt' => $fromDate, '$lt' =>$currentDate)  
             )  
           ),  
           array  
           (  
             '$group' => array  
             (  
               '_id' => array(  
                 '$dayOfYear' => '$created_at',  
               ),  
               'count' => array  
               (  
                 '$sum' => 1  
               ),  
               'date' => array  
               (  
                 '$first' => '$created_at'  
               )  
             )  
           ),  
           array  
           (  
             '$sort' => array  
             (  
               '_id' => 1  
             ),  
           )  
         )  
       );  
     });  

And aggregate results is now with collections and you need the following snippets to convert it to usable format


    $user_signups = [];  
     foreach ($user_signups_raw as $doc)  
     {  
       $item = json_encode( $doc->getArrayCopy());  
       $item = $doc->getArrayCopy();  
       array_push($user_signups, $item);  
     }