简体   繁体   中英

changing documentroot for apache on windows isn't working

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?

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>

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 ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM