DocumentRoot defines the folder for which the content of your website is located in the server. You can set the value in the main configuration for the default website or in a VirtualHost to set the folder specific to the website or virtual servers that you're hosting.
You can change the DocumentRoot location for your default website in the main configuration file or within the VirtualHost configuration.
$ sudo vi /etc/apache2/sites-enabled/000-default.conf [sudo] password for user:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/user/website ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
$ sudo chown --recursive www-data:www-data /home/user/website/
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/user/website ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /home/user/website/> #Options Indexes FollowSymLinks #AllowOverride None Require all granted </Directory> </VirtualHost>
$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/home/user/website(/.*)?"
This applies to distributions that implements SELinux such as CentOS, RHEL and Fedora Use httpd_sys_content_t instead for readonly access for Apache on the folder.
$ sudo systemctl restart apache2 #Ubuntu, Debian, openSUSE and SLES $ sudo systemctl restart httpd # CentOS and Red Hat
Related: How to manage Apache service
$ curl 127.0.0.1 Hi, I'm located in /home/user/website
Comment anonymously. Login not required.