Permission denied error

Discussion in 'Apache' started by sivasankari, Aug 12, 2009.

  1. #1
    hi everybody,

    I am trying to execute a system command through apache web browser using perl/cgi scripting and also trying to write the system command return value into a file name call session.txt.

    If i execute the following code in normal perl programming it's executing fine if i am trying to execute the same through apache web browser it showing 512 error for system command and also i can't open,write or read a file through apache web browser and the error message that i am getting in the httpd error log is

    Error Message:

    [Thu Aug 13 11:28:57 2009] [error] [client 59.163.89.119] ls:
    [Thu Aug 13 11:28:57 2009] [error] [client 59.163.89.119] /var/lib/php/session/
    [Thu Aug 13 11:28:57 2009] [error] [client 59.163.89.119] : Permission denied
    [Thu Aug 13 11:28:57 2009] [error] [client 59.163.89.119]
    [Thu Aug 13 11:28:57 2009] [error] [client 59.163.89.119] Permission denied at /var/www/cgi-bin/kkkkk.pl line 4.


    
    #!/usr/bin/perl
    print "Content-type:text/html\n\n";
    @var=`ls -tr /var/lib/php/session/`;
    open(FILE,"/var/lib/php/session/$var[$#var]") or die $!;
    $filename=<FILE>;
    close(FILE);
    open(OUT,">/var/www/html/web-meetme/session.txt") or die $!;
    print OUT $filename;
    close(OUT);
    
    Code (markup):

    Thanks in advance
     
    sivasankari, Aug 12, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    try chmoding this folder /var/lib/php/session/ to 0777
     
    Bohra, Aug 13, 2009 IP
  3. vasyl

    vasyl Peon

    Messages:
    138
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It executes normal from shell because you are executing it probably as root.
    Apache executes it as apache effective user (cat /etc/httpd/conf/httpd.conf | grep ^User) so it probably more secure way is to chown the /var/lib/php/session/ to apache effective user
     
    vasyl, Aug 13, 2009 IP