Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 3223  / 2 Years ago, wed, september 7, 2022, 9:25:05

I'm using Ubuntu in my laptop.
Every time I turn it on, and after Ubuntu initializes, it ask me for my admin password, wich I do provide, in order to be able to use it.
I've installed Sublime2, and I'm learning my first steps in PHP/MySQL
I'm using this ubuntu laptop at my programming class.
Today, we needed to do some fopen() tests for the first time.



I created a file and added to it this code:



error_reporting(E_ALL ^ E_NOTICE);
$fp=fopen("prueba.txt",'w');
fwrite($fp, 'Curso de PHP');
fclose($fp);
echo 'Horray';


Now, when I try to run the file (I'm using Xampp as my local apache, and I'm using chrome as my browser), I getthis error (and the file is not created at all):




Warning: fopen(prueba.txt): failed to open stream: Permission denied
in /opt/lampp/htdocs/curso_php1/inicial/ejemplo-archivos.php on line
25



Warning: fwrite() expects parameter 1 to be resource, boolean given in
/opt/lampp/htdocs/curso_php1/inicial/ejemplo-archivos.php on line 26



Warning: fclose() expects parameter 1 to be resource, boolean given in
/opt/lampp/htdocs/curso_php1/inicial/ejemplo-archivos.php on line 27




When at my home, I've tried the code again, in my windows macine, and everything worked as expected, without any errors.



It seems as I don have enough permissions (failed to open stream: Permission denied), why is that?



Why is this happening? What should I do? Thanks!"


More From » permissions

 Answers
0

I've found that when this happens, the commands are these (I'm posting it here just in case anyone else happens to step into the same issue):



sudo chown -R myUserName /opt/lampp
sudo chmod -R 777 /opt/lampp


I know that giving permissions 777 is not safe enough, but as I need this in my localhost, and I'm only using it for my programming classes, I think its ok.



Hope this helps someone, someday.


[#28374] Friday, September 9, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravturtl

Total Points: 335
Total Questions: 132
Total Answers: 110

Location: Tanzania
Member since Wed, Feb 24, 2021
3 Years ago
;