Unable to run occ

Hi,

I am trying to run occ but it is saying that it cannot write to the apps directory, even though from what I can see it looks fine. Any help would be appreciated

root:/var/www/nextcloud# sudo -u www-data php occ
Cannot write into "apps" directory
This can usually be fixed by giving the webserver write access to the apps directory or disabling the appstore in the config file. See https://docs.nextcloud.com/server/12/go.php?to=admin-dir_permissions

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:145
Stack trace:
#0 /var/www/nextcloud/console.php(99): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')


root:/var/www/nextcloud# ll
total 180
drwxr-xr-x 17 root     www-data  4096 Sep 24 12:42 ./
drwxr-xr-x 13 root     root      4096 Sep 24 12:29 ../
drwxr-x--- 31 root     www-data  4096 Sep 19 23:14 3rdparty/
drwxrwx--- 38 www-data www-data  4096 Sep 24 13:32 apps/
drwxr-xr-x  3 root     root      4096 Sep 24 12:42 apps2/
drwxr-x---  2 www-data www-data  4096 Sep 24 12:29 assets/
-rw-r-----  1 root     www-data  8868 Sep 19 23:12 AUTHORS
drwxr-x---  2 www-data www-data  4096 Sep 24 13:00 config/
-rw-r-----  1 root     www-data  4050 Sep 19 23:12 console.php
drwxr-x--- 16 root     www-data  4096 Sep 19 23:14 core/
-rw-r-----  1 root     www-data  5057 Sep 19 23:12 cron.php
drwxr-x---  5 www-data www-data  4096 Sep 24 12:33 data/
-rw-r-----  1 root     www-data 41077 Sep 19 23:12 db_structure.xml
-rw-r--r--  1 root     www-data  2697 Sep 19 23:12 .htaccess
-rw-r-----  1 root     www-data   179 Sep 19 23:12 index.html
-rw-r-----  1 root     www-data  2804 Sep 19 23:12 index.php
drwxr-x---  3 root     www-data  4096 Sep 19 23:12 l10n/
drwxr-x---  6 root     www-data  4096 Sep 19 23:12 lib/
-rwxr-x--x  1 www-data www-data   283 Sep 19 23:12 occ*
drwxr-x---  2 root     www-data  4096 Sep 19 23:12 ocs/
drwxr-x---  2 root     www-data  4096 Sep 19 23:12 ocs-provider/
-rw-r-----  1 root     www-data  3152 Sep 19 23:12 public.php
-rw-r-----  1 root     www-data  5323 Sep 19 23:12 remote.php
drwxr-x---  4 root     www-data  4096 Sep 19 23:12 resources/
-rw-r-----  1 root     www-data    26 Sep 19 23:12 robots.txt
drwxr-x--- 14 root     www-data  4096 Sep 19 23:12 settings/
-rw-r-----  1 root     www-data  2110 Sep 19 23:12 status.php
drwxr-x---  3 www-data www-data  4096 Sep 19 23:12 themes/
drwxr-x---  2 www-data www-data  4096 Sep 19 23:12 updater/
-rw-r-----  1 root     www-data   163 Sep 19 23:12 .user.ini
-rw-r-----  1 root     www-data   435 Sep 19 23:14 version.php

root:/var/www/nextcloud/apps# ll
total 152
drwxrwx--- 38 www-data www-data 4096 Sep 24 13:32 ./
drwxr-xr-x 17 root     www-data 4096 Sep 24 12:42 ../
drwxrwx--- 10 www-data www-data 4096 Sep 19 23:14 activity/
drwxrwx---  4 www-data www-data 4096 Sep 19 23:12 admin_audit/
drwxrwx---  9 www-data www-data 4096 Sep 24 12:33 bruteforcesettings/
drwxrwx---  8 www-data www-data 4096 Sep 19 23:14 comments/
drwxrwx---  7 www-data www-data 4096 Sep 19 23:14 dav/
drwxrwx--- 11 www-data www-data 4096 Sep 24 12:39 documents/
drwxrwx--- 10 www-data www-data 4096 Sep 19 23:14 encryption/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 federatedfilesharing/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 federation/
drwxrwx--- 10 www-data www-data 4096 Sep 19 23:14 files/
drwxrwx--- 11 www-data www-data 4096 Sep 19 23:14 files_external/
drwxrwx--- 10 www-data www-data 4096 Sep 19 23:14 files_pdfviewer/
drwxrwx--- 10 www-data www-data 4096 Sep 19 23:14 files_sharing/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 files_texteditor/
drwxrwx--- 10 www-data www-data 4096 Sep 19 23:14 files_trashbin/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 files_versions/
drwxrwx---  7 www-data www-data 4096 Sep 19 23:14 files_videoplayer/
drwxrwx--- 10 www-data www-data 4096 Sep 19 23:14 firstrunwizard/
drwxrwx--- 13 www-data www-data 4096 Sep 19 23:14 gallery/
drwxrwx--- 13 www-data www-data 4096 Sep 19 23:14 logreader/
drwxrwx---  4 www-data www-data 4096 Sep 19 23:12 lookup_server_connector/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 nextcloud_announcements/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 notifications/
drwxrwx---  8 www-data www-data 4096 Sep 19 23:14 oauth2/
drwxrwx--- 11 www-data www-data 4096 Sep 19 23:14 password_policy/
drwxrwx---  5 www-data www-data 4096 Sep 19 23:14 provisioning_api/
drwxrwx--- 10 www-data www-data 4096 Sep 19 23:14 serverinfo/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 sharebymail/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 survey_client/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 systemtags/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 theming/
drwxrwx---  9 www-data www-data 4096 Sep 19 23:14 twofactor_backupcodes/
drwxrwx---  8 www-data www-data 4096 Sep 19 23:14 updatenotification/
drwxrwx---  5 www-data www-data 4096 Sep 19 23:14 user_external/
drwxrwx--- 11 www-data www-data 4096 Sep 19 23:14 user_ldap/
drwxrwx---  8 www-data www-data 4096 Sep 19 23:14 workflowengine/

You seem to using “apps2” as alternative apps directory, which is owned by root. Maybe the occ error says “apps” folder to any folder name that is set in config.php for storing apps.

So try to chown -R www-data:www-data apps2 also.

In case this does not resolve the issue, provide some more information about your system, nc version, config.php, webserver, php version etc.

Yep that fixed it, Thanks!