PHP safelock failed to create a lockfile

Flyer

Active Member
Jun 15, 2007
31
3
58
I have WHM v102.0.14 with PHP 8.0.18. Since upcp ran last night, PHP reports the following error on startup:

warn
PHP:
 safelock: Failed to create a lockfile '/etc/userdatadomains.lock-b232a7f711a9-4100a619-1250' in the directory '/etc' that isn't writable: Permission denied at /usr/local/cpanel/Cpanel/SafeFile.pm line 430.

This only happens with the user that I log in to the server with using ssh.  root and other users with their own cPanel domains are OK.  How do I fix it?
 
  • Like
Reactions: JOEsDC-Seth

kodeslogic

Well-Known Member
PartnerNOC
Apr 26, 2020
562
259
138
IN
cPanel Access Level
Root Administrator
Which OS you are using?
If by chance you are using CloudLinux then you try disabling/reenabling CageFS for that account.
 

Flyer

Active Member
Jun 15, 2007
31
3
58
I'm using CentOS 7.9.2009 on an Azure VM and haven't knowingly done anything with CageFS.
 

kodeslogic

Well-Known Member
PartnerNOC
Apr 26, 2020
562
259
138
IN
cPanel Access Level
Root Administrator
Please share the output for the following command:

Code:
# ls -ld /etc

# ls -l /etc/userdatadomains
 

Flyer

Active Member
Jun 15, 2007
31
3
58
$ ls -ld /etc
drwxr-xr-x. 118 root root 12288 May 4 14:50 /etc
$ ls -l /etc/userdatadomains
-rw-r-----. 1 root mail 873 May 4 09:14 /etc/userdatadomains

/etc/userdatadomains doesn't contain any information about the account I use to login to the server via ssh.
 
Last edited:

Flyer

Active Member
Jun 15, 2007
31
3
58
This could be the key here - is your SSH user also a cPanel user?
It's a non-root account that was created before cPanel was installed. It's been able to run PHP programs, until today. PHP was last updated on 20. April. It's not obvious from last night's cpup log that anything was updated then.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,261
2,431
363
cPanel Access Level
Root Administrator
I'm not sure there's going to be much help we can provide with that. Since cPanel doesn't control or manage those types of users, and we don't recommend anything is created before the cPanel installation takes place, you'll have to check things on your side.

You can check the Yum logs on the machine in /var/log/yum.log on a CentOS 7 machine and that would list any packages that were updated.
 

Flyer

Active Member
Jun 15, 2007
31
3
58
$ sudo tail /var/log/yum.log
Apr 26 23:28:26 Updated: mysql-connector-c++-jdbc-8.0.29-1.el7.x86_64
Apr 26 23:28:27 Updated: mysql-connector-odbc-8.0.29-1.el7.x86_64
Apr 26 23:28:28 Updated: mysql-community-icu-data-files-8.0.29-1.el7.x86_64
Apr 26 23:28:38 Updated: mysql-community-server-8.0.29-1.el7.x86_64
Apr 26 23:28:38 Updated: mysql-connector-odbc-setup-8.0.29-1.el7.x86_64
Apr 26 23:28:41 Updated: mysql-connector-c++-devel-8.0.29-1.el7.x86_64
Apr 26 23:28:41 Updated: mysql-community-libs-compat-8.0.29-1.el7.x86_64
Apr 26 23:28:41 Updated: mysql-community-devel-8.0.29-1.el7.x86_64
Apr 26 23:28:42 Updated: 1:mysql-connector-java-8.0.29-1.el7.noarch
Apr 26 23:28:56 Updated: mysql-shell-8.0.29-1.el7.x86_64

This has been working for a couple of years. I'm not sure at what stage the ssh user was created, but it existed when I was first able to access the Azure VM with Centos 7 and cPanel already installed, after it was created from a stock Azure image. The lock file must be a feature of cPanel, as /usr/local/cpanel/Cpanel/SafeFile.pm is failing to create it, so I don't agree that this is not a cPanel issue. Why is it getting involved when simply running this command?

$ php --version
 

dad-min

Member
May 4, 2022
8
4
3
California
cPanel Access Level
Root Administrator
Hello, I just registered this account to let you know I'm running into the same problem as of today 05/04/22 (the same CLI commands yesterday did not throw error)
Godaddy gen 4 VPS
CentOS v7.9.2009
cPanel & WHM v102.0.14 (STANDARD)

warn
PHP:
 safelock: Failed to create a lockfile '/etc/userdatadomains.lock-259bee0982fbf-cf99c699-166cb' in the directory '/etc' that isn't writable: Permission denied at /usr/local/cpanel/Cpanel/SafeFile.pm line 430.
        Cpanel::SafeFile::_write_temp_lock_file("/etc/userdatadomains.lock", "/etc/userdatadomains") called at /usr/local/cpanel/Cpanel/SafeFile.pm line 794
        Cpanel::SafeFile::_lock_wait("/etc/userdatadomains", Cpanel::SafeFileLock=ARRAY(0x243fee0), "/etc/userdatadomains.lock") called at /usr/local/cpanel/Cpanel/SafeFile.pm line 349
 

dad-min

Member
May 4, 2022
8
4
3
California
cPanel Access Level
Root Administrator
@dad-min - can you let me know what operation you're performing that leads to this error? Are just restarting the PHP service in WHM or performing some work in cPanel?
Actually, I was just running the reindex command via cli for my magento 2 store
php bin/magento indexer:reindex
Although it throws error using any php command via CLI... (which luckily end up getting executed still so I was able to reindex the catalog)

ls -ld /etc
drwxr-xr-x. 106 root root 12288 May 4 13:00 /etc
ls -l /etc/userdatadomains
-rw-r----- 1 root mail 253 May 4 11:36 /etc/userdatadomains
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
15,261
2,431
363
cPanel Access Level
Root Administrator
  • Like
Reactions: JOEsDC-Seth

dad-min

Member
May 4, 2022
8
4
3
California
cPanel Access Level
Root Administrator
Much like in a cron command, you'll likely get better results when calling the full path to the PHP binary, as outlined here:

Interesting, I appreciate the articles, although I use the command:
source /opt/cpanel/ea-php74/enable
which I'm pretty sure adds the full php path to my PATH file (at leastz my ssh instance)

Regardless, the same command has worked fine for years
 
  • Like
Reactions: JOEsDC-Seth

dad-min

Member
May 4, 2022
8
4
3
California
cPanel Access Level
Root Administrator
And this was when you were logged in to SSH as the cPanel user directly, correct?
No, my Cpanel user doesn't have shell access. I have a file system owner and a web server user - as per magento 2.4 docs.
I ssh in with one user to run composer, php commands, etc. The other user is the owner of the directory. They are both in the same user group.