PHP permission denied for managing files - php

I have the following test page
mkdir('test');
$f = fopen('test.txt', 'w+');
fwrite($f, 'gibberish');
fclose($f);
unlink('test2.txt');
Nothing of that happens and I get the following error messages on erro.log
PHP Warning: mkdir(): Permission denied in /var/www/html/test.php on line 5
PHP Warning: fopen(test.txt): failed to open stream: Permission denied in /var/www/html/test.php on line 7
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/test.php on line 8
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/test.php on line 9
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/html/test.php on line 10
PHP Warning: unlink(teste2.txt): Permission denied in /var/www/html/test.php on line 12
I can clearly see that I'm having permission issues, but I have no ideia what sort of permission it is and how do I even set that kind of permission.
Using git or terminal I can create/delete/chmod all files and directories without a problem. It's just PHP that can't.

ssh using your terminal and, first, change the files owner to apache group
chown -R www-data:www-data /var/www/html/
Next allow all members of this group to read and write files
chmod -R g+rw /var/www/html/
This should fix your issue. I strongly suggest you read more about permissions in ubuntu though

Related

require_once: failed to open stream: Permission denied(lampp)

I need help solving , what says to be a permission error in the htdocs folder, because i needed to alter them to even add folders in the first place.
This is my init.php file:
<?php
//Start Session
session_start();
//Include Configuration
require_once('config/config.php');
//Helper Function Files
require_once('helpers/system_helper.php');
require_once('helpers/format_helper.php');
require_once('helpers/db_helper.php');
//Autoload Classes
function __autoload($class_name){
require_once('libraries/'.$class_name . '.php');
}
?>
I try to include it via `
When i run my index.php file i get this error:
Warning: require_once(../../htdocs/PHP-Wizard/helpers/system_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9
Fatal error: require_once(): Failed opening required '../../htdocs/PHP-Wizard/helpers/system_helper.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9
I tried going one folder up with ../ , but it doesn't work.
I looked around for a similar error to mine, but no luck. They all say No such file or directory in (path).
Could it be that it is the same error, or do i really need to change my permissions, if so, how can i do that?
Edit: When i use include_once('helpers/system_helper.php'); i get this error:
Warning: include_once(helpers/system_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9
Warning: include_once(): Failed opening 'helpers/system_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 9
Warning: include_once(helpers/format_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 10
Warning: include_once(): Failed opening 'helpers/format_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 10
Warning: include_once(helpers/db_helper.php): failed to open stream: Permission denied in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 11
Warning: include_once(): Failed opening 'helpers/db_helper.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/PHP-Wizard/core/init.php on line 11
The problem was indeed the permissions, i'm guessing because i copied the folder.
I fixed it by chmod 777 on all the files in that folder, and now it works fine.
Thank you for your time attempting to help me.
I tested using relative paths and it works fine.
<?php
require_once '../test.php';
echo ' you';
Where test.php just contains echo "hello"; resulted in the expected "hello you".
I would guess your problem is with file permissions. Can you check what permissions are on your system_helper.php? It should be at least executable by the user php is running as (usually www-data). I could reproduce your error message by doing a chown root test.php and chmod 600 test.php so I would guess something like
chown www-data: system_helper.php
or
chmod g+rwx system_helper.php
should give you permission to run the script.

PHP Codeigniter error failed to open stream: Permission denied

I have been working on a project that uses codeigninter. I worked on it in Windows 7 and it was fine but after I moved this project on Ubuntu to work on it there, It gives me this error in every page/controller/method that I try to access:
Warning: require_once(/opt/lampp/htdocs/TS_Project/system/core/CodeIgniter.php): failed to open stream: Permission denied in /opt/lampp/htdocs/TS_Project/index.php on line 202
Fatal error: require_once(): Failed opening required '/opt/lampp/htdocs/TS_Project/system/core/CodeIgniter.php' (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/TS_Project/index.php on line 202
The CodeIgniter.php file does exist, the path to it is correct and I am able to read and write in it ( I can open it in a text editor and modify it freely). I tried changing the file permission to it using the chmod command but nothing happens. Why is permission denied to the CodeIgniter.php file?
You need to change the permission of your TS_Project folder to 755.
You can do that by:
sudo chmod -R 755 /opt/lampp/htdocs/TS_Project

pChart - running scripts as www-data doesn't work

So I'm having trouble running PHP scripts for pChart. Running them as the user who created them works fine, but if I sudo to www-data, I get these errors:
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d
/mcrypt.ini on line 1 in Unknown on line 0
PHP Warning: include(/usr/lib/pchart/class/pDraw.class.php): failed to open stream: Permission denied in /usr/share/phpmyadmin/test.php on line 4
PHP Warning: include(): Failed opening '/usr/lib/pchart/class/pDraw.class.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/phpmyadmin/test.php on line 4
PHP Warning: include(/usr/lib/pchart/class/pImage.class.php): failed to open stream: Permission denied in /usr/share/phpmyadmin/test.php on line 5
PHP Warning: include(): Failed opening '/usr/lib/pchart/class/pImage.class.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/phpmyadmin/test.php on line 5
PHP Warning: include(/usr/lib/pchart/class/pData.class.php): failed to open stream: Permission denied in /usr/share/phpmyadmin/test.php on line 6
PHP Warning: include(): Failed opening '/usr/lib/pchart/class/pData.class.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/phpmyadmin/test.php on line 6
PHP Fatal error: Class 'pData' not found in /usr/share/phpmyadmin/test.php on line 10
Does anyone have any idea what permissions or groups I'd need to change to get this working? I've tried changing everything mentioned in the output above to 777 but it's still happening.
Ok, it was permissions, though it's not clear which ones yet. It started working when I changed the pChart2.1.3 folder permissions to 777. Now I can tidy up.

PHP fopen() does not create a file

According to fopen documentation, in some modes it will create the file if it does not exist, but in my situation, I've checked all 'w', 'w+', 'x' and 'x+' modes but it's just throwing warnings at me and it cannot create the file.
It's my code:
$this->handle = fopen($this->log_name, 'w');
and what I get:
Warning: fopen(D:\xampp\htdocs\farid\logs\error.php) [function.fopen]: failed to open stream: No such file or directory in D:\xampp\htdocs\farid\libraries\error\log.php on line 34
Warning: fwrite() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\farid\libraries\error\log.php on line 66
Warning: fclose() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\farid\libraries\error\log.php on line 27
And I'm working in windows environment.
Check if the path to the logfile exists, it creates a file, not a directory.
Also check if the user, which runs xampp, has access to the folder you specified.

I installed phpfreechat 1.3 on my webpage but I got this errors but I dont know what to do

Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/sound.swf) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/smileys/emoticon_surprised.png) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/smileys/emoticon_waii.png) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/smileys/weather_sun.png) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Warning: copy(/home/beradioc/public_html/phpfreechat-1.3/src/../data/public/themes/default/smileys/weather_cloudy.png) [function.copy]: failed to open stream: Permission denied in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 179
Warning: chmod() [function.chmod]: Operation not permitted in /home/beradioc/public_html/phpfreechat-1.3/src/pfctools.php on line 180
Your script does not have permissions.
If you are running on your own server, use chmod. If you're running on shared hosting, try chaning permissions anyway, but it's not granted you'll be successful.
chmod is a command for changing permissions on files and/or directories it would appear that your script does not have sufficient permissions to do so, or to copy files around. I would seriously recommend that you study up on file permission, maybe read the READMe for phpfreechat which will probably tell you what those permissions are and go from there. If you do not have ssh access or direct access to your web server, you will probably need some help from your hosting company after you find out what files ad directories need what permissions.
a quick look at phpfreechat's page states:
Give the web server's write permissions to “phpfreechat-x.x/data/public” and “phpfreechat-x.x/data/private” directories.
If you are using FTP:
CHMOD 777 phpfreechat-x.x/data/private
CHMOD 777 phpfreechat-x.x/data/public
If you are using SSH:
chmod 777 phpfreechat-x.x/data/*

Categories