When a PHP script is executed on a Linux system, the permissions it operates under depend on how it is being executed.
Command Line Interface (CLI):
If a user executes a PHP script directly from the command line (e.g., php script.php), the script will run with the permissions of that specific user. This means it can access, create, or modify files and directories that the user themselves has permission to interact with.
Web Server (e.g., Apache, Nginx):
When a PHP script is executed via a web server, the situation changes. By default, the script will run with the permissions of the user account the web server is running under. This is typically a dedicated user like www-data (on Debian/Ubuntu systems) or apache (on Red Hat/CentOS systems). In this scenario, the PHP script will only have access to resources that the web server user has permissions for, not the permissions of the user who initiated the web request from their browser.
Specific Configurations (e.g., suPHP, FPM with user pools):
In some environments, especially shared hosting or more secure configurations, mechanisms like suPHP or PHP-FPM with per-user pools are used. These configurations allow PHP scripts to be executed under the permissions of the owner of the script file, rather than the web server's user. This provides better isolation and security, as one user's PHP scripts cannot easily interfere with another user's files.