The configuration hierarchy is listed in apache2.conf file 's comment.
# /etc/apache2/
# |-- apache2.conf
# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf-enabled
# | `-- *.conf
# `-- sites-enabled
# `-- *.conf
# * apache2.conf is the main configuration file (this file). It puts the pieces
# together by including all remaining configuration files when starting up the
# web server.
#
# * ports.conf is always included from the main configuration file. It is
# supposed to determine listening ports for incoming connections which can be
# customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
# directories contain particular configuration snippets which manage modules,
# global configuration fragments, or virtual host configurations,
# respectively.
#
# They are activated by symlinking available configuration files from their
# respective *-available/ counterparts. These should be managed by 127.using our
# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
# their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
# the default configuration, apache2 needs to be started/stopped with
# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
# work with the default configuration.
I. How to change DocumentRoot in Apache 2.4
I found that we need 3 steps:1. Add more Directory in /etc/apache2/apache2.conf
<Directory YOUR_FOLDER> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
2. Change default documentRoot in /etc/apache2/sites-available/000-default.conf :
DocumentRoot /var/www
to
DocumentRoot YOUR_FOLDER
3. Restart your Apache server : sudo service apache2 restart or sudo /etc/init.d/apache2 restart
II. How to add virtualhost
We need 3 steps to complete this configure1. In /etc/apache2/sites-available folder create SITENAME.conf file
( SITENAME is your name you want to set)
In SITENAME.conf config your new virtual host
<VirtualHost *:80> DocumentRoot YOUR_NEW_VIRTUAL_HOST_FOLDER ServerName YOUR_VIRTUAL_DOMAIN_NAME ServerAlias YOUR_VIRTUAL_DOMAIN_ALIAS ServerAdmin webmaster@localhost ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combinedme </VirtualHost>
Remember : documentRoot should be configured before ServerName.
2. Run command : sudo a2ensite SITENAME.conf
3. Restart your Apache server : sudo service apache2 restart or sudo /etc/init.d/apache2 restart
※ Notes: Using debug command : bapache2ctl -S to get to know how your server is configured.
※ Notes: Using debug command : bapache2ctl -S to get to know how your server is configured.
You can see more how to config in this link