Map a domain in htdocs/subfolder

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

Map a domain in htdocs/subfolder

Postby machico91 » 08. October 2020 15:38

Hello everyone, I'm Marco and I'm new in this forum.

I write this post because I have been running tests for weeks, but I can not do anything.

My system is Ubuntu 18.04.5 and the version of XAMPP is 7.4.4-1, I installed XAMPP by downloading the .run from the official site (so the installation is in the "opt" folder), I have a domain that I manage via cloudflare and use only https connection.

For the topic I will use for example mydomain.com
What I'm trying to do is make "https://test.mydomain.com" go directly to the "htdocs/test" subfolder, and "https://test2.mydomain.com" directly to "htdocs/test2".
Port configurations are ok (https://mydomain.com/test works).

I have tried to follow multiple guides on the internet, consulted the official documentation, and read many other previous posts in this forum, but have not found a solution (that works for me).

From what I understand, the comment # "Include etc/extra/httpd-vhosts.conf" line in the "lampp/etc/httpd.conf" folder must be removed, the "httpd-vhosts.conf" file in the "lampp/etc/extra" folder must be modified, and finally add "127.0.0.1 test.mydomain.com" in the "hosts" file in the "etc" folder in the Ubuntu root.

Well, nothing works, test.mydomain.com always points to the "htdocs" folder, then to the XAMPP dashboard.
To be sure, I also tried to do tests locally without using domains and going out on the internet, not even here I was successful.
I've edited the above mentioned files hundreds of times, nothing changes.
In desperation, I tried using .htaccess, the "redirect" works, but I get a 403 error for lack of privileges, or lack of DocumentRoot.

Can you explain to me how to perform the procedure correctly?
I kindly ask you to be specific in the steps to be done, and in the syntax to be written, because as I said, the other posts in the forum, or the guides on the internet, which I have followed to the letter, have not worked.

Thanks in advance and have a nice day everyone
machico91
 
Posts: 6
Joined: 08. October 2020 13:14
XAMPP version: 7.4.4-1
Operating System: Ubuntu 18.04.5

Re: Map a domain in htdocs/subfolder

Postby Altrea » 08. October 2020 19:40

Hi,

You are writing a whole bunch of words, but don't show us a single attempt of your configuration exactly.
Sure, we could provide you a full working example, but you would not learn anything from this.

So lets start that you show us a full not working example of what you think should be right?
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: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Map a domain in htdocs/subfolder

Postby machico91 » 08. October 2020 22:19

Hi Altrea,

Thanks for your help, you are absolutely right, here are my server configurations.

Configuration:

File "hosts" in etc/

127.0.0.1 localhost
127.0.1.1 VM-Ubuntu
127.0.0.1 test.mydomain.com

File "httpd.conf" in opt/lampp/apache2/conf

Alias /bitnami/ "/opt/lampp/apache2/htdocs/"
Alias /bitnami "/opt/lampp/apache2/htdocs"

<Directory "/opt/lampp/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

File "httpd.conf" in opt/lampp/etc/extra

Listen 443

ServerAdmin you@example.com
ServerName localhost

DocumentRoot "/opt/lampp/htdocs"
<Directory "/opt/lampp/htdocs">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All
Require all granted
</Directory>

<Files ".ht*">
Require all granted
</Files>

Virtual hosts
Include etc/extra/httpd-vhosts.conf

File httpd-vhosts.conf

<VirtualHost *:443>
ServerName mydomain.com
DocumentRoot "opt/lampp/htdocs"
</Directory>
</VirtualHost>

<VirtualHost *:443>
ServerName test.mydomain.com
DocumentRoot "opt/lampp/htdocs/test"
<Directory "opt/lampp/htdocs/test"
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


At this moment there is no .htaccess in the "htdocs" folder
I hope you can help me, thanks.
machico91
 
Posts: 6
Joined: 08. October 2020 13:14
XAMPP version: 7.4.4-1
Operating System: Ubuntu 18.04.5

Re: Map a domain in htdocs/subfolder

Postby Altrea » 08. October 2020 23:00

Okay, let's see:

machico91 wrote:File "hosts" in etc/
127.0.0.1 localhost
127.0.1.1 VM-Ubuntu
127.0.0.1 test.mydomain.com

The hosts file is only needed for local "fake" domains. So if you want to use a real domain you have officially registered, this is not needed.
But let's try to get this working locally first.

machico91 wrote:File "httpd.conf" in opt/lampp/apache2/conf

Alias /bitnami/ "/opt/lampp/apache2/htdocs/"
Alias /bitnami "/opt/lampp/apache2/htdocs"

Delete those lines, you don't need them. It can produce very weird problems if you address the same ressource from different urls.
In your environment you address https://localhost/... and https://localhost/bitnami/... to the same ressource.
Use Alias if you want to be able to address ressources which are normally not adressable for this domain, for example shared asset files, your music folder, etc.

machico91 wrote:<Directory "/opt/lampp/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Order allow,deny and Allow from all is old APache 2.2 syntax. Replace these two lines with the Line Require all granted

machico91 wrote:File "httpd.conf" in opt/lampp/etc/extra
...
<Files ".ht*">
Require all granted
</Files>

Change this access rule back to Require all denied. htaccess and htpasswd files should NEVER be permitted to be transfered by Apache to the client browser.
This is a huge security issue.

machico91 wrote:File httpd-vhosts.conf

<VirtualHost *:443>
ServerName mydomain.com
DocumentRoot "opt/lampp/htdocs"
</Directory>
</VirtualHost>

There is a closing Directory section without an opening one. This is invalid syntax.

machico91 wrote:<VirtualHost *:443>
ServerName test.mydomain.com
DocumentRoot "opt/lampp/htdocs/test"
<Directory "opt/lampp/htdocs/test"
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

I would never inheritate one vhost inside another (again multiple addresses for the same ressource argument).
Why not creating a completely independend folder like /opt/lampp/vhosts/mydomain.com/htdocs ?
And again old Apache 2.2 access rule syntax (replace with Require all granted).

And last but not least you are using https without all of the certificate configuration,

I am hoping i have described the issues with all the detail you need to understand them. If not always ask for further information.
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: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Map a domain in htdocs/subfolder

Postby machico91 » 09. October 2020 01:06

I followed the list:

File "hosts" in etc/
127.0.0.1 localhost
127.0.1.1 VM-Ubuntu
127.0.0.1 test.mydomain.com

The hosts file is only needed for local "fake" domains. So if you want to use a real domain you have officially registered, this is not needed.
But let's try to get this working locally first.



I deleted line "127.0.0.1 test.mydomain.com"

File "httpd.conf" in opt/lampp/apache2/conf

Alias /bitnami/ "/opt/lampp/apache2/htdocs/"
Alias /bitnami "/opt/lampp/apache2/htdocs"


I deleted this lines.

Order allow,deny and Allow from all is old APache 2.2 syntax. Replace these two lines with the Line Require all granted


Done

Change this access rule back to Require all denied.


Done

Now my file "httpd.conf" in opt/lampp/apache2/conf:

<Directory "/opt/lampp/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Why not creating a completely independend...


I created the folder structure "/opt/lampp/vhosts/mydomain.com/htdocs" and I modified "httpd-vhosts.conf":

<VirtualHost *:443>
ServerName test.mydomain.com
DocumentRoot "opt/lampp/vhosts/mydomain.com/htdocs/test"
<Directory "opt/lampp/vhosts/mydomain.com/htdocs/test"
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

I reset apache, but test.mydomain.com keeps pointing to the XAMPP dashboard.

Do you have any ideas about it?
Thank you for your time.
machico91
 
Posts: 6
Joined: 08. October 2020 13:14
XAMPP version: 7.4.4-1
Operating System: Ubuntu 18.04.5

Re: Map a domain in htdocs/subfolder

Postby Nobbie » 09. October 2020 09:12

The <Directory> line is missing the closing ">".

Anyway, your configuration lacks any SSL handling, no certificates, nothing. There are plenty of tutorials about SSL (https:) In Xampp, especially you have to get valid certificates for your domain. I dont think its a good idea to start with SSL as a total beginner. Try to implement http: at first, so you can get a first insight about configuring apache. You cannot get an Sysadmin for Apache from one day to another.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: Map a domain in htdocs/subfolder

Postby machico91 » 09. October 2020 12:05

Anyway, your configuration lacks any SSL handling...


I changed all the configuration to http on port 80

The <Directory> line is missing the closing ">".


I add >, now is <Directory "opt/lampp/test.mydomain.com/htdocs/test">
I also tried <Directory> "opt/lampp/test.mydomain.com/htdocs/test" to be sure not to make mistakes

The result is the same as before, test.mydomain.com always points to the dashboard.

As for the SSL, I have not configured the certificate because it is generated and managed by cloudflare, in fact (apart from the "redirection") everything works perfectly, however I wanted to try in http to be sure.
machico91
 
Posts: 6
Joined: 08. October 2020 13:14
XAMPP version: 7.4.4-1
Operating System: Ubuntu 18.04.5

Re: Map a domain in htdocs/subfolder

Postby Nobbie » 09. October 2020 12:22

Run http with option -S:

Code: Select all
sudo /opt/lampp/bin/httpd -S


This tells you which VirtualHosts are recognized and also runs a check.

Also have a look into the error_log for detailed error messages.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: Map a domain in htdocs/subfolder

Postby machico91 » 09. October 2020 13:55

Ok, now the "redirect" works,
the error was in:

Virtual hosts
Includes etc/extra/httpd-vhosts.conf

I had un-commented Virtual hosts, now I added it, so now it's like this:

#Virtual hosts
Includes etc/extra/httpd-vhosts.conf

Now ... when I point test.mydomain.com I have a 404 error, in the folder "opt/lampp/vhosts/mydomain.com/htdocs", inside htdocs there is a new installation of wordpress (still to be configured the first time).

if i run sudo /opt/lampp/bin/httpd-vhosts.conf -S I get:
f: Syntax error: newline unexpected

is there an error in the vhosts file?
could you give me a complete example of a working vhosts file in my case?

now, my vhosts file is (there is only this):

<VirtualHost *:80>
ServerName test.mydomain.com
DocumentRoot "opt/lampp/vhosts/test.mydomain.com/htdocs"
<Directory "opt/lampp/vhosts/test.mydomain.com/htdocs">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

the correct syntax is: <Directory "opt/lampp/vhosts/test.mydomain.com/htdocs"> or <Directory> "opt/lampp/vhosts/test.mydomain.com/htdocs" ?
however I tried both

Thank you
machico91
 
Posts: 6
Joined: 08. October 2020 13:14
XAMPP version: 7.4.4-1
Operating System: Ubuntu 18.04.5

Re: Map a domain in htdocs/subfolder

Postby Altrea » 09. October 2020 14:47

You did type a new line after DocumentRoot, this is not valid. The path needs to be written after DocumentRoot just separated by a space
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: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Map a domain in htdocs/subfolder

Postby machico91 » 09. October 2020 16:26

I'm trying, but without success, can you give me an example?

another question:
the correct syntax is: <Directory "opt/lampp/vhosts/test.mydomain.com/htdocs"> or <Directory> "opt/lampp/vhosts/test.mydomain.com/htdocs" ?

thank you
machico91
 
Posts: 6
Joined: 08. October 2020 13:14
XAMPP version: 7.4.4-1
Operating System: Ubuntu 18.04.5

Re: Map a domain in htdocs/subfolder

Postby Altrea » 09. October 2020 17:35

https://httpd.apache.org/docs/2.4/en/mo ... cumentroot

https://httpd.apache.org/docs/2.4/en/mo ... #directory

Apache does have a brilliant documentation with many many many examples given.
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: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 29 guests