4

I'm trying to change documentroot on my local windows machine to point at a sub directory below htdocs. I've changed the DocumentRoot location inside httpd.conf along with the Directory location. I've restarted Apache but prinitng out document root with PHP it still points to the default location.

Changes inside httpd.conf:

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/folder_test/website"

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/folder_test/website">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

When I navigate to http://localhost/folder_test/website I see the following from my PHP output:

C:/Program Files/Apache Software Foundation/Apache2.2/htdocs

My PHP code:

<?php 
  //Get the document root 
  $root = getenv("DOCUMENT_ROOT") ; 
  Echo $root; 
?> 

I've restarted Apache...What am I missing?

Paul
  • 11,671
  • 32
  • 91
  • 143

2 Answers2

4

Open the "\conf\extra\httpd-vhosts.conf" file.

Change the

<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs"
#ServerName www.example.com:80
</VirtualHost>

section to reflect the desired directory, in your case:

<VirtualHost _default_:80>
DocumentRoot "${SRVROOT}/htdocs/folder_test/website"
#ServerName www.example.com:80
</VirtualHost>
D_Zab
  • 710
  • 1
  • 5
  • 14
  • 1
    After searching in hundreds topics this finally worked for me! Thank you. – decadenza Apr 13 '15 at 11:10
  • This worked for me. Then I got the message: "Access Forbidden!" message and I had to add the directory element to the vhost conf file as well, you can read more about it here: https://stackoverflow.com/a/23594870/7199922 – tedi Jan 29 '20 at 10:06
0

Hey if this is not answered still: Sometimes when you change document root and other info in httpd.conf it does not reflect that it because the changes you have dont is not saved at all. In notepad++ and diffmerge it does not show that it is not saved on the contrary it shows as saved. Open it in normal notepad and when you try to replace it it says access denied. May be this is because these folder dont have the modification permission for users. Hence for this purpose you need to

  1. Save the changes in a separate file else where with the same name httpd.conf
  2. Rename http.conf inside your apache root document to httpd_backup.conf or just delete it.
  3. now copy the new file you have created i.e. httpd.conf to apache root document.
  4. Go to "Open apache monitor" and restart
  5. clear all cache and cookies in your browser and try again
ebdo
  • 157
  • 3
  • 14