Run occ command via php file not working

Hey,

i donā€™t know whether its the correct category, but following problem:

i am doing some mysqldump database backups via a .php file which is running by a cronjob. The mysqldumped backups are writte to my Cloud storage. To see this files i want to add the occ command, to scan the SQL backup folder after completing the backup. You understand?

Therefor, i need to execute the occ command in my php file. Following command does work in SSH:

php7.1-cli /homepages/33/d697614970/htdocs/clickandbuilds/nextCloud/occ files:scan --path=Oernifly/files/Backup_SQL

So, it would be so easy, if i have to add the command with a exec() in to my .php file. But this does not work.

    <?php 
   echo exec( 'php7.1-cli /homepages/33/d697614970/htdocs/clickandbuilds/nextCloud/occ files:scan --path=Oernifly/files/Backup_SQL' );
    ?>

i tried so many different ways to describe the command. exec(), system(), shell_exec()

The command does not give a respond. Blank pageā€¦

It is not due to missing permissions. The php files runs the same as the SSH.

Anybody an idea for that? I want to rescan my god dammed folder after the backup. It canā€™t be that hardā€¦ ?! wtf.

I donā€™t now why it should be necessary to force a file system scan, because my experience is,
that new files are usually displayed instantly if youā€™re accessing a folder. Nevertheless if you
want to execute a program it is

  1. always good to use an absolute path to the PHP cli program.

  2. check the access rights of the PHP cli program because it is usually executed with
    the rights of the user under which the web server is running. Try to execute e.g. a
    "/<path-to-cli>/php7.1-cli --version" first.

  3. check the access right of the path to the Nextcloud root. The user which is used to
    execute the command, ususally the user under which the web server is running,
    need to be able to find and access the occ command.

Because the files should part of the automatic sync of my Desktop PC (for having an offline backup and an online backup if the server crashes) - and this is only possible if the file are discovered.

  1. So i entered the absolute path for the PHP CLI. No reaction.

  2. The path/command is: ā€œ/usr/bin/php7.1-cli -vā€ If i run this in SSH, i get my informations. If i execute this in my PHP file nothing happens. So the problem is, that i canā€™t access php7.1-cli by PHP right? How to fix this? I am on a webhoster and canā€™t access the file my myself. And why i can access the php version via the same user in SSH?

But i checked with following command $username = posix_getpwuid(posix_geteuid())['name']; which user PHP i running. its the same as the SSH user.

  1. How to check that?

Not seeing a reply doesnā€™t automatically mean that a program is not being executed.
You should try to redirect the exec output to a variable as described here:

Okay i did as mentioned. Following output: php7.1-cli: not found

I think the hoster didnā€™t gave me the permissions to access the php executable or smth.

Can i install php-cli on my own? Or is the user for executing php files a different as the SSH user?

i donā€™t understand anything nowā€¦ What can i do?

this is working for me

<?php
exec("php console.php files:scan /userhome/files/xyz -v 2>&1",$o,$r);
?>

Sorry, this is definitely not a Nextcloud problem and cannot be answered in general because all server environments are different. Best would be to ask your hoster to answer these question.

Hehe, i know - but they never answer to this kind of replys :slight_smile:

oh yeah finally got it.

I donā€™t understand it anyway. But php7.1-cli doesenā€™t exist and php7.3-cli exists and is usable. Why SSH can run php7.1-cli I DONT KNOW.

I listed with following script my accesscable folder from php:
<?php
echo $_SERVER[ā€˜DOCUMENT_ROOTā€™];
exec(ā€˜ls /* 2>&1ā€™, $output);
print_r($output);
?>
then i entered the next path i believe the php file could be in it

  <?php
echo $_SERVER['DOCUMENT_ROOT'];
exec('ls /usr/* 2>&1', $output);
print_r($output);
?>

until i reached a working php folder. great. Thanks for your help.