Setting permissions in Fedora Apache/PHP - php

I am building a Fedora server (on VirtualBox right now). It is running Fedora 15.
I want my PHP script to be able to edit the contents of a file in the same folder it is in.
The PHP script and the file are in /home/user/public_html/
But, when I call "file_put_contents("./theFile.txt")" I get an error saying that it cannot open the stream, permission denied.
So, I have:
- Made the file permissions 0777.
- Made the folder permissions 0777.
- Added the "apache" user to the group "wheel".
- Changed the user folder permissions to 0771.
- Changed the owner of the public_html folder and the text file to "apache:apache".
I am at my wits end and I have idea what to do next. Suggestions?

SELinux is preventing you from writing out the file. See the httpd_selinux(8) man page for ways to work with/around it.

Related

Unable to upload files to Drupal 7.5

I have a Drupal 7.53 installed on CentOS6.8. After a year or so of working, I suddenly cannot upload files. So when creating a new node with no file upload, everything works fine. When I add a file, it fails, either showing "The request was not completed. The server met an unexpected condition." 500 error, or a Javascript Alert box with the same info.
The tmp folder has permissions 777, and the sites/default/files folder has permissions of 775.
Any ideas what went wrong??
-- UPDATE --
It may also be useful to know that the system is running under CPanel. So httpd runs as user "nobody".
Thanks!
First , check your files configuration in D7 admin .
Next , check if folder sites/default/files have recursively rights 777 and apache (or nginx) user has owner (something like www-data)
Finally, check your access logs if something wrong can be logged and run update.php to get some else information

php writes files that I can't access - windows IIS

I have a php page that writes files onto my local PC, into a specific folder named UploadedImages. This all works fine. The problem is that when I go to look at the file (always an image file -- a .png in this case), and double-click it, windows says I don't have permission to view it. Again, file permissions on the UploadedImages folder is wide open (Everyone -> Read/Write), and my login account has Full Control, and my login account is the Owner of the folder.
If I right-click the file and go into permissions, it shows that I have no permissions on the file. I can go in and grant myself ownership and permissions, then view it -- but it makes no sense that I have to do this every time.
How can I permanently solve this so that every file my php script writes into that folder I have automatic/full access to it?
I am running Windows 10, IIS 10.0 and PHP 5.6.11. It appears that IUSR account is getting the permissions, but why would I (the ADMIN on the folder) have all my rights revoked just because php writes a file there? Thank you.
One of solutions is try to run web server under certain user (not admin) to which you have full access rights.
Second possible solution: maybe your virtual host config contains directive which force server to work under admin or user to which you dont have access - try to change it.
#SweatCoder: You said:
Again, file permissions on the UploadedImages folder is wide open (Everyone -> Read/Write), and my login account has Full Control, and my login account is the Owner of the folder.
[...]
If I right-click the file and go into permissions, it shows that I have no permissions on the file. I can go in and grant myself ownership and permissions, then view it
This is what's called "inheritance". You need to set inheritance on the folder, so permissions on files are inherited from the parent directory.
//edit: see the icacls help information in cmd.exe:
icacls /?

Permission with Apache on CENTOS

I installed LAMP in my CENTOS and it all looks fine. In my www/html/ folder I placed my script and they all work fine, they can write/read everything. However everytime I create a folder and I put files inside it they cannot write, for example, if I use file_put_contents with PHP it does not work due the permission denied error.
Everytime it happens I need to chmod 777 to that folder and all the files inside. It's a great time loss.
Is there someway I configure the CENTOS so everytime I create a folder or upload a file it automatically will have read/write permission?
If you want new created folder/file to automatically have 777 permission, you must set umask to 000.
Ref: Setting the umask of the Apache user

Linux file uploads, fwrites, does not work

I have installed fedora15 on my system, installed apache and php5.3 and mysql. I have not changed any default setting in any configuration files
Created one ftpuser and uploaded files to Documentroot which is '/var/www/html/' and when I run php files all the files runs successfully.
But when it comes to file-uploads, fopen, fwrite, imagemagick convert etc all the programs which involve creation of files programatically does not work. I have given 777 permissions to the folder where I run the php scripts but still it gives me the access denied error.
Below is a sample code which creates permission denied error.
$handle = fopen("test.txt","w+");
if(!$handle)die("Could not open file for writing");
fwrite($handle,"Testing Uploads Successfull.");
fclose($handle);
The above file is located in '/var/www/html/test/' directory of my newly installed fedora15 system.
Though if I run this file as a root user using php command line it executes correctly creating a new file and the text inside it. If I run the same file in command line with another user it produces permission denied error, though the directory has got 777 permission over it.
Please any one help me with this wierd behaiour,
Thanks in advance.
SELinux is preventing the web server from creating and writing to files. See the httpd_selinux(8) man page for more details.

PHP and Permissions

I recently moved my website to a new host and now am experiencing some broken code..
I have an uploading script that is now returning this:
move_uploaded_file() failed to open
stream: Permission denied in *..
I've set the upload directory to 777 which worked fine, but my script is needed to have top level permissions..
(As the script itself sets permission to directories, does lots of copying etc)
Is there a way in apache I can set the PHP script to the owner of all the folders on my server?
Thanks
Also
When looking in phpInfo()
Under
apache2handler
User/Group nobody(99)/99
Is this related?
I wouldn't go that route, just give it permissions to the defined upload_tmp_dir, or define upload_tmp_dir to be a directory you have access to. If it is that directory you have problems with. If the target is the problem, and you've 777'ed it, something fishy is going on.
Do you have ssh access to your new host? The reason I ask is that it's probably not best to use the username/group as nobody, as most other services would use this too. I would change it to something like apache
You can then update httpd.conf, adding in these two lines (reloading the config after):
User apache
Group apache
Then, run chown apache:apache -R dir_name to make apache own it.
well,
When you are trying to set the permission like "0777", you must be running on same authority.
What I mean is.
For example, your script tells to change a folder/file permission to 0777, but the folder or file already has a permission and that is '0755' so you are not authorised to make that change. as the user have only 5 authority.
Either, you need to login to FTP and change the folder permission to 0777 and then you have full control over it or you have to stick with using 0755 or similar.

Categories