Spencer Cooley Spencer Cooley - 1 month ago 7
Linux Question

How do I change the root directory of an apache server?

Does anyone know how to change the document root of the Apache server? I basically want

localhost
to come from
/users/spencer/projects
directory instead of
/var/www
.

Edit



I ended up figuring it out. Some suggested I change the
httpd.conf
file, but I ended up finding a file in
/etc/apache2/sites-available/default
and changed the root directory from
/var/www
to
/home/myusername/projects_folder
and that worked.

RDL RDL
Answer

You need to change the DocumentRoot setting in your httpd.conf file. Chances are it will be under something like /etc/apache2/conf/httpd.conf

Use your favourite editor (I recommend Vim) and look for the DocumentRoot and change it to /users/spencer/projects. Also look a little further down for a setting that looks like this:

<Directory "/var/www">

You will also want to change what is in the quotes to your new directory. This gives Apache access to read from that directory when a user makes a request that call on it.

Now restart your apache service (httpd -k restart) and you should be good to go.

Edit: Apache2 site config files are now typically kept in /etc/apache2/sites-available/ (Debian, Ubuntu, etc.).