Skip to content
Advertisement

PHP: “failed to open stream: Permission denied”

I am getting some interesting results on my server when i try to access any Directory or File via some Function.I have set all my file & directory permissions to 777 and have changed the content owner to Apache but i still get error messages.Code:
move_uploaded_file($_FILES['file']['tmp_name'], '/var/www/html/fileContent_Site/userData/'.$_SESSION['username'].DIRECTORY_SEPARATOR.$_FILES['file']['name']);
Or file_put_contents('userData/userData.txt', $result,FILE_APPEND); mkdir("userData/".$register['username']);

For ‘move_uploaded_file()’ i get:

move_uploaded_file(/var/www/php/Site/userData/radi/110729.png):failed to open stream: Permission denied in /var/www/php/Site/upload.php

move_uploaded_file(): Unable to move ‘/tmp/phpUFvMcn’ to ‘/var/www/php/Site/userData/radi/110729.png’ in /var/www/php/Site/upload.php

And for ‘file_put_content()’ and ‘mkdir()’

file_put_contents(userData/userData.txt): failed to open stream: Permission denied in /var/www/php/Site/register.php

mkdir(): Permission denied in /var/www/php/Site/register.php

Advertisement

Answer

Open http.conf (in /opt/lampp/etc/httpd.conf) file.

Edit this part:

<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User hostname
Group hostname
</IfModule>

See, if that works.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement