title: Linux Permissions And PHP - Groups
body: <p>Here's an aspect of Linux/PHP permissions that always trips me up and I don't understand how to fix it. </p>
  
  <p>I need to allow my PHP script to update 'phone-guide.json' which is owned by 'user1'.</p>
  
  <p><img src="https://i.stack.imgur.com/FuG0G.jpg" alt="enter image description here"></p>
  
  <p>PHP is running as www-data on my web server.</p>
  
  <pre><code>&lt;?php exec('whoami'); ?&gt; // outputs 'www-data'
  </code></pre>
  
  <p>In etc/group, 'user1' is part of the 'www-data' group and vice-versa.</p>
  
  <p><img src="https://i.stack.imgur.com/abJn8.jpg" alt="enter image description here"></p>
  
  <p>If 'www-data' is in the same group as 'user1', a PHP script running as 'www-data' <strong>should</strong> be able to update/change/modify the phone-guide.json file because it is also part of the 'user1' group with (rwx) group permissions... correct?  </p>
  
  <p>However, my PHP script can't update the phone-guide.json file <strong>until</strong> I change the ownership and group of phone-guide.json to www-data:www-data ... then everything works.</p>
  
  <p>I though the whole purpose of 775 (rwxrwxr-x) permissions was to let any user who is part of the same group to read/write/execute the file (rwx).</p>