Automate Letsencrypt SSL Certificate installation with PHP shell_exec command via acme.sh snap package

1.1k Views Asked by At

I install lets encrypt certificates through acme.sh snap package

https://github.com/acmesh-official/acme.sh

I am wondering if there is any way to automate certificate installation via PHP default shell_exec() command.

This shell command used to get certificates works just fine when logged in via SSH

acme.sh --issue --dns dns_gd -d example.com -d *.example.com

However, if I call the same command via PHP shell_exec, it always throws an error

$domainName = 'example.com';
$initCommand = "acme.sh --issue --dns dns_gd -d $domainName -d *.$domainName";
$output = shell_exec("$initCommand 2>&1 | tee -a /var/www/html/sshout.txt 2>/dev/null >/dev/null &");

sshout.txt - The output I am getting on sshout is as following

ssh: 1: /home/ubuntu/.acme.sh: Permission denied
sudo: no tty present and no askpass program specified

Is it possible to get certificates this way?

Or any other way to automate it via PHP? by setting cron, or creating a bash script and calling it from PHP?

I am running PHP 7.2 on ubuntu 18 on an apache server.

1

There are 1 best solutions below

0
On

You should have permission and the right path to run the bash script. I guess this topic is what you need PHP script can't run bash script. sh: Permission denied

the other way is using acmephp