Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Sarah Quantick -
Number of replies: 15
I have set up a LAMP server using Fedora Core 6 as my linux operating system. On instaling Moodle I have come up witht he following error messages when clicking on the site

Warning: fopen(/usr/moodle_data/moodle_data_1_8/.htaccess) [function.fopen]: failed to open stream: Permission denied in /usr/moodle/moodle_1_8/lib/setuplib.php on line 127

Warning: mkdir() [function.mkdir]: Permission denied in /usr/moodle/moodle_1_8/lib/setuplib.php on line 138
ERROR: Could not find or create a directory (/usr/moodle_data/moodle_data_1_8/temp)

ERROR: Could not find or create a directory (/usr/moodle_data/moodle_data_1_8/cache)

ERROR: Could not find or create a directory (/usr/moodle_data/moodle_data_1_8/sessions

I have tried the solutions in the moodle docs but nothing seems to have worked.

Can any body help
Average of ratings: -
In reply to Sarah Quantick

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

Could you please post the contents of your config.php file (EDIT: with the password left out of course)? Also, what user is the owner of your Moodle data folder, and what permissions did you give it (i.e. with the chown and chmod commands as shown in http://docs.moodle.org/en/Installing_Moodle#Creating_the_data_directory_.28moodledata.29)?

EDIT: And btw, could you specify just which solutions in the moodle docs you tried?

RLE

In reply to Richard Enison

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Sarah Quantick -
RLE

Thanks for your help in advance.

Attached is my moodle config.php

Apache is the owner of my moodle data I have used the following Chown commands

Chown -R nobody:nobody /usr/moodle_data
Chown -R apache:apache /usr/moodle_data
Chmod 707 -R/usr/moodle_data

I have followed all the instructions in the web server settings

I didn't quite understand the check PHP settings but pasted these at the end of my httpd.config file
In reply to Sarah Quantick

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

Thx for your response. There are a couple of things I find just a little odd surprise about the commands you listed:

  1. The first command makes nobody the owner of your moodledata folder hierarchy; the second changes it to apache, making the first command irrelevant and unnecessary. This should not be a problem, though, provided apache is running as the user named apache.
  2. The third command uses the mode 707, which is unusual. It grants all permissions to the owner (apache), none to the group, and all to everyone else. Hopefully this would not hurt, but I'm not sure whether that 0 in the middle is the cause of your problem. You might change it to 777 or 770. The latter is preferable because it denies access to amateur hackers (professional hackers have ways of getting around permission settings, but they probably wouldn't bother trying to hack into a Moodle site!).
  3. I'm not surprised that the web server settings solutions didn't help. I don't believe your problem is a web server settings problem but a file/folder permissions problem. That's why I would like you to change the 707 in the chmod command.
  4. Pasting the php settings to the end of your httpd.conf file wouldn't do any good, because those settings belong in the php.ini file. Anyway, I don't believe they relate to your problem.
  5. You can check the permissions of your moodledata folder with this command:  ls -l /usr/moodle_data/moodle_data_1_8
    The beginning of the line of output should tell you the permissions, after the "d", which means directory. It also should give you the names of the owner and group. You can post it if you have a problem interpreting it.

RLE

In reply to Richard Enison

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Sarah Quantick -
Thanks

Chmod 777 didn't work but 770 did something

I now get a different error which if you go to www.nt4l.dyndns.org/moodle you get

Forbidden

You don't have permission to access /moodle on this server.


Apache/2.2.4 (Fedora) Server at nt4l.dyndns.org Port 80



In reply to Sarah Quantick

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

That's interesting. The 0 in the 770 means that users outside the group of the owner of the file or folder having mode 770 get no access to it. Since apache is being denied access, this suggests to me that apache is not running as the user named apache. Maybe you had it right in the first place; maybe the user name for apache is nobody.

Btw, I just noticed that the installation docs page suggests using 707 on hosting systems, to deny access to the group but granting access to others, which is what I said it meant. I don't know why that would be good to do, but it now appears that, if you are using a web host, you should go back to using 707. blush

It still looks like we need to make sure we have the right user name for apache. It couldn't hurt to try nobody; if that doesn't work, try running the command

ls -l /usr/moodle/moodle_1_8

and see what owner is listed. Since this is the folder (along with its sub-folders) where your Moodle php files are, I would expect it to be owned by the apache user. But I could be mistaken.

EDIT: I just saw the Fedora Core test page at http://nt4l.dyndns.org/. It lists /var/www/html as the folder where the document files for that website are. So it might also be of interest to see what owner is listed by the command

ls -l /var/www/html

RLE

In reply to Richard Enison

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

I just checked the Apache manual. If you look in httpd.conf for a User directive, it will tell you what user Apache runs as, provided it is launched by the user root. If it is launched by another user, it runs as that user.

RLE

In reply to Richard Enison

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Sarah Quantick -
RLE

I am now back to the original error

I checked the HTTPd.config
User apache
Group apache

When I checked ls -l /usr/moodle it was nobody so I have changed it to apache

I have tried different combinations on permissions without success.

I have attached a copy of what I have been doing for you to look at

Thanks

Sarah


In reply to Sarah Quantick

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

Very interesting. I could go on and on about what I found fascinating in your attached file, but that would be a waste of time. The important thing is, the last chmod commands you ran gave all permissions to everybody (777) for the Moodle document folders as well as the data folders, and all the files in them. So it seems it is not a file permission problem after all.

While I didn't think it logical that a webserver setting would cause this problem, since Moodle data is supposed to be web inaccessible anyway, I have run out of things to look at. Since Moodle runs as apache, maybe something in the apache configuration file is preventing it from having full access to the data folders.

So could you attach httpd.conf to your next post?

RLE

In reply to Richard Enison

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Sarah Quantick -
RLE

Please find attached my HTTPD config file.

Also if a solution cannot be found I could just start a fresh install of everything even back to installing fedora as I currently have nothing else set up on the webserver although as I am sure you would understand I would prefer not to do this but hey ho if needs must

Sarah
In reply to Sarah Quantick

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

I have carefully read your httpd.conf file and looked up in the Apache on-line manual every directive. I finally found what I was looking for at the end of the file. Here is what I would suggest doing (I'm grasping at straws here):

  1. Make a backup copy of httpd.conf in case this doesn't work or makes things worse.
  2. The last line of the file is an alias directive. It tells Apache where to find the Moodle php files. It is therefore very important and should be left in the file.
  3. Just before that line is a block of lines that looks like this:

<Directory "/usr/moodle_data/moodle_data_1_8">
DirectoryIndex index.php index.html index.htm
AcceptPathInfo on
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

I don't know where that block came from but I suspect it might be the cause of the problem. Logically, it would seem to be harmless but I don't know what else could be the villain here. Try deleting that block (those eight lines only). Then restart Apache and try again. mixed

RLE

In reply to Richard Enison

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Sarah Quantick -
The lines came from the moodle installation documents for red hat and fedora. I have removed them but still no joy
In reply to Sarah Quantick

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

I am surprised the installation documents you found told you to put a directory block in the Apache configuration file for the Moodle data folder like the one for the Moodle documents folder. You can't be talking about the document at moodle.org, because the one I looked at (http://docs.moodle.org/en/RedHat_Linux_installation#Setup_Apache) doesn't say that; you must have looked at a different installation document. The reason I am surprised is that that block tells Apache to give web access to the Moodle data folder, of which moodle.org specifically says just the opposite, i.e., to deny web access to that folder, for security reasons. However, that is a separate issue. I was hoping that removing that block would solve your problem also, because nothing else we have tried has worked, and it is very disappointing that it didn't. But it is a good thing to keep that block out of httpd.conf for security reasons.

So based on your posts, the Moodle data folder (and all sub-folders) is owned by apache, the user Apache runs as, and all permissions have been granted for those folders, so that's not the reason permission is being denied. As far as I can tell, there is now nothing in httpd.conf that would cause Apache to deny Moodle permission to write to those folders, either. I have run out of ideas as to what could cause this permission denial to happen. All I can think to do is to debug. This would involve going into php.ini and turning on all error reporting and then looking at the log(s). I don't know for a fact that this will give us more info on why permission is being denied, but I don't know what else to try.

So if you are ready and willing, here is what to look for in php.ini (after making a backup copy!):

  1. Look for a line that begins "error_reporting" that doesn't have a semicolon in front of it. Change it to read "error_reporting = E_ALL". If there isn't any, look for a line that says that with a semicolon in front of it, and remove the semicolon. If there isn't any, type it in where the error-reporting examples are.
  2. Similarly to #1, make sure the line that begins "log_errors" without a semicolon in front of it says "log_errors = On".
  3. Again, similarly to the first two, make sure there is a line beginning "error_log" without a semicolon in front; it should say something like "error_log = moodlelog". This one is a little tricky, because the moodlelog file needs to be in a folder we can write to. Since our problem is being denied permission to write to the moodledata folder in the first place, we need to find a place we can write to. I would suggest using the Moodle web document folder, which in your case is /usr/moodle/moodle_1_8. So the full line would be "error_log = /usr/moodle/moodle_1_8/moodlelog".
  4. Restart Apache and try the installation again. Then look at moodlelog (and the Apache log) and see if there is anything there we don't already know! The error messages should also appear in your browser.

If this is too complicated, you can attach your php.ini file to your next post and I'll make the changes. A simpler procedure, which will cause the error messages to appear in your browser, is to make the Moodle source code change suggested in http://moodle.org/mod/forum/discuss.php?d=71081#p318466.

If that doesn't help, there are more debugging options to try!

RLE

In reply to Sarah Quantick

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

Okay. Since I posted my last response to your last post, I did get some ideas as to possible causes:

firewalls, anti-virus and other such security software.

Which brings us to the point where it becomes necessary to ask: do you personally own the server? Does your employer own it? Or are you using a web host?

In the first case, you might ask the company that sold it what security software they installed on it. In the second, presumably your employer has an IT department or help desk you could ask. In the third, you should certainly be able to ask tech support at the web host. If you don't get a satisfactory response, you can always switch hosts! smile

RLE

In reply to Sarah Quantick

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Brad Hong -
Hi Sarah,

I got exactly the same problem as yours.

After a long time searing for the solutions. Finally it is works for me now.

Solution: turn off the SELINUX setting at: /etc/selinux/config
SELINUX=disabled
Reboot computer than everything works for me.

You can even turn on the selinux setting after the moodle works. strange.

Good luck
Brad
In reply to Brad Hong

Re: Error Warning: fopen htaccess) [function.fopen]: failed to open stream: Permission denied

by Richard Enison -

SQ,

That proves my point. SELINUX = Security-Enhanced Linux. As I said, over a month ago, security software.

RLE