PHP Warning: mkdir(): Permission denied in Seperate filesystem - php

This may or may not be a duplicate question, partly because the destination folder it's trying to write to, is on a Windows filesystem. I have a script which has a mkdir php function in it, which is trying to create a folder and a file to a mounted windows file system.
Permission on the file
-rwxrwxrwx. 1 apache apache 24850 Jan 6 11:31 fns.php
Permission on the folder is
drwxr-xr-x. 8 a-linux-user root 0 Dec 29 15:55 ACT!
I have the file system mounted on
/media/shared
I'm getting a mkdir(): Permission denied error. I was wondering where I should start debugging the issue.
My httpd.conf file has this permission:
User apache
Group apache
the line or the fstab is
//domain.com/shared /media/shared cifs uid=a-linux-user,credentials=/home/some-dir/.creds,domain=GRM,comment=systemd.au‌​tomount 0 0

Edit your apache -> conf -> httpd.conf file & change User and Group from daemon to your machine owner name. (in your case: a-linux-user) See if that works.

Related

Permission denied with user ubuntu but not with user www-data on .csv file

I'm seeing weird Ubuntu permission issues only on a single .csv file when trying to access with php. The file is list.csv, owned by ubuntu:www-data, and ubuntu user is part of www-data group. The rest of the site works fine, no permission issues, but I see the following error when trying to load this file with php:
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileObject::__construct(xxx/list.csv): failed to open stream: Permission denied'
If i do chown www-data:www-data list.csv, i can load with php. Why is this file not being loaded by php if owned by ubuntu, even if ubuntu is part of www-data group?
Additionally, I can open this file as ubuntu user (vi list.csv) read and write.
Edit: Permissions on the file are: -rwxr-xr-x 1 ubuntu www-data
Edit again: Changed permissions to 0644 -rw-r--r-- 1 ubuntu www-data no luck
Edit some more: File lives in a directory that has x permission:
drwxr-xr-x 3 ubuntu www-data 4096 Jul 28 23:09 content/
Not sure it has anything to do with execute permissions as I can change owner to www-data:www-data and the file gets loaded. It would seem its something to do with user ubuntu owning the file and not www-data
Edit: Its this line of code that errors out, trying to load .csv file into php SplFileObject:
SplFileObject::__construct("xxx/content/list.csv");
I can see in the OP that the only difference between the owner and group is write permission (you have tried xr and r with the group). So, I suspect your PHP is trying to open the file in write mode.
To confirm this try:
$myCSV = new SplFileInfo('YOUR CSV');
$myCSV->isReadable(); // should be true
$myCSV->isWritable(); //expecting this to be false
Edit: If that's whats going with your program you can open the file just in read mode using: $myCSV->openFile('r')
Your server might have the PHP open_basedir parameter set which would prevent access to any files outside of this directory.
To verify this have a look into your relevant php.ini file (for example /etc/php5/apache2/php.ini) and check if the open_basedir line is set.

PHP glob/scandir and Linux softlinks/permissions

I'm trying to write a simple online music player to improve my programming.
I have a server running CentOS 6.5, with an external hard disk containing all my files. I mounted my storage partition to /mnt/storage and my music is in /mnt/storage/cascornelissen/Muziek, which has the following permissions:
drwxrwxr-x 19 cascornelissen ftpusers 4096 Nov 4 14:43 Muziek
Then I have a simple httpd webserver, hosting the project in /var/www/html/melodi, which constains a softlink to the Muziek directory mentioned earlier:
lrwxrwxrwx 1 root ftpusers 34 Jan 26 22:31 music -> /mnt/storage/cascornelissen/Muziek
I want to use PHP's glob to list all the files but that returned an empty array. So I tried scandir("music") but it returns the following error:
Warning: scandir(music): failed to open dir: Permission denied in /var/www/html/melodi/index.php on line 42
Any ideas on how to fix this permissions issue?
Try this:
chmod ugo+x /mnt /mnt/storage /mnt/storage/cascornelissen
Probably some part of your path will not allow entry for your Apache user. Allowing entry to a directory means adding x or execute permissions to the directory.
Explanation
# create path a/b
mkdir -p a/b
ls a/b # this works
# now remove all permissions for a
chmod 000 a
ls a/b # ls: cannot access a/b: Permission denied
# but why, we should still have permission for b??
# Now, lets add x permission for a:
chmod ugo+x a
ls a/b # works again
ls a # ls: cannot open directory a: Permission denied
# So, we cannot list contents of a, but we can
# access a/b *through* a
So, execute permission or x for a directory means we can access the path below it, even if we cannot read the contents of the directory itself. In your case, Apache needs permission to "walk through" /mnt/storage/cascornelissen even though it will not read any files until it reaches Muziek.

