How to use occ commands on a Shared Hosting without SSH access

On some hosters it is possible to use a separate PHP-file to perform occ commands. It depends on the settings of the hoster though, whether that will work or not (it works with mine). It might be worth a try:

  1. create a file on your webspace called occ-command.php (or whatever you wanna call it) with the following content (adjust RELATIVE/PATH/TO/occ to point to your occ in the nextcloud-installation folder; also the path to php possibly needs to be adjusted):
    <?php 
       exec("/usr/bin/php -d memory_limit=1024M RELATIVE/PATH/TO/occ -n status > occ_result.txt");
       exec("echo \"Command completed!\" >> occ-result.txt 2>&1");
       header('Location: occ-result.txt');
    ?>
    
  2. visit occ-command.php with a browser
  3. after executing the command, the browser will be redirected to a logfile (occ-result.txt)
  4. some providers block the php-function exec. If that is the case, you can try to replace exec with passthru, system or shell_exec.
  5. for security reasons it is better to delete occ-command.php and occ-result.txt from your webserver when you are done.
4 Likes