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

Questions regarding the Command Line Interface
CLI
emanhig
Posts: 3
Joined: Tue Feb 23, 2016 3:39 am

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

Postby emanhig » Thu May 04, 2017 8:04 am

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?

emanhig
Posts: 3
Joined: Tue Feb 23, 2016 3:39 am

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

Postby emanhig » Thu May 04, 2017 9:31 am

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");


Return to “CLI”



Who is online

Users browsing this forum: No registered users and 2 guests