Write to ./etc/

I am trying to use a php script to write to a file in the ./etc/test/ directory, and though that file was 777 permissions i get

 Permission denied in **/var/www/html/config/index.php** on line **18**
can't open file

when i try to open with fopen and “w” as a paramater. with fopen and “r” it reads the content fine.