LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Permission denied even with chmod 777 (https://www.linuxquestions.org/questions/linux-newbie-8/permission-denied-even-with-chmod-777-a-771160/)

Zabrajin 11-24-2009 02:35 AM

Permission denied even with chmod 777
 
Hello everyone,

i've just setup my first Linux server and installed apache + php. I have a simple PHP script which should just create ja directory. But i always get the following error:

PHP Warning: mkdir() [function.mkdir]: Permission denied in /var/www/html/default/test.php on line 3

So as you can see the script is within the folder 'default' which has rights set so 777

Code:

ls -rtl
drwxrwxrwx  2 apache apache 4096 2009-11-23 19:38 default

The php script contains this:
PHP Code:

<?
echo substr(decoctfileperms('.') ), 2);
mkdir("/var/www/html/default/test");
?>

The first line, which echos the current permission shows 777

I've also checked if the httpd process is running with the right user:

Code:

ps aux | grep httpd
root      6765  0.0  0.8 272440  9080 ?        Ss  Nov23  0:08 /usr/sbin/httpd
apache  13158  0.0  0.9 274536  9292 ?        R    02:47  0:00 /usr/sbin/httpd
apache  13213  0.0  0.8 273492  8804 ?        S    02:49  0:00 /usr/sbin/httpd
apache  13228  0.0  0.9 273940  9280 ?        R    02:49  0:00 /usr/sbin/httpd
apache  13238  0.1  0.8 273748  8844 ?        R    02:49  0:00 /usr/sbin/httpd
apache  13246  0.0  0.8 273748  8864 ?        R    02:49  0:00 /usr/sbin/httpd
apache  13250  0.0  0.8 273752  9064 ?        R    02:49  0:00 /usr/sbin/httpd
apache  13256  0.0  0.9 274536  9244 ?        R    02:50  0:00 /usr/sbin/httpd
apache  13260  0.1  0.9 274264  9768 ?        R    02:50  0:00 /usr/sbin/httpd
apache  13268  0.0  0.8 273756  8840 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13272  0.0  0.9 274536  9256 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13273  0.0  0.8 273492  8808 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13275  0.0  0.9 274532  9556 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13281  0.0  0.8 273880  8952 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13284  0.0  0.8 273624  8956 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13291  0.0  0.8 273748  8764 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13301  0.0  0.8 273492  8780 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13304  0.0  0.8 273880  9008 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13310  0.0  0.8 273748  8796 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13311  0.0  0.9 274272  9296 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13312  0.0  0.9 274536  9272 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13314  0.0  0.9 274544  9368 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13318  0.0  0.8 273624  8808 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13321  0.0  0.8 273880  8928 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13323  0.0  0.8 273492  8808 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13325  0.1  0.8 273748  8944 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13327  0.0  0.8 273752  9000 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13340  0.0  0.5 272440  5540 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13345  0.0  0.8 273752  8828 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13346  0.0  0.8 273756  9028 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13347  0.0  0.8 273748  8924 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13350  0.3  0.9 274540  9484 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13352  0.0  0.8 273880  9108 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13359  0.0  0.9 274020  9328 ?        S    02:51  0:00 /usr/sbin/httpd
apache  13361  0.0  0.8 273748  9084 ?        R    02:51  0:00 /usr/sbin/httpd
apache  13362  0.0  0.5 272440  5540 ?        R    02:52  0:00 /usr/sbin/httpd
apache  13363  0.1  0.8 273740  8760 ?        R    02:53  0:00 /usr/sbin/httpd
apache  13364  0.0  0.7 273340  7584 ?        S    02:53  0:00 /usr/sbin/httpd
apache  13366  0.0  0.8 273484  8580 ?        S    02:53  0:00 /usr/sbin/httpd
apache  13367  0.2  0.8 273616  8804 ?        S    02:53  0:00 /usr/sbin/httpd
apache  13368  0.1  0.8 273488  8572 ?        S    02:53  0:00 /usr/sbin/httpd
root    13370  0.0  0.0  85000  820 pts/0    R+  02:53  0:00 grep httpd

