Nextcloud does not allow moving the data folder?

I hope somebody in the community can help me because I have hit a brick wall. Is there anyway the command below can be written in a different way that does not involve using the OCC portion?

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

I cannot move my Nextcloud v25.0.4 root data folder to my secondary 8TB data drive due to how the OCC portion of the command above generates the Memchache PHP error shown below:

An unhandled exception has been thrown: OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

I am a newbie. So I do not have the needed advanced skills to fix this problem. I would appreciate it a lot if anybody in the community can share step by step instructions on how to fix this specific problem. I am running PHP 8.1.2 and Nextcloud v25.0.4 and Ubuntu Server 22.

Vincent,
I have looked at the link you provided which provides a link to a second website. I read through the various posts and I found none to be helpful due to how none provide a step by step explanation on how to implement the correct fix.

Moreover, to quote your Nov '22 post you say:
"this time set it systemwide in /etc/php/8.1/mods-available/apcu.ini "

Can you elaborate on this with more steps? Is what you say the correct fix I need to follow to fix my Memcache PHP problem? Additionally, do I need to install “php-apcu” onto my Ubuntu Server? Are the “Install php-apcu Using apt-get” steps listed in the link below the correct course of action I should take to fixing my Memcache PHP problem?

https://installati.one/install-php-apcu-ubuntu-20-04/

Lastly, is there a script I can run that can fix this Memcache PHP problem? Any advice will be greatly appreciated because as I said in the beginning I have hit a brick wall. Thank you for your time.

Are you using FPM or apache2 php?

Try this:

vi /etc/php/8.1/cli/php.ini
#and add in bottom the file: 
apc.enable_cli = 1 

However for CRON, you have to also add this line to your fpm php.ini file (if running PHP-FPM).

you could manualy edit /var/www/nextcloud/config/config.php with your text editor of choice.
and change ‘maintenance’ => ‘false’, to true

if you place the line what Kerasit said

apc.enable_cli = 1
in /etc/php/8.1/mods-avaiable/apcu.ini it should solve the memcache problem.

Kerasit, thank you for your post. To answer you question I used the command shown below to learn what version of Apache I am running:

me@mysrvr:~$ apache2 -v
Server version: Apache/2.4.52 (Ubuntu)
Server built:   2023-03-08T17:32:01

As for CRON it seems I do not need to worry about it because I am running Apache version 2.4.52. Additionally, I am running PHP 8.1.2 and Nextcloud v25.0.4 and Ubuntu Server 22.

Just to confirm, by adding the code below to my php.ini file:

apc.enable_cli = 1

My Ubuntu server should be able to run the Linux command below with no longer generating a Memcache PHP handling error:

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

In short, if the command above is successful I will finally be allowed to move my NextCloud root data folder to my secondary 8TBdata folder. I will try it out and let everybody know the results I get. Thank you for the advice.

Vincent, thank you for your post. I am going to give Kerasit’s approach a try. If it does not work I will try your approach relating to editing my config.php by changing the ‘maintenance’ => ‘false’, to true.

Thanks for the help. And on a closing note, I am totally perplexed by how complex this task to move my NextCloud root data folder to my secondary 8TBdata drive has become due to these conflicts in the software. The way I understand it the Apache2 and/or PHP software is preventing the OCC maintenance mode command to work. Is this assessment correct?

Well to cut it in stone and make it simple:

OCC is a command line tool. It executes on the local host (on the machine where the command is executed) independant on any webserver or not. In fact you could execute OCC commands with no webserver on that machine at all. Apache2 is not blocking you from this.

