Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exec call for htpasswd on new host

Status
Not open for further replies.

gagz

Programmer
Nov 21, 2002
333
US
Hi-

I have the following command scripted in a php file that worked perfectly on a previous host, but is now not working on a new host (who claims it should work):

echo exec("htpasswd -b /home/ssgdc/public_html/client/.htpasswd " . $username . " " . $password);

it didn't work from the command line, since apparently htpasswd wasn't in my path, so i changed it to:

echo exec("/usr/local/apache/bin/htpasswd -c -b /home/ssgdc/public_html/client/.htpasswd " . $username . " " . $password);

that worked on the command line. Neither work in the actual script.

I've tried multiple iterations of perms on the .htpasswd file w/ no luck. The users/pws that were in the .htpasswd file when i moved the site to this host still work fine.

Any ideas what it could be? anything in php.ini or something like that?

thanks.
 
permissions. does your webserver process have the rights to execute these commands?

you might want to try sudo.
 
The first thing I would check is that your new host actually allows the use of that function.

Create a file "phpinfo.php" with the contents:
<?php phpinfo(); ?>

Run it and look for the section that shows disabled functions. If exec is disabled your going to need to find another way.

Also look to see if safe_made is to "on" this will cause you the most trouble. If safe mode is on the only commands that PHP will be able to execute are located in the "safe_mode_exec_dir". These directories can also be located in the phpinfo script.


If safe mode is not on and exec is not disaable and you still can't get it to work give the following code a whirl.

$username = escapeshellarg ($_POST['username']);
$passwd = escapeshellarg ($_POST['passwd']);
$pw_file = "/home/yourname/.htpasswd";
$bin_path = "/usr/local/apache/bin/htpasswd";
$command = $bin_path." -c -b ".$pw_file." ".$user." ".$passwd;
$result = shell_exec($command);


Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top