fopen() does not work on my apache2 local server on Linux Mint
The filetest.txt is created and I can open it using Sublime and write to it. The directory for this particular project is
/var/www/site02
. When configuring apache2 after installation, I specifically changed the ownership of this specific directory (site02) to be able to read and write files (sudo chown $USER:$USER -R ... you get the idea). In fact, I can indeed read and write with my user account in this directory (I can freely use cli git commands in this directory without "sudo").If I access
index.php
using the code mentioned above, I get the following error:"Warning: fopen(test.txt): Unable to open stream: Permission denied in /var/www/site02/index.php, line 6"
What happened? I've tried googling the problem but got thousands of different reasons, which only confused me more. Is the problem a problem with the apache server? Or do I need to make some configuration changes to PHP?
So, after posting this question, I decided to open /var/www/site02 with a file manager (Thunar) to check the permissions under the graphical interface. Yes, the owner of this directory is me and I can read and write. The group ismyusername, and the permissions are also read and write. But for "others" there is only one permission: read. I changed it to read and write. And test it with some code:
And it worked!