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.
I had to edit
/etc/apache2/sites-available/default
. The lines are the same as mentioned by RDL.In RedHat 7.0:
/etc/httpd/conf/httpd.conf
If you are (like me) finding this post via Google:
I found it at /etc/apache2/sites-available/000-default.conf
If someone has installed
LAMP
in the/opt
folder then the/etc/apache2
is not what you are looking for.Look for
httpd.conf
file in/opt/lampp/etc/httpd.conf
.Change the line in this folder and save it from terminal.
Applies to Ubuntu 14.04 and later releases. Make sure to backup following files before making any changes.
1.Open
/etc/apache2/apache2.conf
and search for<Directory /var/www/>
directive and replace path with/home/<USERNAME>/public_html
. You can use * instead of .2.Open
/etc/apache2/sites-available/000-default.conf
and replaceDocumentRoot
value property from/var/www/html
to/home/<USERNAME>/public_html
. Also<Directory /var/www/html>
to<Directory /home/<USERNAME>/public_html
.3.Open
/etc/mods-available/php7.1.conf
. Find and comment following codeDo not turn ON
php_admin_flag engine OFF
flag as reason is mentioned in comment above Directive code. Also php version can be 5.0, 7.0 or anything which you have installed.Create
public_html
directory inhome/<USERNAME>
.Restart apache service by executing command
sudo service apache2 restart
.Test by running sample script on server.
Incase you are using Ubuntu 16.04. Please update the 000-default.conf in the directory /etc/apache2/sites-available.
here--> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/YourFolder