Page 1 of 1

Blank $HOMEDIR Variable when calling cli via php exec() function

Posted: Thu May 04, 2017 8:04 am
by emanhig
I have written a custom bash script which is called by php with root permissions via sudoers. The bash script adds a web domain with letsencrypt support.

My PHP my command is

Code: Select all

exec("sudo -u root /var/tuilder/bin/vestacp_add_domain.sh example.com 104.xxx.xxx.xx");
My shell script is:

Code: Select all

#!/bin/bash
domain=$1
ip=$2

/usr/local/vesta/bin/v-add-web-domain admin $domain $ip www.$domain
/usr/local/vesta/bin/v-add-letsencrypt-domain admin $domain www.$domain
In my scenario, this is the best way for me to perform these functions (rather than using the vesta web api.)

After some testing because it wasn't working, I discovered that the $HOMEDIR variable in the v-add-web-domain script was blank, and that the web domain was being created in /admin/web/ NOT /home/admin/web/.

My question is how is the $HOMEDIR variable being set, and why is it blank in the above scenario?

Re: Blank $HOMEDIR Variable when calling cli via php exec() function

Posted: Thu May 04, 2017 9:31 am
by emanhig
Solved the problem.

The environmental variable $VESTA was set in the php exec environment.

Solved by doing this:

exec("VESTA='/usr/local/vesta' sudo -u root /var/tuilder/bin/vestacp_add_domain.sh example.com 104.xxx.xxx.xx");