How do we know that a directory is apache writable?
Apache, is a program running in the background. Apache is originally started by user root
(also called root-process
). This root-process
launches several child processes which handle the client requests. For security reasons, the child processes are not run by user root
but as a user with minimal privileges. Usually this user is named apache
or www-data
.
To find out what user this is for apache v1:
ps -ef | grep httpd | grep -v grep
or for apache v2:
ps -ef | grep apache | grep -v grep
Result for apache 2 will be something like this:
root 5001 1 0 07:21 ? 00:00:00 /usr/sbin/apache2 -k start www-data 5021 5001 0 07:21 ? 00:00:00 /usr/sbin/apache2 -k start www-data 5022 5001 0 07:21 ? 00:00:00 /usr/sbin/apache2 -k start www-data 5023 5001 0 07:21 ? 00:00:00 /usr/sbin/apache2 -k start
In this case the user/group is www-data
So, in order to make a directory writable by the webserver we have to set the directory’s owner or group to Apache’s owner or group and enable the write permission for it. Usually, we set the directory to belong to the Apache group (apache
or `www-data or whatever user is used to launch the child processes) and enable the write permission for the group.
chgrp www-data /path/to/mydir
chmod g+w /path/to/mydir
(www-data
is the name you found with the ps
command above).
Regarding:
2) I've also been told to make the app/runtime directory web-writable. Is this the same as apache writable ?
Yes, this is a directory you need to set writable to the group Apache expects. Probably this will be somewhere in /var/www/
or it is set as a virtual host in /etc/apache2/sites-enabled/
and/or /etc/apache2/sites-available
Related videos on Youtube
MEM
Updated on September 18, 2022Comments
-
MEM over 1 year
I've been told that I should create a images folder and an assets folder, and that I needed to make sure that: "they are apache writable". I've also been told to make the app/runtime directory web-writable. Is this the same as apache writable? If so:
How can I do that at once, or know that ?
Doing a
ls -l
I'm getting something like:drwxr-xr-x 13 user user 4096 2011-08-26 10:23 app drwxr-xr-x 4 user user 4096 2011-08-26 10:23 runtime drwxr-xr-x 2 user user 4096 2011-08-26 11:11 images drwxr-xr-x 2 user user 4096 2011-08-26 11:12 assets
-
MEM over 12 yearsThanks a lot. Is there a way to create the directory with mkdir and at the same time, give those permissions ?
-
MEM over 12 yearsIs it true that we can also do: chmod -R o+w /or/path/here ? (the -R being option obviously). ?
-
Rinzwind over 12 yearsYes 1 method would be:
mkdir dirname && chgrp www-data dirname
-
Rinzwind over 12 years@MEM yes.
R
will do all dirs from where you issue the command. There are a lot of ways to do this ;) -
MEM over 12 yearsThanks a lot. Really. Glad to know a little bit more. :)
-
enzotib over 12 years
ps -ef | grep [a]pache
is a common idiom to avoid the spuriousgrep
line in the output.