Permission denied with nginx and php - php

I have create under my nginx webdir a ln -s (symbolic link) to a directory in my homedir
I now try to read it from a PHP script but get:
Warning: opendir(/usr/local/n/test): failed to open dir: Permission denied in /usr/local/n
I have set no open base dir in php.ini
directory and files are having a group in which the web user is part of
both nginx and php fpm run under that same user
How can I fix this?

The only solution to this was to copy the files. I wasn't able to get nginx to read symbolically linked files.
I've seen recommendations that the files under the main 'public' or 'html' directory can be followed, but this was not the case for me.

I remember there is option in php or nginx(apache) to allow symbolic link, you need to check that.
you could search google : nginx and php using symbolic link
I couldn't remember that option exactly.

Related

The stream or file "D:\Inetpub.....\storage\logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied on Windows

I have a website made with Laravel, I need to upload it to windows server (Plesk Cpanel) i have set the database and everything is good, but when trying to open the website it shows me :
The stream or file "D:\Inetpub.....\storage\logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
no solution found for windows any help, please?
You must change permissions for this file, or for all "storage" dir.
I found this in Google for Plesk - Link for Plesk and for Cpanel - Lunk for CPanel.
You must set 777 or read, write, execute permissions for all groups.
Or read here what permissions you need.
Good luck!
sudo chmod 777 path/to/project/storage/logs/laravel.log

Why does switching to secure folder (httpsdocs) break the PHP file upload function

Server version: Apache/2.4.34 (Unix)
NOTE: This is not a Plesk or control panel questions. This is a custom PHP application hosted on a Rackspace dedicated server with no control panel.
I'm trying to utilize an existing SSL certificate for several sub-directories of a domain, but the architecture for the domain separates out two directories for non-secure/secure:
httpdocs
httpsdocs
I copied everything from httpdocs to httpsdocs and also forced traffic to https using .htaccess. Everything worked great until I tried the PHP file upload functionality.
Here's the bit of code that is failing from the secure side:
$path = "uploaded_files/".$row_query[0].'/'.$file_name;
copy($temp_file, $path);
In doing some debugging, I found that the temp file gets created:
/tmp/phpanKT4N
but the error I see in the logs is:
copy(uploaded_files/New Sub Folder/30052_testing.txt): failed to open stream: Permission denied in /var/www/vhosts/.com/httpsdocs/demo/resource/add_resource.php on line 108
I tried changing copy() to move_uploaded_file() but here's the error for that:
PHP Warning: move_uploaded_file(uploaded_files/test/30054_testing.txt): failed to open stream: No such file or directory in /var/www/vhosts/<thedomain>.com/httpsdocs/demo/resource/add_resource.php on line 111
PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpOC9YEF' to 'uploaded_files/test/30054_testing.txt' in /var/www/vhosts/<thedomain>.com/httpsdocs/demo/resource/add_resource.php on line 111
I searched stack and saw that ownership must match, but the permissions appear to be the same for httpdocs and httpsdocs.
The /tmp folder is owned by root:root and like I said this works perfectly from the non-secure folder. The non-secure and secure upload folders are identical:
httpdocs:
drwxrwxr-x+ 8 theuser apache 4096 Sep 22 2015 uploaded_files
httpsdocs:
drwxrwxr-x+ 8 theuser apache 4096 Sep 22 2015 uploaded_files
Is this a configuration, permissions issue, or what?
Figured this out... Ran the following:
First find apache's user:
egrep -i '^user|^group' /etc/httpd/conf/httpd.conf
Result:
User apache
Group apache
Then ran this and it solved all the PHP file upload issues in httpsdocs:
chown -R apache:apache /var/www/vhosts/<thedomain>.com/httpsdocs/
chmod -R g+rw /var/www/vhosts/<thedomain>.com/httpsdocs/

PHP rename() permission denied via Apache (SELinux related)

I have a simple script that outputs Permission denied warning in the browser:
rename('/opt/web/test.tmp', '/opt/web/test.tmp1')
Script path is /opt/web/test_rename.php
/opt/, /opt/web/ and /opt/web/test_rename.php are 777 and have apache owner / group.
httpd process owner is apache
test.tmp is 777 and have apache owner as well
It works fine with cli.
What else could I do to make it work via apache?
The problem was with SELinux. It can block php rename function.
I've found the answer here: http://forums.fedoraforum.org/archive/index.php/t-111081.html
On the Fedora Core 3 Linux distribution, you may get a "failed to open stream: Permission denied in ..." message. In fact changing the permission of the directory will not work (even if you set to 0777).
It is because of the new SELinux kernel that allow apache user to write only in /tmp dir (I think). In order to solve the problem you must to disable the SELinux (at least for apache service) to allow the server to write in other directories. To do that, run the system-config-securitylevel app and disable the SE to apache service. Reboot your system and continue your work.

Permission denied in Apache instead of 777

I am having a hard time deploying a PHP website built using Grav on CentOS.
Whenever I try to open the website I get 500 Server Error. The logs say:
Uncaught exception 'RuntimeException' with message 'Creating directory '/var/www/html/glug_site/cache//compiled/files' failed on error mkdir(): Permission denied' in /var/www/html/glug_site/vendor/rockettheme/toolbox/File/src/File.php:420\nStack trace:\...
I followed the guide mentioned here but it didn't helped.
Then, I did chmod 777 -R glug_nith/ but still it doesn't work. I even logged into apache user using sudo -u apache bash to see if I am able to create folders and files inside myapp and I was successful. I tried deleting the .htaccess file to see if that would help but it didn't.
I cannot understand instead of having all the permission why its showing permission denied. Also I couldn't find any thing that might be blocking the permission. Please help.
try uncommenting the 12th line in ur .htaccess file
Modify this
# RewriteBase /
to
RewriteBase /

session_start() returns "No such file or directory" directly after creating the session file

I'm trying to set the session.save_path on my IIS/PHP via fastcgi server. So I created a new folder called tmp in my php folder, gave IUSR and IIS_IUSRS full permissions to this folder, and set my session.save_path variable in php.ini to "\tmp".
Upon loading my webpage I get the error:
Warning: session_start(): open(tmp\sess_gp13t5fg969iddfq1lrt3e88o1, O_RDWR) failed: No such file or directory (2)
The weird thing is I know it can see the folder because I look in my newly created tmp folder and it actually created the sess_gp13t5fg969iddfq1lrt3e88o1 file right before throwing the error telling me it doesn't exist. So how can it create the file and then not see it? What could I be doing wrong?
Update: If I set session.save_path with an absolute path, it works. When I give it a relative path of just "\tmp" it no longer works. Every example I see uses a relative path for the save_path and I personally need to use a relative path. Why would a relative path cause this issue and how do I fix it?
I found the answer you seek:
Relative Paths in PHP
include($_SERVER["DOCUMENT_ROOT"] . "/relative path here");
Under linux the PrivateTmp config of systemd may be the problem.
The solution would be to copy the corresponding systemd unit file to /etc/systemd and remove there the privatetmp config.
In my case:
cp /usr/lib/systemd/system/httpd.service /etc/systemd/system
systemctl daemon-reload
systemctl restart httpd.service
Change in /etc/systemd/httpd.service then
PrivateTmp=true
to
PrivateTmp=false

Categories