Document Root for various apps

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Document Root for various apps

Postby misstheresa2009 » 29. August 2020 14:58

Hello Everyone!

I am trying to understand how the Virtualhost system works. I think I have finally figured things out, but I have a question. Creating a virtualhost should be:

Listen 80

# This is the "main" server running on 172.20.30.40
ServerName server.example.com
DocumentRoot "/www/mainserver"

<VirtualHost 172.20.30.50>
DocumentRoot "/www/example1"
ServerName www.example.com

# Other directives here ...
</VirtualHost>

<VirtualHost 172.20.30.50>
DocumentRoot "/www/example2"
ServerName www.example.org

# Other directives here ...
</VirtualHost>

But I want to create virtualhost entries for separate apps such as Wordpress, Joomla, Prestashop, PhpBB and a few others. For the Document root folder I would like to do something like this:

# This is the "main" server running on 172.20.30.40
ServerName server.example.com
DocumentRoot "/www/mainserver"

<VirtualHost 172.20.30.50>
DocumentRoot "/hotdocs/Wordpress"
ServerName wordpress1.localhost

<VirtualHost 172.20.30.50>
DocumentRoot "/hotdocs/Joomla"
ServerName Joomla1.localhost

I realize that I should include the Directory location but I need to know if I'm on the right track. If not, can someone please point me in the right direction? I looked just about everywhere on the internet, but I can't find the answer I am looking for. Before I start creating virtualhost entries I want to make sure that I'm not headed for a virtualhost nightmare. Thanks! :)

Regards,

misstheresa2009
misstheresa2009
 
Posts: 2
Joined: 05. February 2016 11:17
Operating System: Windows 7

Re: Document Root for various apps

Postby Altrea » 29. August 2020 19:38

Hi,

some hints:
  • If you want to use virtualhosts you will need to define them for every host. Some of the "main server" definitions will not take effect any longer when using virtualhosts.
    Instead the very first virtual host defined will act as a default virtual host for any not matching requests, so
  • as very first virtual host define something like a catchall virtualhost which normally should never match
  • The only reason to use an IP address instead of the wildcard Asterisk is if it is important to separate a request by IP. So it is really important for you the domain http://www.example.com will only match for NIC 172.20.30.50?
  • If you use /www/example1 as path for DocumentRoot, it will resolved relatively to the root of the drive Apache is installed on, so if Apache is running from path C:\xampp\apache\bin\ then /htdocs/wordpress will be path C:\htdocs\wordpress\. Is that really what you want? It is highly recommend (at least on windows) to use full absolute paths
  • If using a DocumentRoot outside the default htdocs folder you would need to define access rules for this directory too (for htdocs it is already done in httpd.conf)
  • I would almost always define separate log files for each vhost to make it easier to debug routing problems and for debugging purposes activate the rewrite log too

summerized all of this my recommendation for a virtualhost definition would something like this:
Code: Select all
# localhost vhost (also default vhost)
<VirtualHost *:80>
    Servername localhost
    DocumentRoot "C:/xampp/htdocs"
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    LogLevel notice rewrite:trace5
    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# wordpress1.localhost vhost
<VirtualHost *:80>
    Servername temp1.dev
    DocumentRoot "C:/xampp/vhosts/wordpress1.localhost/htdocs"
    ErrorLog "logs/wordpress1.localhost-error.log"
    CustomLog "logs/wordpress1.localhost-access.log" common
    LogLevel notice rewrite:trace5
    <Directory "C:/xampp/vhosts/wordpress1.localhost/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# joomla1.localhost vhost
<VirtualHost *:80>
    Servername temp1.dev
    DocumentRoot "C:/xampp/vhosts/joomla1.localhost/htdocs"
    ErrorLog "logs/joomla1.localhost-error.log"
    CustomLog "logs/joomla1.localhost-access.log" common
    LogLevel notice rewrite:trace5
    <Directory "C:/xampp/vhosts/joomla1.localhost/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


As you can see i have created a new directory for all vhosts. the reason for that is that it is not recommend to define vhost DocumentRoot folders which are subfolders of another vhost DocumentRoot.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 10342
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Document Root for various apps

Postby misstheresa2009 » 29. August 2020 21:05

Thanks, Altrea! Thanks for taking the time to explain this to me. It is greatly appreciated.

Regards,

misstheresa2009
misstheresa2009
 
Posts: 2
Joined: 05. February 2016 11:17
Operating System: Windows 7

Re: Document Root for various apps

Postby fslharoon » 30. August 2020 01:14

Altrea wrote:Hi,

some hints:
  • If you want to use virtualhosts you will need to define them for every host. Some of the "main server" definitions will not take effect any longer when using virtualhosts.
    Instead the very first virtual host defined will act as a default virtual host for any not matching requests, so
  • as very first virtual host define something like a catchall virtualhost which normally should never match
  • The only reason to use an IP address instead of the wildcard Asterisk is if it is important to separate a request by IP. So it is really important for you the domain http://www.example.com will only match for NIC 172.20.30.50?
  • If you use /www/example1 as path for DocumentRoot, it will resolved relatively to the root of the drive Apache is installed on, so if Apache is running from path C:\xampp\apache\bin\ then /htdocs/wordpress will be path C:\htdocs\wordpress\. Is that really what you want? It is highly recommend (at least on windows) to use full absolute paths
  • If using a DocumentRoot outside the default htdocs folder you would need to define access rules for this directory too (for htdocs it is already done in httpd.conf)
  • I would almost always define separate log files for each vhost to make it easier to debug routing problems and for debugging purposes activate the rewrite log too

summerized all of this my recommendation for a virtualhost definition would something like this:
Code: Select all
# localhost vhost (also default vhost)
<VirtualHost *:80>
    Servername localhost
    DocumentRoot "C:/xampp/htdocs"
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    LogLevel notice rewrite:trace5
    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# wordpress1.localhost vhost
<VirtualHost *:80>
    Servername temp1.dev
    DocumentRoot "C:/xampp/vhosts/wordpress1.localhost/htdocs"
    ErrorLog "logs/wordpress1.localhost-error.log"
    CustomLog "logs/wordpress1.localhost-access.log" common
    LogLevel notice rewrite:trace5
    <Directory "C:/xampp/vhosts/wordpress1.localhost/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# joomla1.localhost vhost
<VirtualHost *:80>
    Servername temp1.dev
    DocumentRoot "C:/xampp/vhosts/joomla1.localhost/htdocs"
    ErrorLog "logs/joomla1.localhost-error.log"
    CustomLog "logs/joomla1.localhost-access.log" common
    LogLevel notice rewrite:trace5
    <Directory "C:/xampp/vhosts/joomla1.localhost/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


As you can see i have created a new directory for all vhosts. the reason for that is that it is not recommend to define vhost DocumentRoot folders which are subfolders of another vhost DocumentRoot.


Thanks man I was also facing same issue thanks for great explainantion.
fslharoon
 
Posts: 1
Joined: 30. August 2020 01:06
XAMPP version: 7.3.14.0
Operating System: windows


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 104 guests