Spencer Cooley Spencer Cooley - 10 months ago 70
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

to come from
directory instead of


I ended up figuring it out. Some suggested I change the
file, but I ended up finding a file in
and changed the root directory from
and that worked.

Answer Source

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.).