You can change the group of /etc/apache2 to the same group that apache runs as and give the group write permission. This might be safer than trying to su with php and a system call.
Sign up to request clarification or add additional context in comments.
Comments
0
Any directory that you want the Apache process to write to needs to be writable by the user that the Apache daemon runs as. So you either need to make the directory world-writable (ie chmod 777) or owned by the Apache user.
htdocsfolder and put your php file there.