# Change documentroot on Apache 2.4 [closed]

I knew how to do it on Apache 2.2, however, how do I change the document root on Apache 2.4? I run Debian 8.20 on a Virtualbox VM as my apache server and Ubuntu 15.04 as my host OS.

I tried to change Document root on /ooo-default.conf to something like: /home/www

I also guess that I have to do chmod –R 755 /home/www. Inside of the directory is However whenever I try to load my VM's IP in Firefox it just 404's.

Here is one run from the Apache error log:

[Wed Oct 28 20:05:38.708080 2015] [mpm_prefork:notice] [pid 5884] AH00163: Apache/2.4.10 (Ubuntu) configured -- resuming normal operations
[Wed Oct 28 20:05:38.708142 2015] [core:notice] [pid 5884] AH00094: Command line: '/usr/sbin/apache2'
[Wed Oct 28 20:05:52.281645 2015] [core:error] [pid 5887] (13)Permission denied: [client 127.0.0.1:46927] AH00035: access to /index.php denied (filesystem path '/home/www/index.php') be\$
[Wed Oct 28 20:06:37.527726 2015] [mpm_prefork:notice] [pid 5884] AH00169: caught SIGTERM, shutting down


Now I am getting timeuts when trying to connect to my VM from my browser.

## closed as unclear what you're asking by roaima, Archemar, chaos, mdpc, dr01Oct 29 '15 at 9:13

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Why don't set the DocumentRoot in /etc/apache2/apache2.conf? It is one and the same for all virtual hosts. If you set it in 000-default.conf I think you will have to set it too in the other /etc/apache2/sites-enabled/ the day you will create them.

To set the correct owner and permissions you have to know which user run the service. Anyway the read permission should be enough I think

The cause could be SElinux,

SELinux is a Mandatory Access Control (MAC) system which is a kernel (LSM) enhancement to confine programs to a limited set of resources.

I guess that one of its security policy avoid that apache2 user to read folders which are not under /var/www/, its not recommended to disable it but it is possible , it depends on how you will use the VM (testing dev prod?).

• I am just using it for practice. Also I don't see document root in my /etc/apache2/apache2.conf – Mario Kamenjak Oct 28 '15 at 22:27
• lets test if the problem is SElinux first, disable it temporarily with echo 0 > /selinux/enforce or setenforce 0 , restart apache2 and test again with browser. Temporarily mean until you restart the VM – lese Oct 28 '15 at 23:05
• Is it safe to turn off SELinux temporarily on my working machine? – Mario Kamenjak Oct 29 '15 at 9:57
• You have to do it on the server (the virtual machine) , not on your local machine. No, as I said it is not recommended. But we are just checking/testing if this is your problem. Disabling it temporarily mean that this config is reset after the machine is reboot. So execute the test suggested in the previous comment. If this solve the problem, you will have to fix SElinux configuration, in order to allow apache2 to read only the folder /home/www and its subfolders – lese Oct 29 '15 at 10:02
• +1 for the SELinux bit. Nothing for setting the Document Root globally. – roaima Oct 29 '15 at 15:06

The clue is here

[Wed Oct 28 20:05:52.281645 2015] [core:error] [pid 5887] (13)Permission denied: [client 127.0.0.1:46927] AH00035: access to /index.php denied (filesystem path '/home/www/index.php')


Apache cannot access or run your index.php. Ensure the permissions on /home and /home/www are sufficient for Apache to access them and that index.php is readable too:

chmod a+rx / /home /home/www
chmod a+r /home/www/index.php


You will also need to review the access rights within the Apache configuration. Look for <Directory> or <Location> directives and ensure they match your new document root. Restart Apache as necessary.

If that doesn't solve the problem try disabling SELinux to test whether that's the issue. If it is, you can find out how to relax its access restrictions for Apache easily enough.

• how exactly should the chmod command look? – Mario Kamenjak Oct 28 '15 at 22:29
• alright chmod's did not work. How do I return them back to normal so I don't have a security hole? – Mario Kamenjak Oct 29 '15 at 13:53
• @Mario why should you have a security hole? – roaima Oct 29 '15 at 15:04
• misconfigured access rights. on my working machine. – Mario Kamenjak Oct 29 '15 at 15:17
• @MarioKamenjak I've not given you any misconfigured access rights. Perhaps someone else has, but I can't see your system so I can't advise on that here. – roaima Oct 29 '15 at 16:36

Here's the steps.

• Change document root in 000-default.conf.
• Restart apache2

Thanks

• I retried that again, now on my Ubuntu local machine, however now I get 403 errors. – Mario Kamenjak Oct 28 '15 at 17:09
• 403 is access denied, You should check the ownership and permission of your project directory – Shabir A. Oct 28 '15 at 17:13
• to what should I set it? – Mario Kamenjak Oct 28 '15 at 17:14
• You should try with 766 – Shabir A. Oct 28 '15 at 17:22
• @Shabir why would permissions of 0766 make an improvement over 0755? – roaima Oct 28 '15 at 18:07