OCC is a nextcloud library, so it will also be dependant on the nextcloud php files and settings. So yes, you needs to add apc.enable_cli = 1 to the php ini file relevant for handling the machine command line stuff. This USUALLY is the standard php librabry /etc/php/8.1/cli/, but can ALSO be set on the global settings for the PHP engine itself in the master php.ini file. There are in fact several places this can be set. Setting it in /etc/php/8.1/mods-avaiable/apcu.ini ensures that any PHP engine (php system interpretor, PHP-FPM or PHP-CLI - which all uses the same PHP modules installed) will always allow this setting regardless. There is security issues with allowing CLI execution from the PHP engine used by your webserver, as in a rare case there is a vulnerability in nextcloud, it can execute commandline commands in the context of the webserver user. So I highly recommends to set this value ONLY in the CLI php.ini file, as that one is never used by the webserver, but will definately be used by systemcron when setting that up. This, however, is independant on Nextcloud itself, but as a result of Linux+PHP and would be the same issue and case regardless of PHP app.

Try do run this to see what happens:
sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on

To explain:
You asks the Linux host itself to run that OCC command using the default PHP engine it knows based on default environment settings, and you also tells it to - regardless of php.ini files - add the apc.enable_cli=1 in the config it loads. Essentially this enables APCu with that command.

If this is a success, then yes. You will have to add apc.enable_cli=1 at the bottom of the correct .ini file.

1 Like

Kerasit,
Thank you for your post. Below is the result I got after i executed your posted command line.

me@mysrvr:/$ sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on
Console has to be executed with the user that owns the file config/config.php
Current user id: 33
Owner id of config.php: 0
Try adding 'sudo -u #0' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u 0' to the docker command (without the single quotes)

I then added the ‘sudo -u #0’ as shown below:

sudo -u #0 www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on

Below is the result I got:
sudo: option requires an argument -- 'u'

I then Googled the problem and tried the modified command below based on the post below:
sudo -u 'www-data' php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on

My skills are not advanced enough to see what the problem is but here is what does not make sense to me. The command above is defining sudo -u 'www-data' as a user. Isn’t the ‘www-data’ user the correct user to integrate into the command line? Why is it rejecting the use of the ‘www-data’ user?

Below are the steps as I understand them so far:
Step#1: Run command line below.
sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on

Step#2: Add apc.enable_cli = 1 to php ini file located at /etc/php/8.1/cli/. And you also say to addapc.enable_cli=1 at the bottom of the correct .ini file. Can you tell me which one is the correct .ini file?

Step#3: Copy the existing data to it’s new location
sudo -u www-data cp -r /var/www/nextcloud/data/. /mnt/8TBdata/

Step#4: Set your new data location
sudo -u www-data php /var/www/nextcloud/occ config:system:set datadirectory --value=/mnt/8TBdata

Step#5: Disable maintenance
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off

Any advice anybody in this forum can offer about this new problem relating to my manually installed Nextcloud will be greatly appreciated. Thank you for your time.

Hold on here. There is something that does not make sense.

Which user runs your webserver? root or www-data?

Try do:

ls -l /var/www/nextcloud

Who owns the Nextcloud library?

Then try do:

ps -aux | grep apache

There should be a couple of processes. But is ANY of them running as www-data?

Are you using php-fpm then you needs to also do:

ps -aux | grep php-fpm

Which user does this run as?

The user who owns the entire Nexctloud library - AND all subfolders and files - HAS to be the one that also executes PHP. If NOT running php-fpm, it most likely is an apache module, hence apache user (usually this is www-data) needs to be the owner. If running php-fpm, it is the user running the php-fpm process. These does not HAVE to be the same, but it is easier (and theorethically only raises risk a fraction) to have it running by the same user.

BTW, on RHEL and similar systems (Fedora, Alma, Rocky, CentOS …) the apache user is apache:apache.

1 Like

sorry to fall in your good help. but as you can read in the post the OP is unexperienced.

/var/www/nextcloud is owned by www-data screenshot first post.

OS: Ubuntu 22.04
php 8.1 fpm
mysql

ps aux imo too much for OP

try for apache user

cat /etc/apache2/envvars | grep ‘USER’

for php-fpm user try

cat /etc/php/8.1/fpm/pool.d/www.conf | grep user

check permission of config.php maybe you edited it with root and permissions got changed

ls -la /var/www/nextcloud/config/config.php

