Sunday, 20 March 2011

PHP Error: Permission denied in Unknown at line 0 [FIX]

I was setting up a quick PHP test in my home directory today, but when I tried to load my file (http://localhost/~david/test.php) I encountered a strange error:

Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failed opening required '/home/david/public_html/test.php' (include_path='.:/usr/share/php5/PEAR:/usr/share/php5') in Unknown on line 0

My code was pretty simple - no "include" or "require" statements anywhere, and perfectly valid syntax. This puzzled me for some time - it appeared as if PHP was trying to "require" my test file in itself. As it turns out, that wasn't too far from the truth.

This error was simply caused by Apache (and therefore PHP) not having read permissions to my PHP file. So it could tell that the file was there (otherwise I would get a 404 error), but when PHP tried to open the file for reading it failed, due to my file permissions (in this case, 007). To fix the problem, I simply had to run:

chmod 777 /home/david/test.php

After this my PHP code ran perfectly. It's worth knowing that this kind of error can occur - it might save a lot of Googling like I had to do!

Note: Normally I wouldn't change the permissions on a PHP file to 777 (everyone has full access, including write). However, in this case it was just a simple test page running on localhost, so I wasn't too worried about security.

Wednesday, 9 March 2011

[FIX] qt-facetrainer does not generate model for user (pam-face-authentication on openSuSE)

I was setting up the pam-face-authentication module using opencv on openSuSE today (following this guide). The installation process went well, using the one-click-install package. However, after running qt-facetrainer and adding the correct entries to /etc/pam.d/sudo I encountered the following error:

david@laptop:~> sudo -s
> Camera 0
mmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
 Face Verification Pluggable Authentication Module Started
Biometrics Model not Generated for the User.
Giving Up Face Authentication. Try Again=(.
root's password:
root's password:
sudo: pam_authenticate: Authentication token manipulation error
The fix turned out to be simple. Instead of running qt-facetrainer as myself, I had to run it as root (kdesu qt-facetrainer). This generated a face model for the root user, which allows me to authenticate myself as root using sudo. I still encounter the munmap errors, but I am now able to authenticate myself for su and sudo using face recognition!