Forum Moderators: coopster

Message Too Old, No Replies

PHP under Apache rights

strange problem (for me)

         

drdewm

8:48 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



I have an Apache server running on a Linux OS and when I try to mkdir() using PHP to my /var/www/html/example/files directory I get the following error message :
[client 172.16.0.234] PHP Warning: mkdir(/var/www/html/example/files/159): Permission denied in /var/www/html/example/modules/files/files.class.php on line 63

I can use the same module to mkdir in the /tmp directory without a problem and I can PHP command line mkdirs and file creation all day but not when I call the PHP script through a browser. Through a browser I get permission denied every time.

the file system permissions for /var/www/html/example/files are as follows (for testing I know this is bad):
drwxrwxrwx 40 apache apache 4096 Feb 1 15:06 files

the user/group portion of my HTTPD.conf are as follows:
User apache
Group apache

output from check.php is as follows:
examplesite System Checks
MySQL Available OK
MySQL Server Version
MySQL Database Connection Connected OK
MySQL Database Select Selected OK
Operating System Linux trippliteis2 2.6.9-1.667smp #1 SMP Tue Nov 2 14:59:52 EST 2004 i686
PHP Version 4.3.10 OK
Server API apache2handler
Web Server Apache/2.0.52 (Fedora)
User Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0
default locale C
session.auto_start 0 OK
session.save_handler files
session.save_path /var/lib/php/session OK
session.serialize_handler php
session.use_cookies 1 OK
session.use_trans_sid 0 OK
file_uploads 1 OK
/locales/en directory writable Warning: you will not be able to save translation files. Check the directory permissions.
/files directory writable Warning: you will not be able to upload files. Check the directory permissions.
/files/temp directory writable Warning: you will not be able to make PDF's. Check the directory permissions.
root_dir /var/www/html/example OK

All other aspects of the Apache/PHP server with the MySQL backend are functional from browsing to database entries. The only issue I have is with using the PHP under Apache to do the mkdir() and file functions. I can log into the Apache account and issue mkdir directives wihtout a problem it's only when the calls are made through Apache/PHP.

the PHP code is as follows:
<?php
mkdir("/tmp/testernew1", 0777); <==== works fine
?>
<?php
mkdir("/var/www/html/example/files/testernew1", 0777); <===== fails
?>

Any help would be appreciated.

[edited by: jatar_k at 8:51 pm (utc) on Feb. 10, 2005]
[edit reason] removed url [/edit]

BjarneDM

8:33 am on Feb 11, 2005 (gmt 0)

10+ Year Member



You've just got permission problems.

Apache is running as a special user.
Normally, Apache and PHP is running under this.
But when you are using PHP from the commandline, yuo are executing the script as yourself - not as Apache. And then of course everything then just works. The reason it works with /tmp is that /tmp has setting that allows everybody to write to that folder

So, to fix this, you'll have to give Apache write access to the part of the server you want to modify with your PHP script. And you'll usually need to be root (or sudo) to be able to do this.

There are two ways to accomplish this:
1) assign the group to Apache and chmod g+w
2) make Apache part of the group and chmod g+w

drdewm

6:28 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



I must be missing something. I started the apache httpd with user:apache and group:apache. I have a user account named apache with high enough access to write just about anywhere on the disk. The owner and user of the root and every sub directory is apache:apache. I even went crazy and chmod -r 777 the whole directory. I still get permission denied when trying through a browser to mkdir() or copy files.
Right now I changed my code to write the files to the /tmp directory and I have a 1 minute cron job to move them to their correct place. This works but is nutty.
Thanks for any help. I appreciate it. This is aging me.

BjarneDM

7:22 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



When apache starts, the first instance is running under the root account and is only used for controlling the other instances. The other instances is then the ones doing the actual processing and serving of webpages.

Try a

ps -auxww ¦ grep httpd
and see what the 'worker' httpd's are running as.

I've enabled webdav on my machines for some directories, and that involves a lot of thinking about the permissions for files and directories in order for the users not to be able to destroy important parts of the server. And for me that's working perfectly.

I'ld still say that you are having permission problems. It's probably something completely simple and obvious - at least in hindsigt.

drdewm

12:27 am on Feb 14, 2005 (gmt 0)

10+ Year Member



I have gone through the details so many times that at this point I'm a bit frustrated. I agree it does seem like a permissions issue but I just can't seem to get it. I'm starting to wonder if it's a bogus message due to failure for other than permissions.

[root@theplace ~]# ps -auxww ¦ grep httpd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
root 5581 0.0 0.5 27240 13376? Ss Feb10 0:02 /usr/sbin/httpd
apache 5387 0.0 0.5 27240 13428? S 04:02 0:00 /usr/sbin/httpd
apache 5388 0.0 0.5 27240 13428? S 04:02 0:00 /usr/sbin/httpd
apache 5389 0.0 0.5 27240 13428? S 04:02 0:00 /usr/sbin/httpd
apache 5390 0.0 0.5 27240 13396? S 04:02 0:00 /usr/sbin/httpd
apache 5391 0.0 0.5 27240 13396? S 04:02 0:00 /usr/sbin/httpd
apache 5392 0.0 0.5 27240 13396? S 04:02 0:00 /usr/sbin/httpd
apache 5393 0.0 0.5 27240 13396? S 04:02 0:00 /usr/sbin/httpd
apache 5394 0.0 0.5 27240 13396? S 04:02 0:00 /usr/sbin/httpd
root 16556 0.0 0.0 5412 660 pts/1 S+ 18:15 0:00 grep httpd

The directory permissions:
[root@theplace html]# ls -l
total 104
drwxrwxrwx 14 apache apache 4096 Jul 21 2004 1.0.2
drwxrwxrwx 17 apache apache 4096 Jul 26 2004 beta
drwxrwxrwx 7 apache apache 4096 Jan 20 16:59 dba
drwxrwxrwx 2 apache apache 4096 Aug 3 2004 dev
drwxrwxrwx 15 apache apache 4096 Feb 3 11:50 dotproject
-rwxrwxrwx 1 apache apache 48 Jul 22 2004 index.php
drwxrwxrwx 8 apache apache 4096 Jul 28 2004 ipw
-rwxrwxrwx 1 apache apache 52 Jul 19 2004 phpinfo.php
drwxrwxrwx 7 apache apache 4096 Oct 21 15:10 phpldapadmin-0.9.4b
drwxrwxrwx 3 apache apache 4096 Jul 22 2004 phpmaker
drwxrwxrwx 4 apache apache 4096 Jul 26 2004 repgen
-rwxrwxrwx 1 apache apache 563 Feb 8 14:29 setperms.sh
drwxrwxrwx 5 apache apache 4096 Jul 26 2004 ta
[root@theplace html]#

dbryant

8:01 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



Did you ever find a solution? I am experiencing the same problem with TWiki. I am running Fedora Core 3 and Apache 2.0.52. I have even created a directory in / with mod=777.

drdewm

9:59 pm on Mar 26, 2005 (gmt 0)

10+ Year Member



I added the user that spawned HTTPD daemon into the /etc/sudoers.conf

dbryant

12:58 am on Mar 28, 2005 (gmt 0)

10+ Year Member



That won't fix the problem on my system as it is started by root in init.