number 0 means owned by root it should be owned by number 33 user www-data.

to run as root you ommit the -u which tells the sudo command to use a different user then the root. but we don’t want to do that.

the line is used in a script/config file ‘www-data’ or no ’ ’ makes no differance on the command line

you only add this line once to /etc/php/8.1/cli/php.ini

once done you need to reload php-fpm

sudo systemctl restart php8.1-fpm

1 Like

Kerasit,
Thank you for your post. Below I have posted all three results I got after running your three command lines. I hope the results below helps you in determining what what is preventing me from running the two command line variations shown below which do not work:

sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

Which user runs your webserver? root or www-data?

me@mysrvr:~$ ls -l /var/www/nextcloud
total 168
drwxr-xr-x 47 www-data www-data  4096 Mar  5 19:17 3rdparty
drwxr-xr-x 57 www-data www-data  4096 Mar 20 02:02 apps
-rw-r--r--  1 www-data www-data 19327 Feb 23 10:30 AUTHORS
drwxr-xr-x  2 www-data www-data  4096 Mar 30 18:08 config
-rw-r--r--  1 www-data www-data  4095 Feb 23 10:30 console.php
-rw-r--r--  1 www-data www-data 34520 Feb 23 10:30 COPYING
drwxr-xr-x 23 www-data www-data  4096 Mar  5 19:17 core
-rw-r--r--  1 www-data www-data  6317 Feb 23 10:30 cron.php
drwxrwx---  6 www-data www-data  4096 Mar  5 19:17 data
drwxr-xr-x  2 www-data www-data 16384 Mar  5 19:17 dist
-rw-r--r--  1 www-data www-data   156 Feb 23 10:30 index.html
-rw-r--r--  1 www-data www-data  3456 Feb 23 10:30 index.php
drwxr-xr-x  6 www-data www-data  4096 Mar  5 19:17 lib
-rw-r--r--  1 www-data www-data   283 Feb 23 10:30 occ
drwxr-xr-x  2 www-data www-data  4096 Mar  5 19:17 ocm-provider
drwxr-xr-x  2 www-data www-data  4096 Mar  5 19:17 ocs
drwxr-xr-x  2 www-data www-data  4096 Mar  5 19:17 ocs-provider
-rw-r--r--  1 www-data www-data  3139 Feb 23 10:30 public.php
-rw-r--r--  1 www-data www-data  5549 Feb 23 10:30 remote.php
drwxr-xr-x  4 www-data www-data  4096 Mar  5 19:17 resources
-rw-r--r--  1 www-data www-data    26 Feb 23 10:30 robots.txt
-rw-r--r--  1 www-data www-data  2452 Feb 23 10:30 status.php
drwxr-xr-x  3 www-data www-data  4096 Mar  5 19:17 themes
drwxr-xr-x  2 www-data www-data  4096 Mar  5 19:18 updater
-rw-r--r--  1 www-data www-data   383 Feb 23 10:32 version.php

Who owns the Nextcloud library?

me@mysrvr:~$ ps -aux | grep apache
root        1025  0.0  0.0 274568 38108 ?        Ss   15:53   0:00 /usr/sbin/apache2 -k start
www-data    1038  0.0  0.0 275124 15472 ?        S    15:53   0:00 /usr/sbin/apache2 -k start
www-data    1039  0.0  0.0 275124 15472 ?        S    15:53   0:00 /usr/sbin/apache2 -k start
www-data    1040  0.0  0.0 275124 15472 ?        S    15:53   0:00 /usr/sbin/apache2 -k start
www-data    1041  0.0  0.0 275124 15472 ?        S    15:53   0:00 /usr/sbin/apache2 -k start
www-data    1042  0.0  0.0 275124 15472 ?        S    15:53   0:00 /usr/sbin/apache2 -k start
me                 1779  0.0  0.0   6476  2332 pts/0    S+   15:59   0:00 grep --color=auto apache

Are you using php-fpm then you needs to also do:

