I have this PHP code:
<?php $myfile = fopen("testfile.txt", "w") ?>
And the following permissions in my
drwxrwxrwx. 3 root root 4096 Nov 20 08:51 . drwxr-xr-x. 3 root root 17 Nov 18 23:48 .. -rwxrwxrwx. 1 root root 537 Sep 16 14:56 50x.html -rwxrwxrwx. 1 root root 1171 Nov 20 03:50 make.php
But when I run the above PHP code which is in the
make.php it doesn’t create the
What is wrong here? I also tried changing the user to
nginx with the
chown command but it doesn’t work.
Hahah! First of all .. I love your username, "ctrlz".
Regarding your issue and SELinux:
The web is scattered with posts of people recommending to disabling SELinux. It is definitely the simplest "solution", but it is not ideal in a production environment as it leaves your server more vulnerable.
I don't know what Linux distribution you are using (and I'm not sure how much, if at all, SELinux varies between the others), but CentOS provides a SELinux Guide.
SELinux "contexts" are shown in the format
user:role:type:range. By default, SELinux ships in the
targeted mode, which limits access to resources by the
You can append the
-Z flag to commands such as
netstat, and more to view SELinux contexts on different resources.
To view the SELinux contexts of your web folder, run:
ls -lZ /usr/share/nginx/html
To view the context of your
nginx process, run:
ps -auxZ | grep -i nginx
There are also SELinux "booleans" that can be enabled / disabled for common use cases. To view a list of booleans related to a web server (
nginx in this case), run:
getsebool -a | grep -i httpd
To update a boolean value, you can set it using the
setsebool command. Example:
setsebool httpd_read_user_content 1
A few other helpful commands:
That's about where I am at with my SELinux know-how at the moment. I know this is an old post, but I hope this will help others.
Answered by Logan on January 5, 2022
Ok so basically I had to change to this:
/etc/selinux/config file. More info here: How to Disable SELinux.
I don't know if this is the best solution.
Answered by ctrlz on January 5, 2022
2 Asked on February 20, 2021 by v15
2 Asked on February 20, 2021 by uba
2 Asked on February 20, 2021
0 Asked on February 20, 2021 by leakingamps
7 Asked on February 20, 2021 by sander
0 Asked on February 19, 2021 by steve-newcomb
6 Asked on February 19, 2021 by xtrader
1 Asked on February 19, 2021 by max-gawason
0 Asked on February 19, 2021 by vishvesh
0 Asked on February 18, 2021 by user3728501
0 Asked on February 18, 2021 by drakinite
1 Asked on February 18, 2021
1 Asked on February 18, 2021 by rakslice
1 Asked on February 18, 2021 by tigers
2 Asked on February 18, 2021
3 Asked on February 18, 2021 by cb1066
Get help from others!