Shell Script from PHP not able to cp or mv or anything

Hi there,

For some reason my maintenance mode shell script is not working. Both shell scripts are chmod +x'd, and owned by apache, running from php using exec(), maintenance.html and htaccessmaintenance are both owned by apache.

My code is:

#/bin/bash

cp maintenance.html /var/www/vhosts/$1/httpdocs/maintenance.html
if [ -f /var/www/vhosts/$1/httpdocs/maintenance.html ]
then

wall 'copied'

fi

chown apache:psacln /var/www/vhosts/$1/httpdocs/maintenance.html
if [ -f /var/www/vhosts/$1/httpdocs/.htaccess ]
then
chown apache:psacln /var/www/vhosts/$1/httpdocs/.htaccess
mv /var/www/vhosts/$1/httpdocs/.htaccess /var/www/vhosts/$1/httpdocs/.htaccess.bak
chown apache:psacln /var/www/vhosts/$1/httpdocs/.htaccess.bak
fi
cp htaccessmaintenance /var/www/vhosts/$1/httpdocs/.htaccess
chown apache:psacln /var/www/vhosts/$1/httpdocs/.htaccess

It works executed from the command line, but not from PHP, no idea why. I know a lot of the chown's are overkill, but I'm grasping at straws now.

What is the PATH variable when seen inside PHP? That is probably the issue.
Add (example):

export PATH=/usr/bin:/usr/local/bin

as the first line of the script. Or. You can also source /etc/profile and .profile
This is probably a better solution.

It also depends who those directories belong to. If they're not writable by the apache group, apache and things apache runs probably can't touch them.