Permissions denied when writing to symlink - php

I have a program that is being hosted on a linux box running Centos 7. The program is accepting form data and saving to a windows file server. the windows file server is mounted on the linux box. i have created a symlink in the directory that the program is in. everytime that i launch the program in the web browser and try and add the data, i receive the following error:
file_put_contents(/W/Shortage/2017/Apr/Shortage04-04-17.csv): failed to open stream: Permission denied in /var/www/html/DriverTest/driverss.php on line 78
In my smb.conf file, i have the property already set to follow symlinks. everyone has rwx rights to the files and the symlinks as well. this is the php code where the error is referring to:
if(!is_dir('/W/Shortage/'.$year. '/' .$month))
{
mkdir('/W/Shortage/'.$year. '/' .$month, 0777, true);
}
file_put_contents('/W/Shortage/'.$year. '/' .$month. '/Shortage'.date('m-d-y').".csv", $result, FILE_APPEND);
when i SSH into the system using a user that i created, i can cd into the directory and do touch test.txt and the file is created. i can also use vi to edit the test.txt file and enter data into it. in the directory, the owner of the files and folders are apache. i am not sure why i do not have any permissions to write to that directory. any suggestions or anyone seeing anything wrong with what i am doing so far?

Related

PHP can't create file, permission denied

I am trying to run some PHP applications on CentOS powered server with apache and MySQL. My apps have to create files on server, but it always says that permission is denied to create a file.
Files are located in /var/www/html. I even tried setting 777 permission to html folder and html/*. I changed apache user and group to myuser, that exists, and restarted apache. I changed the ownership of html folder and all files inside to myuser. I even tried changing document root to /home/myuser/public_html
I tried this code to test write permission. File location is /var/www/html/index.php and /home/myuser/public_html/index.php
$handle = fopen("a.txt", "w");
fwrite($handle, "test");
fclose($handle);
I am just more than amazed by this problem. The same configuration works on my another Ubuntu server.
Some geniuses must be here, help me.
You need to allow you server user to do write operation on your directory, User the below command, If it is a multilevel directory use -R flag.
sudo chown www-data my-dir
Instead of manually giving permission you can try chmod($handle, 0777) within your code.

Ubuntu 16.04 Permission Denied

index.php is located at /var/www/html/
It tries to include autoload.php from /root/vendor
And I'm getting include_once(../../../root/vendor/autoload.php): failed to open stream: Permission denied
Ubuntu 16.04
Enter your terminal and run this command in your terminal.
sudo nautilus
This command will enter you as root into the files application and mostly allow you to do anything to the files that you need to change.
go to the file that you want to change permissions on, mostly visit the folder var, then the folder www, then the folder html.
Once you are here, right click the index.php file and click properties, or permissions.
Change the permissions to read and write or create & delete for all of the options.
I hope I was able to help and much clearer this time, as I have received a downvote for not being clear enough.

Warning: file_put_contents(): failed to open stream: Permission denied

Hi I am new to Mac and web development..
These days I am trying to do a simple web page with a simple form with HTML and Javascript, and the form will be processed by PHP. The PHP will be access txt file, read from and write to this txt file.
The error message comes from this line of code.
file_put_contents("order.txt", $content);
and the error message is
Warning: file_put_contents(order.txt): failed to open stream: Permission denied in /Users/maoyang/Sites/3006/process.php on line 57
all the HTML and PHP codes are in the myname/Sites/3006 folder of my computer. I have done some research and all of them tells me that I need to change some configuration to make the txt file writeable, but really very confused how to do so. Anyone know a good instruction page I could follow(for mac environment).
Thank you very much..
On OSX Apache is run by the _www user. You need to make sure that this user has permissions to write on the file you want to modify. To do so, open a terminal window and type:
sudo chown -R _www:_www /Users/maoyang/Sites/3006
Fill in your Administrator user password when requested. This will change the ownership of the /Users/maoyang/Sites/3006 folder to the _www user (the same one that run Apache) so the webserver will have writing permission on that folder (and all subfolders and files)

How to write a text file

test.php opens test.txt and writes to it. It works fine on one hosting server.
After migrating the code to another host, test.php now can't write out test.txt. The error shows:
Warning: fopen(/home/username/public_html/test.txt)
[function.fopen]: failed to open stream: Permission denied
It will only work when the test.txt file is set to 777. On the original host, test.txt was set to 755.
What am I missing to give permission for test.php to write to the file without 777 on this new host?
Also, file upload PHP scripts aren't working either.
It is not just the permission that is important, but also who owns the files. 755 is enough if the folder/file is owned by the same user that is used for running the web server.
Writing directly to the public_html directory is a huge security risk. I suggest creating a subdirectory (probably best outside the public_html) folder and give it the appropriate permissions / ownership.
It is safer to have the folder owned by the user that runs apache (or whichever web server is being used) - usually something like apache or www-data instead of giving world write permissions.

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.

Categories