(BTW: is it right that there are that many httpd processes? I've another site running on the server)

Thus i should be able to create directories via php or not? Why do i get this error even though the permissions are set to 777?


best regards

Zabrajin

Tinkster 11-24-2009 03:48 AM

Hi, welcome to LQ!

Actually your snippet doesn't do anything for me;
with a <?php it creates the directory just fine.


Cheers,
Tink

Zabrajin 11-24-2009 04:08 AM

Quote:

Originally Posted by Tinkster (Post 3767728)
Hi, welcome to LQ!

Actually your snippet doesn't do anything for me;
with a <?php it creates the directory just fine.


Cheers,
Tink

Hm maybe you've disabled php short tags? I've tried it with <?php ?>, but no difference for me.
Still says permission denied :(

kirukan 11-24-2009 04:19 AM

Quote:

<?
echo substr(decoct( fileperms('.') ), 2);
mkdir("/var/www/html/default/test");
?>
check who is owning this php script? if you want to create directory within /var/ww/html/default then this script should own by apache user.

Zabrajin 11-24-2009 04:30 AM

The permission for the script is as follwing
Quote:

ls -rtl
-rw-r--r-- 1 apache apache 88 2009-11-24 04:25 test.php
Since the webserver is running as the user apache this should be ok i think

kirukan 11-24-2009 04:33 AM

it doesn't have execute permission (use 755 thats enough)

Zabrajin 11-24-2009 04:37 AM

Changed permission to 755 but still the same error...

kirukan 11-24-2009 04:40 AM

is SELinux enabled?

Zabrajin 11-24-2009 04:46 AM

i'm not sure but i don't think so. It's a VPS with a basic fc10 install. Can i check that somehow?

//edit: I've just run the script as root via the local php interpreter and then everything works fine. Anybody has a clue why it fails when i try it within the webserver?

Web31337 11-24-2009 10:52 AM

PHP safe mode is on?
this just looks extremely stupid to me: it must work under even 0700 with user "apache". copy your phpinfo() outputs.
--
upd: try to su to "apache" and cd to that directory then mkdir test there.

Zabrajin 11-24-2009 04:15 PM

Quote:

Originally Posted by Web31337 (Post 3768079)
PHP safe mode is on?
this just looks extremely stupid to me: it must work under even 0700 with user "apache". copy your phpinfo() outputs.
--
upd: try to su to "apache" and cd to that directory then mkdir test there.

i can't su to apache...

Code:

su apache
This account is currently not available.

//edit... removed php info link xD

anomie 11-24-2009 04:21 PM

Quote:

Originally Posted by Zabrajin
i'm not sure but i don't think so. It's a VPS with a basic fc10 install. Can i check that somehow?

Code:

$ /usr/sbin/getenforce

davidstvz 11-24-2009 07:03 PM

Quote:

Originally Posted by Zabrajin (Post 3768405)
i can't su to apache...

Code:

su apache
This account is currently not available.

And you can view the php info page here: http://199.187.126.22/phpinfo.php


If you look at the info in /etc/passwd (if you need to modify don't do it directly, use a program or at least vipw) you will see that the user apache may not have a shell, a home and/or a password which will prevent it from being used as a regular user. You could try to edit in a shell and use the passwd command to give a password and then try what Web suggested (back up your /etc/passwd and /etc/shadow files and restore them after you're done this test).

Smartpatrol 11-24-2009 09:14 PM

...

w3bd3vil 11-24-2009 09:33 PM

You must have enabled SELinux, trying checking that first.

Web31337 11-24-2009 10:15 PM

2 Zabrajin: follow advices about SElinux.

2 davidstvz: there's no need to go such a hard way and add password and shell for users that must never have it so take an unnecessary risk.
running su -s /bin/sh apache will do the trick safely.

kirukan 11-24-2009 11:16 PM

Quote:

And you can view the php info page here: http://199.187.126.22/phpinfo.php
is this your public ip? if yes don't post such real public ip's actually this is for your safety(To prevent the attacks).

Zabrajin 11-25-2009 02:12 AM

Quote:

Originally Posted by anomie (Post 3768421)
Code:

$ /usr/sbin/getenforce

aahhm... what should i do with this line of code? How can ich chek wether SELinux is enabled or not?



Quote:

Originally Posted by Web31337 (Post 3768678)
2 Zabrajin: follow advices about SElinux.

2 davidstvz: there's no need to go such a hard way and add password and shell for users that must never have it so take an unnecessary risk.
running su -s /bin/sh apache will do the trick safely.

I did the su to apache the way you described and i'm able to create the directory

Zabrajin 11-25-2009 03:46 AM

Ok i got it ^^ Setting the httpd_sys_script_rw_t context for the default folder fixed it!
Thanks everyone for the hint with SELinux! I didn't know about that and would have searched for ages :)


best regards

Zabrajin

Bazze 02-06-2011 07:40 AM

I'm having the exact same issue. How did you solve this? I'm running Debian 5.0 on a VPS.

I've done the following:
Quote:

chown -R www-data.www-data documents
chmod -R 777 documents
which gave this:
Quote:

drwxrwxrwx 2 www-data www-data 4096 Feb 5 13:53 documents
I've tripple checked so all my paths is correct in my script, and I've also tripple checked what user PHP is running as. Any ideas?


All times are GMT -5. The time now is 09:08 AM.