Recently, I was working on one of my projects. To deploy the application, I first created a domain and set up the database using CloudPanel (a web server control panel). After that, I accessed my VPS using Git and set up my deployment using GitHub Actions—essentially building a standard CI/CD pipeline.

However, right after deployment, I faced a major issue with my code: severe file permission errors. In my local development environment, everything worked flawlessly. But once deployed, multiple parts of the application suddenly broke. File uploads failed, logs wouldn't write, and several other background tasks stopped working.

After spending almost two days diagnosing the problem, I finally found the root cause: it was simply a file ownership issue.

Many control panels like CloudPanel create a dedicated system user for each domain for security reasons. The PHP worker processes run strictly under that specific domain user. However, because I gave my GitHub Actions runner root access via SSH to deploy the files, the newly deployed files were assigned to the root user on the server. Because the PHP worker process (running as the domain user) did not have permission to modify files owned by root, the application broke.


Below, I have shared a simple PHP script you can use to easily diagnose this exact kind of error, along with the commands to resolve it.

Find out Which user is run in you worker process

php
<?php

header('Content-Type: text/plain');

$uid = posix_geteuid();
$gid = posix_getegid();

$user = posix_getpwuid($uid);
$group = posix_getgrgid($gid);

echo 'PHP user: ' . ($user['name'] ?? $uid) . PHP_EOL;
echo 'PHP group: ' . ($group['name'] ?? $gid) . PHP_EOL;
echo 'UID: ' . $uid . PHP_EOL;
echo 'GID: ' . $gid . PHP_EOL;

?>

Change ownership using terminal

bash
sudo chown -R example:example /root-folder
  • -R (Recursive if you want all the subfolder and file)
  • example (first example is user and second one is group)
  • note: in your case username and group could be other