-2

After following the PHP implementation from the captcha guide, I get the following messages on the page where the captcha should appear:

Warning: require_once(/var/www/resources/recaptchalib.php): failed to open stream: Permission denied in /var/www/submit.php on line 49
Fatal error: require_once(): Failed opening required '/var/www/resources/recaptchalib.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/submit.php on line 49

My line 49 is:

require_once($_SERVER['DOCUMENT_ROOT'].'/resources/recaptchalib.php');

What am I doing wrong?

  • Help with what? What is unclear about the error message? What is the question? Have you tried diagnosing it yourself? – PeeHaa Feb 19 '14 at 08:26
  • If I knew what to do or how to diagnose the issue, I wouldn't be here, would I? – user3226844 Feb 19 '14 at 08:28
  • Well I'm sorry to say, but if you cannot read a simple error messages or interpret what it is trying to tell you (possible with the use of the google) you probably should find a different profession – PeeHaa Feb 19 '14 at 08:29
  • What does a profession have to do with this? I'm a mechanic. – user3226844 Feb 19 '14 at 08:31
  • Also exact duplicate of http://stackoverflow.com/a/12820243/508666 – PeeHaa Feb 19 '14 at 08:31
  • @user3226844, @PeeHaa is probably being a bit harsh, but try to read carefully the error messages. `Failed to open stream: Permission denied` seems a pretty clear message, you should ask or look for "How do I grant permission to this file in php" or something similar – aleation Feb 19 '14 at 08:35
  • The thing is, what permission do I give to it, since I've heard it could just cause security issues if you give it the wrong numbers. I know how to do a chmod, but do i need to give it permission to execute, or just to read/write? – user3226844 Feb 19 '14 at 08:38
  • whenever you are not sure, give it permissions gracefully, first read, and see if it works, then read/write etc... in this case I think that with just read permissions you should be fine – aleation Feb 19 '14 at 08:39
  • Tried them all, including 777. Still the same problem. – user3226844 Feb 19 '14 at 08:42
  • Ahh hold on. I was changing the permissions on submit.php, rather than the captchalib. That's working on 777, so I'm going to try restricting the permissions until I get it to the minimum level required to work. – user3226844 Feb 19 '14 at 08:47
  • You will need only probably a 755 (owner: read, write, execute; group: read, execute; others: read, execute), or if it is included from php, then 744. :) – András Iványi Feb 19 '14 at 10:04
  • Currently using 644. Seems to be working fine. – user3226844 Feb 20 '14 at 08:39

1 Answers1

0

My first guess would be: nothing, your code is probably okay.

The error message tells everything, probably the file access rights (or ACL-s) are misconfigured. The user, who runs you webserver, does not have the neccessary rights to access that PHP file.

András Iványi
  • 317
  • 1
  • 10
  • This is what I had assumed, since I followed the guide to the letter. I'm not sure about the permissions though. What am I supposed to change it to, without adversely affecting security? Obviously I'm changing the permissions on the submit.php file, but to what? – user3226844 Feb 19 '14 at 08:25
  • 1
    The read/write permissions of a file is something you have to change at Operative System level normally (windows or osx or whatever), or when you create the file from php (although normally when you create a file from php it inherits the permissions). Google about "How to give permission to a file in *your server's operative system*" – aleation Feb 19 '14 at 08:38