How to fix: File is locked error?

In this simple tutorial Cloudamo will show you how to fix file is locked error when trying to edit or delete a file on Nextcloud. This error means that the file is being used by another process or user, and you cannot modify it until it is released. This can be frustrating and prevent you from working on your files.

Fortunately, there are some ways to fix this error and unlock your files. In this tutorial, we will show you three methods to do so, using cPanel or similar, which is a web-based control panel for managing your web hosting account. You will need to have access to your cPanel account and your Nextcloud database to follow these steps.

Method 1: Disable file locking in Nextcloud config file

One way to fix the file is locked error is to disable the file locking feature in Nextcloud. This feature is meant to prevent concurrent access and conflicts on files, but it can also cause problems if the locks are not released properly. To disable file locking, you need to edit the Nextcloud config file, which is located in the config folder of your Nextcloud installation. You can use the File Manager tool in cPanel to find and edit this file.

  • Log in to your cPanel account and navigate to the File Manager tool.
  • Locate the config folder of your Nextcloud installation and open it.
  • Find the file named config.php and right-click on it. Select Edit from the menu.
  • In the editor, look for the line that says 'filelocking.enabled' => true, and change it to 'filelocking.enabled' => false,
  • Save the file and exit the editor.

This will disable the file locking feature in Nextcloud and you should be able to edit or delete your files without any error.

Method 2: Empty the file locks table in Nextcloud database

Another way to fix the file is locked error is to empty the file locks table in Nextcloud database. This table stores the information about the locked files and the processes or users that are using them. Sometimes, the locks are not cleared after the files are closed, and they remain in the table. To empty the file locks table, you need to access your Nextcloud database using the phpMyAdmin tool in cPanel.

  • Log in to your cPanel account and navigate to the phpMyAdmin tool.
  • Select your Nextcloud database from the left sidebar.
  • Find the table named oc_file_locks and click on it.
  • Click on the Operations tab at the top.
  • Under the Table maintenance section, click on the Empty the table (TRUNCATE) link.
  • Confirm the action by clicking on OK.

This will delete all the records from the file locks table and you should be able to edit or delete your files without any error.

Method 3: Use the occ command to scan and repair the file system

The third way to fix the file is locked error is to use the occ command to scan and repair the file system. The occ command is a command-line tool that allows you to perform various operations on your Nextcloud instance. One of the operations is to scan and repair the file system, which can detect and fix any issues with the file locking mechanism. To use the occ command, you need to access your Nextcloud installation folder using the Terminal tool in cPanel.

  • Log in to your cPanel account and navigate to the Terminal tool.
  • Change the directory to your Nextcloud installation folder by typing cd /path/to/nextcloud and pressing Enter. Replace /path/to/nextcloud with the actual path of your Nextcloud installation folder.
  • Run the occ command to scan and repair the file system by typing php occ files:scan --all and pressing Enter. This will scan all the files and folders in your Nextcloud instance and fix any issues with the file locking mechanism.
  • Wait for the command to finish and then exit the Terminal tool.

This will scan and repair the file system and you should be able to edit or delete your files without any error.

Conclusion

In this tutorial, we have shown you three ways to fix the file is locked error in Nextcloud with use of cPanel. You can try any of these methods to unlock your files and resume your work on Nextcloud. We hope you found this tutorial helpful and informative. If you have any questions or feedback, please let us know in the comments below.

3 Likes

Thank you! it worked perfectly. FYI in the config folder there is a php file “config.sample.php” with a lot of settings and parameters you can add to the “config.php” file. One of these is: ` ‘filelocking.enabled’ => true,
If is not in config.php just add it. I put it after
Like this:

$CONFIG = array (…)
‘filelocking.enabled’ => false,

Hi guys. I also experience a problem with any file that is being opened. Once the file gets opened, the file obviously gets locked as my locking is still enabled.

After we close the file, the file stays locked even after the cron finished.

I tested this with Excel locally and it locks the file on open, but does not unlock when the file is closed and the file goes into read only mode.

On Collabora the same happens. Once the file gets opened, the file is locked, but when you close the file, it stays locked.

I have disabled the file locking for now, but this is a huge problem. We still on Nextcloud 26.0.10.

2 Likes

Hello.
We are facing the same pb since 10 days, the file is locked and does not want to unlock even when it is closed. Impossible to unlock even with Admin profile, we have to call users one by one !!
Did you find a solution ?

We have Cloud 27.1.5, last version of Temporary files locking and sync client PC.

1 Like

I’m also experiencing this insane issue. It’s super annoying. Why is this so bad… it’s such a key feature, so hard to collaborate when you have to deal with this all the time

3 Likes

I had the same problem once and it really wasn’t nice.

But the Music Player app was the problem for me; it had a folder (e.g. Private) as the default music file path and then I was no longer able to delete all the files in this folder.

When I changed the file path in the Music app, everything worked again.