In your terminal/console (only Linux, in windows you need Putty)
ssh user@ip
php -i | grep "Loaded Configuration File"
It shows something like this Loaded Configuration
File => /etc/php.ini.
ALTERNATIVE METHOD
You can make the php file on the website, which run: <?php phpinfo(); ?>, and you can see a php.ini location on your line with: "Loaded Configuration File".
Update This command gives path right away
cli_php_ini=php -i | grep /.+/php.ini -oE #ref. https://intellipaat.com/a/15763333/248616
php_ini="${cli_php_ini/cli/apache2}" #replace cli by apache2 ref. https://intellipaat.com/a/13210909/248616
Come and join Linux training to gain great knowledge.