I've just tried to execute your script, but got the following error.
[2.7.2-RELEASE][m-admin@firewall]/home/m-admin: php pfsense-import-certificate.php /home/m-admin/fullchain.pem /home/m-admin/key.pem
Fatal error: Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /etc/inc/config.lib.inc:1056
Stack trace:
#0 /etc/inc/config.lib.inc(1056): fwrite(false, 'a:31:{i:1716369...')
#1 /etc/inc/config.lib.inc(660): backup_config()
#2 /home/m-admin/pfsense-import-certificate.php(90): write_config('Save new certif...')
#3 {main}
thrown in /etc/inc/config.lib.inc on line 1056
PHP ERROR: Type: 1, File: /etc/inc/config.lib.inc, Line: 1056, Message: Uncaught TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in /etc/inc/config.lib.inc:1056
Stack trace:
#0 /etc/inc/config.lib.inc(1056): fwrite(false, 'a:31:{i:1716369...')
#1 /etc/inc/config.lib.inc(660): backup_config()
#2 /home/m-admin/pfsense-import-certificate.php(90): write_config('Save new certif...')
#3 {main}
thrown
I've just tried to execute your script, but got the following error.
I use vanilla pfSense version 2.7.2.