PHP5 apache not working from another directory

I'm kinda novice on setting up a PHP environment (Apache), but nothing to do about it.
I have a VPS, which has Ubuntu 12.04 LTS.
My issue is that I receive following error:
[Wed Nov 13 16:43:31 2013] [error] [client 127.0.0.1] PHP Fatal error:
Unknown: Failed opening required '/root/blog/index.php'
(include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0
index.php contains following code:
<?php
print phpinfo();
?>
It is WORKING IF it is located under "/var/www/" directory.
But I wanted to change the location of the script to "/root/blog".
I have re-configured the "000-default" configuration file under "sites-enabled" folder in apache2 folder. So it shouldn't be a problem.
I've tried assigning different permissions (chmod 777) to "/root/blog" folder (both: recursively and traditionally), but no avail.
I've checked the user and user group for the "/var/www" folder and files, and they are:
root/root - root user and root group. So, that should not be an issue.
What should I do about it ?
Can someone help me ?
P.S AFAIK, apache version: 2.2, PHP: 5.3.10 (installed today, using apt-get install php5 apache2)
I imagine the problem comes from the Apache user not having permission to read/execute files under the /root directory, since after all, that's the root user's home directory.
I really recommend you don't serve your website from /root but if you really want to try executing this command:
chown -R nobody /root/blog
(I'm assuming nobody is your Apache's user)
Out of curiosity, why run the website from /root? /var/www is the standard location for website files and if it works when the files are under this directory why not stick to it?

Unable to save a file due to file permissions

I'm trying to upload and save an image file. This has worked fine in the past, but is now returning an error.
Warning: move_uploaded_file(//home/bitnami/htdocs/lookgram/photos/1/22.jpeg): failed to open stream: Permission denied in /opt/bitnami/apache2/htdocs/lookgram/build/classes/Photo.php on line 138
Warning: move_uploaded_file(): Unable to move '/tmp/phpAyWyw4' to '//home/bitnami/htdocs/lookgram/photos/1/22.jpeg' in /opt/bitnami/apache2/htdocs/lookgram/build/classes/Photo.php on line 138
This looks like a file permssion error, so here is the permissions on the folder:
drwxrwxr-x 6 bitnami bitnami 4096 Mar 15 01:02 photos
Any ideas?
This is because photos/1/ is only writable by root user. For upload to work we need to make the owner of that folder same as httpd process owner OR make them globally writable (bad practice).
Check apache process owner: $ps aux | grep httpd. The first column will be the owner typically it will be nobody
Change the owner of photos/1/ to be become nobody or whatever the owner you found in step 1.
$sudo chown nobody /home/bitnami/htdocs/lookgram/photos/1/
Chmod photo/1/ now to be writable by the owner, if needed [Seems you already have this in place].
$ sudo chmod -R 0755 /home/bitnami/htdocs/lookgram/photos/1/
For more details why this behavior happen, check the manual http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir , note that it also talking about open_basedir directive.

How to access a file from URL using Curl

-rw-r--r-- 1 root root 514 Jan 15 04:03 curl.php
-rw-r----- 1 root root 1344 Feb 5 02:09 dbm-config.ini
-rw-r--r-- 1 root root 5149 Feb 5 02:19 mysql-connectivity-status.php
Here, Am accessing the file "mysql-connectivity-status.php" from url like http://<ip>/html/DB-Monitoring/mysql-connectivity-status.php.
In mysql-connectivity-status.php I have called the file dbm-config.ini. While am accessing via URL am getting the following Warning.
Warning: parse_ini_file(/var/www/html/DB-Monitoring/dbm-config.ini): failed to open stream: Permission denied in /var/www/html/DB-Monitoring/mysql-connectivity-status.php on line 113
So, I don't want to change the permission for the dbm-config.ini But how to I access the file using URL?
-rw-r----- 1 root root 1344 Feb 5 02:09 dbm-config.ini
The file can be read from and written to, by the user root rw- and read from by the members of the group root r--
If you access the php file using curl, this is executed most likely with your webservers user and group which is not root:root
That's why php can't read the ini file.
I recommend to move the file out of your document root so it can't be accessed directly from the web, then change the owner to your webserver user and group
determine the username php is executed with
ps aux | grep "httpd" # apache environment
ps aux | grep "php" # php fastcgi environment
chown user:group dbm-config.ini
The problem is that your webserver cannot access that file. If you cannot fix that you cannot access it remotely through that webserver. :)
Wild guess, since I don't know what you're using:
chown root:apache dbm-config.ini
chmod g+r dbm-config.ini
might help. That will set the owning group of the file to apache and give the group read access. IF your webserver is apache and that is the correct group that it is using this might help.

Categories