views:

29

answers:

3

Can i write /etc/apache2/ directory. I want to create a file with php and apache. But i must root. Is there a way to sudoers?

Can do this?

+1  A: 

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.

Galen
A: 

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.

Alex Howansky
A: 

You might be able to manage a way to do this, by changing /etc/apache2's group owner or making your /etc/apache2 world-writable (permission 777), but this is perhaps the worst idea in the history of web-servers. Allowing your process to write files to that directory means that if someone found a way to write files with filenames other than those you specify, they could overwrite your virtualhosts, apace configurations, module configurations... you name it! You'd essentially be opening your webserver to any opportunistic internet thug who can rub two rootkits together and make a spark.

sleepynate
I can wirte with permission 777 but I want to do it safely and when necessary.
feykintosh
Frankly, I don't think you'll find anyone who says that allowing write-access to your apache directory by apache itself is "safe". Please consider moving the location of whatever you need to write to a safer location, and then using another modality (perhaps a `cron` script?) to move it to the appropriate location.
sleepynate
i can write sites-avaiable directory and other software(like webmin/cpanel - webmin with perl) can do this.
feykintosh