webhead Posted October 16, 2006 Share Posted October 16, 2006 Hi, I'm trying to do a mysqldump from php. I can do so from Terminal but not php.Phpinfo shows the PATH to be /bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/System/Library/CoreServicesbut I need to add /usr/local/mysql/bin/ so it can find mysqldump.I made sure safe mode is off and tried various ways to set the mysqldump command, but it just can't find it. Here is what I tried with putenv:[code]$myPath = "PATH=/bin /sbin /usr/bin /usr/sbin /usr/libexec /System/Library/CoreServices /usr/local/mysql/bin/";$chgPath = putenv($myPath); echo "<br>return value of putenv = ",$chgPath; echo "<br>my path = ",$myPath;echo "<br>returned path = "; echo getenv('PATH');[/code]Help! Quote Link to comment https://forums.phpfreaks.com/topic/24120-putenv-doesnt-work/ Share on other sites More sharing options...
shoz Posted October 16, 2006 Share Posted October 16, 2006 The paths are separated by colons (":").[code]putenv('PATH=/path/to/mysql/bin:'.getenv('PATH'));echo getenv('PATH');[/code]You should consider setting a variable to hold the path to the binary instead of using the PATH environ var.eg[code]$mysqldump = '/path/to/mysql/bin/mysqldump';$command = "$mysqldump --version";passthru($command);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24120-putenv-doesnt-work/#findComment-109685 Share on other sites More sharing options...
webhead Posted October 16, 2006 Author Share Posted October 16, 2006 Thanks! Progress made but still no output file from mysqldump.What it's doing now is showing that it found mysqldump after the putenv statement, but the getenv is unchanged. Here's my code:[code]putenv('PATH=/usr/local/mysql/bin:' . getenv('PATH'));echo "getenv is --> ", getenv('PATH');echo "<br /><pre>" . shell_exec('which mysqldump') . "</pre>";$mysqldump = "/usr/local/mysql/bin/mysqldump";$command = "$mysqldump --version";passthru($command);$dumpit = "$mysqldump -h $h -u $u -p$p $d > $filedest"; passthru($dumpit);[/code]And the displayed messages:[code]getenv is --> /bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/System/Library/CoreServices/usr/local/mysql/bin/mysqldump (result of $command)mysqldump Ver 10.10 Distrib 5.0.24a, for apple-darwin8.5.1 (i686) [/code] Quote Link to comment https://forums.phpfreaks.com/topic/24120-putenv-doesnt-work/#findComment-109712 Share on other sites More sharing options...
shoz Posted October 16, 2006 Share Posted October 16, 2006 "/usr/local/mysql/bin/mysqldump" should be the result of "which mysqldump"I've also noticed that when run through apache "getenv()" does not show the new PATH. The results show that the directory is a part of the new PATH however. The output of phpinfo after the putenv() call also shows the dir in the PATH under "Environment".When run on the command line the output of getenv reflects the change.[quote=webhead]Progress made but still no output file from mysqldump.[/quote]Does apache have write access to the directory you're trying to dump to? If you're sure that apache has write access to the directory you can use the following to put the errors in a file called dump_err.txt[code]$errdest = '/path/to/dir/dump_err.txt';exec("$mysqldump ... > $filedest 2> $errdest", $output, $return);if ($return){ echo file_get_contents($errdest);}[/code]I recommend you run this script from the command line instead of through apache. Quote Link to comment https://forums.phpfreaks.com/topic/24120-putenv-doesnt-work/#findComment-109758 Share on other sites More sharing options...
webhead Posted October 16, 2006 Author Share Posted October 16, 2006 [quote author=shoz link=topic=111678.msg452842#msg452842 date=1161036201]Does apache have write access to the directory you're trying to dump to? [/quote]DOH!!I could have sworn I set the chmod for that directory. The weird thing is that it wrote to that directory from Terminal. But since all is well now, no more swearing for me. ;-)Thanks loads! Quote Link to comment https://forums.phpfreaks.com/topic/24120-putenv-doesnt-work/#findComment-109781 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.