title: Perl CGI PHP Session Permission Denied
body: <p>I'm trying to get PHP session variables into a Perl CGI script.  I've got the following perl code below which seems to work in getting me the PHPSESSID which I then pass to the PHP::Session along with the directory where the session files are stored.</p>
  
  <pre><code>my $cookie_name='PHPSESSID'; 
  my $sess_query = new CGI;
  my $session_name = $sess_query-&gt;cookie($cookie_name);
  my $session = PHP::Session-&gt;new($session_name,{save_path =&gt;'/var/lib/php/session/'});
  </code></pre>
  
  <p>My problem is occuring when I get a permission denied error</p>
  
  <blockquote>
    <p>[Fri Dec  2 16:52:44 2011] upload.cgi: /var/lib/php/session/sess_417ar7qsh4sh853gqs3bj454i5: Permission denied at /var/www/html/xxx/upload.cgi line 22, referer:...</p>
  </blockquote>
  
  <p>The line 22 is the <code>PHP::Session-&gt;new</code> line in the above code.</p>
  
  <p>My httpd server is running as user apache and the cgi scripts are owned by apache as are all the sesssion files in <code>/var/lib/php/session/</code> so I'm wondering why wouldn't the CGI script be able to read the session files.</p>
  
  <p>I read online where one person use LWP as a workaround, but that's not my preference as I feel this is something silly on permissions that I'm missing. </p>
  
  <hr>
  
  <p><strong>UPDATE:</strong> Added info - here are the session files - as you can see the session file exists and is owned by apache, but the CGI perl script can't read these:</p>
  
  <pre><code>-rw-------. 1 apache apache   0 Dec  2 16:58 /var/lib/php/session/sess_417ar7qsh4sh853gqs3bj454i5
  -rw-------. 1 apache apache 126 Dec  2 16:58 /var/lib/php/session/sess_f39ot5ul3bu55uu7d1rg3aqq02
  </code></pre>