me@mysrvr:~$ ps -aux | grep php-fpm
me              1786  0.0  0.0   6476  2356 pts/0    S+   16:01   0:00 grep --color=auto php-fpm

You ask which user runs my entire Nexctloud library - AND all subfolders and files? Does the information shown above answer this question for you?

I can tell you the “me” user is my normal Ubuntu Server user account. If I want to access to something at the ROOT level I need to use a special ADMIN password.

I hope you can clarify what you think is the problem with the information I have posted. Thank you for your time.

i got confused

Okay so far.

Now ls -l of the …./Nextcloud/config folder.

The error message it shows you is specifically that it is not the right owner you use for sudo

Yes. This is all accurate.

I suspects that after manually editing the config.php, it has changed ownership.

sudo chown -R www-data:www-data /var/www/nextcloud

I forgot to mention i ran Vincent’s commands shown below he previosly posted. So maybe that changed the user owner? However, his OCC command never worked due to a handling error.

setting the user we use

sudo chown www-data:www-data /mnt/8TBdata

setting the file we use

sudo chmod 750 /mnt/8TBdata

But i don’t follow how the config.php file got changed because i have not changed it using NANO txt editor.

Never the less your system reported that the nextcloud config file is not owned på www-data but is owned by root. This has to be changed. My command makes sure that all files in Nextcloud and underneath, is owned by correct user.

www-data also needs to own the data folder and below.

Kerasit,
Sorry, I did not include the following in my last post. Below is the result I got after running the command line you specified which is the
ls -l command line
to the NextCloud config folder path below:
/var/www/nextcloud/config/

me@mysrvr:~$ ls -l /var/www/nextcloud/config/
total 76
-rw-rw---- 1 root     www-data   837 Mar 20 02:02 config.php
-rw-r--r-- 1 www-data www-data 72711 Feb 23 10:30 config.sample.php

It clearly shows the config.php file is owned by “root” user and not “www-data” user. So this is a problem.

If I understand you correctly, running the command line below should change the “root” owner to “www-data” owner.
sudo chown -R www-data:www-data /var/www/nextcloud

After that is done your command line below should work without a problem:

sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on

I will try it tomorrow.

This is the issue. In fact the owner and chmod settings is not accordingly to recommended for Nextcloud. But they will be fixed with an update - if ownership is correct.

Read this thread:

Kerasit,
Thank you for your post. Here is my update.

Step #1:
I successfully changed the “root” ownership to “www-data” ownership as shown in command lines below:

me@mysrvr:~$ sudo chown -R www-data:www-data /var/www/nextcloud
[sudo] password for me:
me@mysrvr:~$ ls -l /var/www/nextcloud/config/
total 80
-rw-rw---- 1 www-data www-data   838 Apr  1 17:33 config.php
-rw-r--r-- 1 www-data www-data 74456 Mar 21 09:20 config.sample.php

Step #2:
I then was able to successfully change to maintenance mode as shown in command line result below. This was not possible before due to a unhandled error. But now it works and thank you for your help with this command line.

me@mysrvr:~$ sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on
Maintenance mode enabled

Step #3:
I then used the command line below to copy the existing data to it’s new location:
me@mysrvr:~$ sudo -u www-data cp -r /var/www/nextcloud/data/. /mnt/8TBdata/

Step #4:
I then used the command line below to set my new data location and I got the unhandled error shown below:

me@mysrvr:~$ sudo -u www-data php /var/www/nextcloud/occ config:system:set datadirectory --value=/mnt/8TBdata
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

Step #5:
I disabled maintenance mode using the command line shown below:

me@mysrvr:~$ sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --off
Maintenance mode disabled

My new problem is at Step #4. Do you or anybody in the forum have any advice on what is the correct command line I need to use to set my new data location successfully? Any information will be greatly appreciated. Thank you for your time.

Have you tried just changing 'datadirectory' => '/var/www/nextcloud/data' in your config.php to 'datadirectory' => '/mnt/8TBdata'?

1 Like