How to add custom php file to right sidebar?

There are three ways to do that:

  1. Create a widget (Recommended)
    Here is official documentation. You can include your php file within widget() function of your widget class.

  2. Create and place a shortcode in exiting wordpress default text widget.
    Here is sample code

    //Place this code in theme's functions.php
    
    add_shortcode('ContactForm', 'cf_shortcode');
    
    function cf_shortcode($att) {
       ob_start();
       include "path/to/php/file";
       return ob_get_clean();
    }
    

Then place [ContactForm] in wordpress default text widget.

Create a child theme and override sidebar.php file of your theme there.