using virtualhost return to root folder

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

using virtualhost return to root folder

Postby alain.roger » 02. October 2019 14:31

Hi,

i use XAMPP 7.2.4 and i have virtualhost.
by default typing a localhost should redirect to localhost/dashboard according to your app and if we click on Application link we go to apps.

Till i did not set virtualhost, basically on my local machine, everything was ok. Since i set up my virtualhost, all request are redirected to virtualhost and therefore generate an error:
Access forbidden!
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.

if you want to access to virtualhost, you can type the virtualhost name (in my case: test.com.local) and you are correctly redirected to directory stored in /var/www/test.com.local
so where is my mistake when i want to access to localhost/dashboard and it does not work ?

here is my vhost.conf file extract:
Code: Select all
<VirtualHost test.com.local:80>
    DocumentRoot "/var/www/test.com.local"
    ServerName www.test.com.local
    ServerAlias test.com.local
   <Directory "/var/www/test.com.local">
      Options Indexes FollowSymLinks Includes ExecCGI
           AllowOverride None
           Require all granted
   </Directory>
    ErrorLog "logs/test.com.local.com-error_log"
    CustomLog "logs/test.com.local.com-access_log" common
</VirtualHost>
What does not kill you, makes you stronger

RogTek, Web agency: htttp://www.rogtek.com
facebook: http://www.facebook.com/rogtek
User avatar
alain.roger
 
Posts: 20
Joined: 03. February 2012 22:14
XAMPP version: 7.4.10
Operating System: Kubuntu 20.04

Re: using virtualhost return to root folder

Postby Altrea » 02. October 2019 18:44

Hi,

Two things:

First: If you switch to virtual hosts it will override some of the default configurations of your Apache.
SO, at this point localhost is no longer the servername for your Apache.
You need to specify all domainnames you want to serve by your Apache, localhost is one of them too.

Second: Never never ever place your virtual host servername inside the opening <virtualhost> Definition. It is recommend to use the wildcard asteriks * following by a colon : and the port, so in most cases <VirtualHost *:80>

Additional Tipps:
- The DocumentRoot folders need to have proper rights for the Apache user
- The very first VirtualHost in your configuration will be the default virtual host for non matching requests too, so it is most recommend to set a debug virtualhost as default one to see quickly if your desired virtual host matches or not.
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: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: using virtualhost return to root folder

Postby Nobbie » 02. October 2019 19:32

alain.roger wrote:so where is my mistake when i want to access to localhost/dashboard and it does not work ?


You have no VirtualHost for localhost and that is your mistake. You can have NO VirtualHosts and thats Ok. BUT: if you have any VirtualHost, ALL(!!!) of your Hosts MUST BE VIRTUALHOSTS. The external configurations and declaration for "localhost" are OBSOLETE and IGNORED, if you have ANY VirtualHost.

Create a VirtualHost for localhost and you are done. DO NOT user domain names in the <VirtualHost ...> Declaration, only use them in the ServerName declaration.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: using virtualhost return to root folder

Postby alain.roger » 03. October 2019 13:26

that's a very interesting point that all must be virtualhost if i have at least 1 virtualhost. I didn't notice it. so thanks a lot.

However, if i set a virtualhost for localhost as bellow:
Code: Select all
<VirtualHost *:80>
    DocumentRoot "/opt/lampp/htdocs/test1.dev"
    ServerName test1.dev
    ServerAlias www.test1.dev
   <Directory "/opt/lampp/htdocs/test1.dev">
      Options Indexes FollowSymLinks Includes ExecCGI
           AllowOverride None
           Require all granted
   </Directory>
    ErrorLog "logs/test1.dev-error_log"
    CustomLog "logs/test1.dev-access_log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/opt/lampp/htdocs"
    ServerName localhost
    ServerAlias 127.0.0.1
   <Directory "/opt/lampp/htdocs">
      Options Indexes FollowSymLinks Includes ExecCGI
           AllowOverride None
           Require all granted
   </Directory>
    ErrorLog "logs/localhost-error_log"
    CustomLog "logs/localhost-access_log" common
</VirtualHost>


i always go to XAMPP dashboard even if i typed: http://test1.dev in my browser.

I rn apachectl -S and there is only 1 (by default) virtualhost as you can see below:
Code: Select all
VirtualHost configuration:
ServerRoot: "/opt/lampp"
Main DocumentRoot: "/opt/lampp/htdocs"
Main ErrorLog: "/opt/lampp/logs/error_log"
Mutex default: dir="/opt/lampp/logs/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ldap-cache: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/opt/lampp/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: MODPERL2
User: name="daemon" id=1
Group: name="daemon" id=1


So there is still an issue and i do not figure out what it is.
What does not kill you, makes you stronger

RogTek, Web agency: htttp://www.rogtek.com
facebook: http://www.facebook.com/rogtek
User avatar
alain.roger
 
Posts: 20
Joined: 03. February 2012 22:14
XAMPP version: 7.4.10
Operating System: Kubuntu 20.04

Re: using virtualhost return to root folder

Postby Nobbie » 03. October 2019 15:26

I cannot see any VirtualHost in your log. Probably your vhost.conf (which i dont know, xampp used to configure virtualhost in httpd-vhosts.conf) is not evaluated. Run /opt/lampp/bin/httpd -S for the analysis of VirtualHosts. You have to uncomment the include to httpd-vhosts.conf in httpd.conf to activate VirtualHosts.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: using virtualhost return to root folder

Postby alain.roger » 04. October 2019 08:58

Ok, i solved it.

In fact i add somewhere a # that generated issue. I removed it and everything is ok now.
basically i realized the "apachectl -S" or "httpd -S" give the same output. Both commands are in /opt/lampp/bin directory.
What does not kill you, makes you stronger

RogTek, Web agency: htttp://www.rogtek.com
facebook: http://www.facebook.com/rogtek
User avatar
alain.roger
 
Posts: 20
Joined: 03. February 2012 22:14
XAMPP version: 7.4.10
Operating System: Kubuntu 20.04


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 66 guests