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

Hello [rakekniven],

I installed this app on my Nextcloud which is hosted on Hetzner.

However, it is not clear to me how I should then run occ…

If I just type
update
then nothing happens

Once in OCCweb, which command shall I use to upgrade to the next nextcloud version ?

Thank you !
Vincent

Please see https://apps.nextcloud.com/apps/occweb and https://git.adphi.net/adphi/occweb

This app is deprecated and should not be used anymore.

btw. it was never designed for upgrading an NC instance.

Hi rakekniven

Thank you for keeping us up to date on this! I am glad I read until your final post - do you know an alternative?

I have SSH-access to the managed server (Hetzner) but no sudo-rights. This means I can run occ-commands but I can’t specify the user to www-data first. I suppose it would be unsafe to simply run

php occ maintenance:mode --on
php occ db:convert-filecache-bigint

am I right?

All the best,
Maggo

I think your user is the user the webserver is running as. So I would give it a try.

No - security is not an issue here.

Hi! Thank you guys for your quick replies! I just wanted to make sure I won’t mess with the permissions as the warning in the manual says. Thank you for reassuring me :slight_smile:

I found alternative options in the admin manual to set the user without sudo but haven’t successfully tried them yet (rtfm, sorry, I know…). It might help someone else, who knows.

https://docs.nextcloud.com/server/20/admin_manual/configuration_server/occ_command.html#http-user-label