Newbie: How to set up virtual hosts...

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

Newbie: How to set up virtual hosts...

Postby ashtonleasure » 28. August 2020 18:26

I am very new to the programming world, so please have some patience with me :D I have searched and searched for a tutorial on how to set up virtual hosts in the newest version and I have been largely unsuccessful. If anyone could give a run down on how to go about this, I would be very appreciative. From what I've learned, I need to uncomment the vhosts code in the httpd.conf file, enter '127.0.0.1 mysite.loc' in /etc/hosts file, and enter the virtual host in /opt/lampp/etc/extra/httpd-vhosts.conf but I'm obvioulsy not doing this correctly. Please help!!!!
ashtonleasure
 
Posts: 3
Joined: 28. August 2020 17:59
XAMPP version: 7.4.9
Operating System: Mac OSX

Re: Newbie: How to set up virtual hosts...

Postby stinnet » 03. September 2020 10:51

Could you tell where you have stuck?
Here's a short for a cleaner process:

1. Switch to root user in the Terminal not to have problems with permission
Code: Select all
sudo su -

2. Then edit the config file
Code: Select all
vi /etc/apache2/httpd.conf

3. Then find this line
Code: Select all
#Include /private/etc/apache2/extra/httpd-vhosts.conf

4. Add the following line below
Code: Select all
Include /private/etc/apache2/vhosts/*.conf

5. Then create this directory
Code: Select all
mkdir /etc/apache2/vhosts
cd /etc/apache2/vhosts

6. And create the default virtual host config file
Code: Select all
vi _default.conf

7. Add this config
Code: Select all
<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>

After this stage you will have a smoother install.
stinnet
 
Posts: 2
Joined: 01. September 2020 13:03
XAMPP version: v7.1.1-0
Operating System: Windows

Re: Newbie: How to set up virtual hosts...

Postby ashtonleasure » 03. September 2020 12:34

stinnet wrote:Could you tell where you have stuck?
Here's a short for a cleaner process:

1. Switch to root user in the Terminal not to have problems with permission
Code: Select all
sudo su -

2. Then edit the config file
Code: Select all
vi /etc/apache2/httpd.conf

3. Then find this line
Code: Select all
#Include /private/etc/apache2/extra/httpd-vhosts.conf

4. Add the following line below
Code: Select all
Include /private/etc/apache2/vhosts/*.conf

5. Then create this directory
Code: Select all
mkdir /etc/apache2/vhosts
cd /etc/apache2/vhosts

6. And create the default virtual host config file
Code: Select all
vi _default.conf

7. Add this config
Code: Select all
<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>

After this stage you will have a smoother install.


I am not sure where I am stuck, I only know the IP adress doesn't work. I will walk you through what I've done.

1. I followed the directions you gave me.

2. I when to my httpd-vhosts.conf file and entered the following...
<VirtualHost *:80>
ServerAdmin *************
DocumentRoot "/opt/lampp/htdocs"
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
ServerAdmin *************
DocumentRoot "/opt/lampp/htdocs/vhost_test"
ServerName vhost_test
</VirtualHost>

3. I entered the /etc/hosts file and entered the following at the bottom.
127.0.0.1 vhost_test

4. In my browser I enter http://vhost_test:8080 and it says the IP address can not be found.

I believe my problem is with step 3 because I can change the file path for the first virtualhost, the localhost one, and it is working. However, as soon as I change the server name I run into problems. Thank you for taking the time to try and help me! I am very grateful.
ashtonleasure
 
Posts: 3
Joined: 28. August 2020 17:59
XAMPP version: 7.4.9
Operating System: Mac OSX

Re: Newbie: How to set up virtual hosts...

Postby Nobbie » 03. September 2020 12:50

I think you are editing the wrong hosts file. As your Xampp Installation is running in a Virtual Machine, you should edit another hosts file. I dont know how the Virtual Machine is implemented for Xampp, i do not recommend using it anyway. There is an installer for a "normal" Xampp installation on macOS also, which installs into the /Application/Xampp Folder instead of running in a Virtual Machine. You should uninstall Xampp-VM and instead download and install the "normal" version. You can find out which is normal and which is VM, as the VM installers are approx. twice as big (filesize) than the normal installers.

On https://www.apachefriends.org/de/download.html you can find six installers for Xampp OSX, i assume the first three of them are "normal" installations, the other three are VMs. Pick one of the normal and install it. Finally you do not run Xampp in /opt/lampp (thats a Linux path of the Virtual Machine), instead you will find it in /Applications/Xampp etc. And for that installation /etc/hosts of course is the correct system hosts file, where you can apply your changes. Apache will simply run on port 80 then, so simply use http://localhost for the Xampp Dashboard.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 43 guests