Please follow the below template, it will help us to help you!
Standard Install on Ubuntu 22.04 lts using simple ssh script.
I created custom php File within /var/www/html/export.php
From the moment I try to use new PDO() the script can no longer be used over Browser. Error Code is 500. Calling "php export.php" within ssh shell works excellent.
This error usually means there is something wrong on the PHP code.
Since there was a lot of recent changes to the web server configuration, just for test try to move you file to /var/www/html/admin/export.php and try again to see if something changes.