octobercms/october · error · ApplicationException
cms::lang.lang.error_deleting_file
Error message
cms::lang.lang.error_deleting_file
What it means
ApplicationException thrown by `Lang::delete()` when `File::delete($fullPath)` fails although the file exists: PHP could not unlink it. Almost always a permissions problem — no write/execute permission on the containing directory or the file is owned by a different user than the web server.
Source
Thrown at modules/cms/classes/Lang.php:315
* delete the object from disk
*/
public function delete()
{
$fullPath = $this->getFilePath();
$this->validateFileName();
if (!FileHelper::validateInTheme($this->theme, $fullPath)) {
throw new ValidationException(['fileName' =>
LangHelper::get('cms::lang.cms_object.invalid_file', [
'name' => $this->fileName
])
]);
}
if (File::exists($fullPath)) {
if (!@File::delete($fullPath)) {
throw new ApplicationException(LangHelper::get(
'cms::lang.lang.error_deleting_file',
['name' => $this->fileName]
));
}
}
}
/**
* validateFileName supplied with extension and path.
*/
protected function validateFileName($fileName = null)
{
if ($fileName === null) {
$fileName = $this->fileName;
}
$fileName = trim($fileName);
View on GitHub (pinned to b608633a7e)
Solutions
- Fix ownership of the file and its directory: `chown -R www-data:www-data themes/<theme>/lang`.
- Ensure the directory itself is writable by the web server (unlink permission lives on the directory, not the file).
- As a last resort delete the file manually over SSH, then retry the UI operation.
Example fix
# before — directory owned by root; unlink denied $ ls -ld themes/mytheme/lang drwxr-xr-x root root themes/mytheme/lang # after — unlink permission is on the directory sudo chown www-data:www-data themes/mytheme/lang sudo chmod u+rwx themes/mytheme/lang
Defensive patterns
Strategy: validation
Validate before calling
$path = $lang->getFilePath();
if (file_exists($path) && (!is_writable($path) || !is_writable(dirname($path)))) {
return back()->with('error', 'File or directory is not writable — fix ownership before deleting.');
}
$lang->delete(); Try / catch
try {
$lang->delete();
} catch (ApplicationException $e) {
// unlink failed: report which path and its perms for quick ops triage
Log::error('Lang delete failed', ['path' => $lang->getFilePath(), 'perms' => @fileperms($lang->getFilePath())]);
throw $e;
} Prevention
- Remember unlink permission depends on the directory, not the file — check both.
- Standardize on a single owning user for web and CLI file operations.
- Automate ownership repair (chown) as part of post-deploy steps.
When it happens
Trigger: Deleting a lang file created by a root CLI session so www-data cannot unlink it; directory without write permission for the PHP user; file held open / immutable flag set on some filesystems.
Common situations: Mixed CLI/web file ownership after deploys; hardened production dirs; containers where the volume is mounted read-only.
Related errors
- cms::lang.cms_object.error_creating_directory
- cms::lang.cms_object.error_saving
- editor::lang.filesystem.error_renaming
- editor::lang.filesystem.error_deleting_file
- editor::lang.filesystem.error_deleting_dir
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/ce33fef425ac5042.
Report an issue: GitHub.