nadermx / backgroundremover

Background Remover lets you Remove Background from images and video using AI with a simple command line interface that is free and open source.
https://www.backgroundremoverai.com
MIT License
6.46k stars 538 forks source link

It works fine from ssh buy not from PHP, why ? #40

Closed bil80 closed 1 year ago

bil80 commented 1 year ago

Hello, i installed it successfully, it works without any issue from a ssh command line, but when i run it from a PHP page, there is no output, and there is no errors on the log file. Is there any settings to do ?

conrad10781 commented 1 year ago

If you posted your PHP script, I could better answer, but presuming you're doing something like the following and it's "not working":

$output = `backgroundremover -i "FILE.jpg" -o "FILE.png"`;

And through your shell ( ssh command line ), you're doing the following and it is working:

backgroundremover -i "FILE.jpg" -o "FILE.png"

You would have multiple issues. First being that you would want to use the full path to backgroundremover ( run "which backgroundremover" without the quotes ), but you're going to see it's installed in a local users .local/bin directly probably and not the more common /usr/bin, which is going to leave you with the next issue.

Are you running the PHP through a web server or the command line? If the command line, as long as you're running the command as the same Linux user that installed it and who you're SSH'd in as, just make sure you're using the full path.

If you're running it through a web server, that is likely being run through a different user than your Linux user ( IE "www-data" on Ubuntu in Apache ). It may still work using the full path, but you will likely run into permission issues ( which you could circumvent with chmod's that may create other issues ). So you will either need to install the package again globally or to setup a true home directly for www-data ( or whatever the user is ) and install it there, and again still use the full path in PHP.

nadermx commented 1 year ago

This is more PHP code than a issue with this package. Try https://stackoverflow.com/questions/25230686/using-the-exec-command-php