I am setting up a new CentOS 6.6 machine running PHP 5.5 and migrating our site to the server but am getting the error in my httpd error log:
PHP Warning: fopen(/ssd-media/www/app/storage/logs/laravel.log): failed to open stream: Permission denied in /ssd-media/www/index.php on line
I have already checked and the httpd process is being run as the user/group "apache" and have done the chmod -R 775 storage and verified that the file has the right user / group configured and permissions and then ran the following code:
<?php
$myfile = fopen("/ssd-media/www/app/storage/logs/laravel.log", "w") or die("Unable to open file!");
$txt = "test\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
I have moved the DocumentRoot to /ssd-media/www which is not where CentOS is installed, it is an SSD RAID that is only for the apache / mysql files. Other than that it is a fairly simple configuration for which I followed this guide:
https://webtatic.com/packages/php55/
What other reasons would I get a permissions denied on that file? I tried 777 permissions as well to no avail.
Related
I have a debian 9 running apache2 with php7.
I have an ubuntu which has a shared folder (samba).
I have used fstab on debian 9 to attack the shared folder.
I can create folder with php and create file, but I cant write into the file?! What can be the problem?
$myfile = fopen("./mntdp/dp_handler/newfile2.txt", "w") or die("<br>Unable to open file!");
$txt = "Mickey Mouse\n";
fwrite($myfile, $txt);
$txt = "Minnie Mouse\n";
fwrite($myfile, $txt);
fclose($myfile);
Warning: fopen(./mntdp/dp_handler/newfile2.txt): failed to open stream: Permission denied in /var/www/html/dir.php on line 10
So the newfile2.txt is created on the ubuntu share, but I cant write in it?! Why?
I used chmod -R 777 on dp_handler the owner is the user what I use in the fstab, so the admwz user is the owner and the group is root.
I have tried so many stuff can somebody help?!
I am attempting to create a cronjob under the user apache, but I get permission denied errors for files that are accessed by the program. The specific file that my php script cannot access is /var/www/html/amazon/amazon_data.txt. Here is me checking the permissions, and testing to see if I can write to the file:
bash-3.2$ whoami
apache
bash-3.2$ ls -l /var/www/html/amazon/amazon_data.txt
-rwxrwxr-- 1 apache apache 1082 Apr 3 15:43 /var/www/html/amazon/amazon_data.txt
bash-3.2$ vi /var/www/html/amazon/amazon_data.txt
Now I try to run a script that tries to access the file I get this warning:
bash-3.2$ /usr/bin/php /var/www/html/amazon/amazon_inventory_sync.php
PHP Warning: Module 'json' already loaded in Unknown on line 0
PHP Warning: fopen(amazon_data.txt): failed to open stream: Permission denied in /var/www/html/amazon/amazon_inventory_sync.php on line 26
Warning: fopen(amazon_data.txt): failed to open stream: Permission denied in /var/www/html/amazon/amazon_inventory_sync.php on line 26
Unable to open amazon_data.txt!bash-3.2$
Why can I access and edit the file with the user just fine, but not in the php script when executing it via command line? There is no issue when I run the script from a browser.
Edit: I can run it fine under the user soh, who is in the group apache. apache is also in the group apache.
The issue was due to the file being requested not being a literal location. This is the code which did not work:
$filename = "amazon_data.txt";
$file = fopen($filename, "a+") or die("Unable to open $filename!\n");
This may work fine when the script is run remotely via HTTP, but it may cause issues when running cron jobs or execution in the terminal. Changing the $filename to be the full location fixed this issue.
$filename = dirname(__FILE__)."/"."amazon_data.txt";
$file = fopen($filename, "a+") or die("Unable to open $filename!\n");
Why does this happen? I am guessing instead of the php file's folder being used, it was using a directory which the apache user did not have access to, such as the current working directory that the command in terminal was being executed from.
I'm running XAMPP 1.8.2 with the default PHP 5.4.19 on OS X 10.8.5.
My PHP application is supposed to have read/write access to a certain local directory, but it's not working. For testing, I distilled it down to a very simple script:
<?php
$file = "/Volumes/RAID/AT_RISK/copra/uploadedfiles/file.txt";
$current = "hello world\n";
file_put_contents($file, $current);
?>
Warning: file_put_contents(/Volumes/RAID/AT_RISK/copra/uploadedfiles/file.txt): failed to open stream: Permission denied in /Applications/XAMPP-1.8.2/xamppfiles/htdocs/filetest.php on line 4
I've tried this command, but it doesn't help.
sudo chmod -R 777 /Volumes/RAID/AT_RISK/copra/
Here you can see the permissions for yourself:
$ pwd
/Volumes/RAID/AT_RISK/copra/uploadedfiles
$ ls -l
total 32
-rwxrwxrwx 1 elliott staff 7 Oct 12 22:31 file.txt
Silly me. Although the folder had correct permissions, the volume itself (/Volumes/RAID) was 700. Problem solved.
I'm trying to upload files using my Ubuntu Virtual Server.
The PHP function moving the uploaded files returns the following error:
"Warning: move_uploaded_file(files/Site Logo.png): failed to open stream: Permission denied in /var/www/test.php on line 5 Warning: move_uploaded_file(): Unable to move '/tmp/phpZB7Mxi' to 'files/Site Logo.png' in /var/www/test.php on line 5"
The directory has permissions 0777 which I set through the SSH and it still doesn't upload. PHP.ini is configured to upload ON and stuff but no luck. I'd guess its permissions problems but I have set it to pretty much RWX for every user?
My code originally was too complex for a video system so I tried a basic code like below:
$file = $_FILES['video']['name'];
echo $file;
move_uploaded_file($_FILES['video']['tmp_name'],"files/".$file);
echo "Done";
This wouldn't work either. So I am guessing it's how the server is configured?
I was getting the same problem, it was permission problem. Just
sudo chmod 777 /var/www/work_pathname/the_upload_pathname/*
A few things to check:
You did check the permissions on files/ using ls -l?
Did you run
chmod 777 /var/www without the -R flag?
Still sounds like a permissions error, something small you might have missed...
I'm trying to create a file in a directory outside the document root of the web server. The folder has permissions 777 but php says Permission Denied:
Warning: fopen(/home/site2/public_html/images/x.jpg) [function.fopen]: failed to open stream: Permission denied in /home/site1/public_html/test_sites.php on line 2
Permission problem
<?php
$f = fopen('/home/site2/public_html/images/x.jpg', 'wb');
if(!$f) die("Permission problem");
fclose($f);
echo "OK";
?>
The 777 permissions is half the battle. You will also need to change the group to be www-data (if on debian) using the:
chgrp g+w www-data /home/growtent/public_html/images
That "should" work, depending on what system you are running and given that my memory is correct.
It sounds like safe mode is on and doc_root has been set. You'll need to set doc_root to empty or turn off safe mode.