Setting up a virtual host on XAMPP on Mac - macos

I am trying to set up a virtualhost on my apple mac on localhost. The server is provided by XAMPP, which bundles Apache/MySQL/PHP in one bundle.
Here is what I have done so far:
Edited /private/etc/hosts to include 127.0.0.1 to point to test.myserver.local
127.0.0.1 test.myserver.local
Edited /Applications/XAMPP/etc/extra/httpd-vhosts.conf to inlcude my vhosts details
<VirtualHost *:80>
DocumentRoot /Users/???/Documents/workspace/trunk/htdocs
ServerName test.myserver.local
<Directory "/Users/???/Documents/workspace/trunk/htdocs">
AllowOverride All
</Directory>
</VirtualHost>
Placed a simple index.html in there with the word test in it.
I have restarted the server, and then browse to the test url to be greeted with Apache's default page instead of my test page.
The vhosts file works for another virtual host, the code is copied with the respective bits changed (i.e. folder paths), the hosts file works, as when Apache is turned off, my browser says server not found.
Why is Apache refusing to show up my test code? Are there any other files I need to change? I cant think of any others, its usually just those on linux/windows.

On xampp you need to edit 3 files to setup virtual hosts
the /etc/hosts and /Applications/XAMPP/etc/extra/httpd-vhosts.conf as you did.
But also you need to edit /Applications/XAMPP/xamppfiles/etc/httpd.conf to include the http-vhosts.conf
make sure you have uncommented this line
# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
EDIT
Have you tried to add this lines
Order allow,deny
Allow from all
Just before the
AllowOverride All

Try leaving the the setting for "localhost" at the end of the file "httpd-vhosts.conf",
i.e.:
#
# Virtual Hosts
#
...
# others vhost
<VirtualHost *:80>
...
</VirtualHost>
# localhost
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
#end of httpd-vhosts.conf file
Worked for me, greetings!

Have you told Apache to actually use name-based virtual hosting?
# Use name-based virtual hosting.
#
NameVirtualHost *:80
I don't believe it's enabled by default in Xampp on Mac.

Related

XAMPP on MAC - change directory and virtual hosts to other volume

I am trying to move my default htdocs folder from
/Applications/xamppfiles/htdocs/
to a folder on another partition at
/Volumes/Webserver/xampp/htdocs/
which happens to be the directory where XAMPP for Windows is installed, allowing me to use the same directory for my website project regardless whether I code on Windows or MAC.
(Note: I am using a Macbook Air with Bootcamp and ParagonNTFS, hence can read/write NTFS partitions)
I have successfully adjusted the httd.conf and vhost.conf files and managed to relocate the localhost directory to point to the files on the other volume, but I do NOT want to change the localhost directory, but rather create a new virtual host that points me to the other volume. So in short, I want these three domains
localhost -> /Applications/xamppfiles/htdocs/
site1.local -> /Volumes/Webserver/xampp/htdocs/project1/
site2.local -> /Volumes/Webserver/xampp/htdocs/project2/
The issue now is that when entering site1.local or site2.local into my browser, the browser redirects me to google because it cannot find the folders.
If I change the forward directory for localhost, things work fine.
localhost -> /Volumes/Webserver/campp/htdocs/project1/
Following config at play here:
httd.conf
DocumentRoot "/Volumes/Webserver/xampp/htdocs"
<Directory "/Volumes/Webserver/xampp/htdocs">
Include etc/extra/httpd-vhosts.conf
httpd-vhosts.conf
# Project1
<VirtualHost *:80>
ServerName site1.local
DocumentRoot "/Volumes/Webserver/xampp/htdocs/project1"
<Directory "/Volumes/Webserver/xampp/htdocs/project1">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/site1.local-error_log"
</VirtualHost>
# Project2
<VirtualHost *:80>
ServerName site2.local
DocumentRoot "/Volumes/Webserver/xampp/htdocs/project2"
<Directory "/Volumes/Webserver/xampp/htdocs/project2">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/site2.local-error_log"
</VirtualHost>
# localhost [must be included as the default named server]
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Volumes/Webserver/xampp/htdocs"
<Directory "/Volumes/Webserver/xampp/htdocs">
Require all granted
</Directory>
</VirtualHost>
I can access the localhost fine, but site1 and site2 dont work. If I change the documentroot of localhost, I can access fine though.
hosts
127.0.0.3 site2.local
127.0.0.2 site1.local
127.0.0.1 localhost
I tried assigning each site its own ip address, but without success.
Any help is much appreciated.
Had to restart about 10 times but now it seems the settings have taken effect. I can confirm the arrangement above works but requires a full restart in order to take effect.

How to create virtual hosts in MAMP?

I am new to Mac but used Ubuntu for development for a long time. I know how to create virtual hosts in Ubuntu but have no idea about Mac. I have created a hosts entry like below :
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost mysite.loc
255.255.255.255 broadcasthost
::1 localhost
But what to do next?
While googling, I found these steps to easily create virtual hosts on MAMP:
Open your console in mac and edit your hosts file like this
sudo vim /etc/hosts
This opens a system file that contains the following line:
127.0.0.1 localhost
add your desired host name after local host:
127.0.0.1 localhost mysite.loc
press ESC, then :wq! to overwrite and close the file.
Now go to your MAMP directory and open apache config file located at /Applications/MAMP/conf/apache/httpd.conf in any text editor and locate the following lines:
# Virtual Hosts
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Remove the hash (pound) sign from the beginning of the line that begins with Include
# Virtual Hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Save the file, and then open Applications/MAMP/conf/apache/extra/httpd-vhosts.conf. This is where you define the virtual hosts.
At the bottom of the page are two examples of how to define virtual hosts in Apache. They look like this:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/Applications/MAMP/Library/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "/Applications/MAMP/Library/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
Edit both examples. Virtual hosts override the existing localhost, so the first one needs to re-establish localhost. Edit the second one for the virtual host you want to add. Only the DocumentRoot and ServerName directives are required. To add a virtual host for mysite, the edited definitions should look like this:
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/username/Sites/mysite"
ServerName mysite.loc
</VirtualHost>
This assumes that you want to locate the files for mysite in your Sites folder. Replace "username" in the second definition with your own Mac username. If you want to store the files in a different location, adjust the value of DocumentRoot accordingly.
If you want to create more than one virtual host, copy one of the definitions, and edit it accordingly.
Save all the files you have edited, and restart the servers in the MAMP control panel. You should now be able to access the virtual host with the following URL: http://mysite.loc/.
Enjoy..!!
Allow virtual hosts
Go to Applications > MAMP > conf > apache > httpd.conf
Find this line:
# Virtual hosts
#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Uncomment the code by removing the hash symbol.
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Allow SymLink Override
Find this line in that same httpd.conf file.
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
change None to All.
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
Add the virtual host path
Go to Applications > MAMP > conf > apache > extra > httpd-vhosts.conf
add the virtual host with servname and document root like the below code
<VirtualHost *:80>
ServerName example.dev
DocumentRoot "/path/to/directory"
</VirtualHost>
Allow your computer to recognize your local domain
Open terminal and type
sudo pico /etc/hosts
then add your domain
127.0.0.1 example.dev
Restart your server.
If the url is showing error in chrome try safari
In my config in MAMP, only the first virtual host was responding.
After hours of search I founded the instruction for solving the problem (before listing virtual hosts definitions) :
NameVirtualHost *:80
Now, my 3 virtual hosts are working !
I followed this post, as recommended by szatti1489, and it worked for me: https://www.taniarascia.com/setting-up-virtual-hosts/
A couple of points are worth mentioning though:
This line didn't already exist in my httpd.conf file, I had to add it: Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
I had to use the .test domain ending, not .dev for my VirtualHost ServerName. The post mentions this, but then continues using.dev. Apparently, Chrome didn't support the .dev domain ending after 2017, although it didn't work in Firefox or Safari for me either.
Recently I changed from XAMP to MAMP on MAC. I tried to set up my last virtual hosts, but MAMP's 8888 port number was avoid the regular work.
Finally I found the solution. You could change the Listen port and the ServerName in httpd.conf as you could find in the following post:
https://www.taniarascia.com/setting-up-virtual-hosts/
Adding to the answer of Ritesh
You probably also want to add a directory configuration in your httpd.conf similar to the one that is already there, but for your the document root of your new server.
For Example:
<Directory "/Users/username/Sites/mysite">
Options All
AllowOverride All
Order allow,deny
Allow from all
XSendFilePath "/Users/username/Sites/mysite"
</Directory>
Building off of Srinivasan's answer. This is what I did in order to have 2 virtual hosts set up
myapp-local.local:8888/
myapp-local2.local:8888/
/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:8888>
DocumentRoot /Applications/MAMP/htdocs/my_app
ServerName myapp-local.local
<Directory "/Applications/MAMP/htdocs/my_app">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:8888>
DocumentRoot /Applications/MAMP/htdocs/instance-2/my_app
ServerName myapp-local2.local
<Directory "/Applications/MAMP/htdocs/instance-2/my_app">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
sudo vi /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost myapp-local.local
127.0.0.1 localhost myapp-local2.local
255.255.255.255 broadcasthost
::1 localhost
Drupal specific:
sites/default/settings.php
$settings['trusted_host_patterns'] = [
'^localhost$',
'^myapp-local.local$'
'^myapp-local2.local$'
];
*/
restart MAMP server

publish xampp publically from home laptop

I'm trying to publish a locally installed WordPress website - publically.
Had to reformat my laptop, so now running Windows 10 from my laptop at home.
I can already RDP to it from e.g. work PC, externally, etc.
I used to have Windows 8, WAMP installed and used to publish websites to my domain - www.site01.co.uk
site01.co.uk has been pointing to my fixed IP since I had Windows 8 and still is pointing. The fixed IP address hasn't changed.
I now opened up XAMPP httpd.conf and placed below "code" at the bottom:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\wp"
servername http://www.site01.co.uk
<Directory "C:\xampp\htdocs\wp">
Allow from all
Require all granted
Options Indexes
</Directory>
</VirtualHost>
This didn't work .
WordPress is installed in htdocs\wp folder.
You have a couple of problems with your Virtual Hosts definition. Virtual Hosts is definitely the way to go though.
When you create a Virtual Host Apache ignores the default definition of localhost in your httpd.conf file so its always a good idea to include a VH definition for that as the first VH defined, with access limited to Require local this helps stop drive-by ip address access attempts as the Require local will return an Access denied if you/they just use your WAN ip to try and see whats on your web server.
This should go in the \xampp\apache\conf\extra\httpd-vhosts.conf file. Remove all the example stuff from that file when you add this definition.
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
<Directory "C:\xampp\htdocs">
AllowOverride All
Options Indexes FollowSymLinks
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\wp"
ServerName site01.co.uk
ServerAlias www.site01.co.uk
<Directory "C:\xampp\htdocs\wp">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
Apache 2.4 uses the Require parameter and not the Allow/Deny which was Apache 2.2 syntax.
You now edit the httpd.conf file and find the
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
and remove the # comment like so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Then make sure that the Port Forwarding on your router is forwarding port 80 to the correct ip address for your PC.

Virtual Hosts not working XAMPP 1.8.3

Im trying to set up a virtual host using my local xampp stack but after following many tutorials i simply can't work out where im going wrong.
Here is what i added to my httpd-vhost.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot E:\Programs\xampp\htdocs
</VirtualHost>
<VirtualHost *:80>
DocumentRoot E:\Programs\xampp\htdocs\CVCMS
ServerName cvcms.dev
<Directory "E:\Programs\xampp\htdocs\CVCMS">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And here is my hosts file
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost
127.0.0.1 lmlicenses.wip4.adobe.com
127.0.0.1 lm.licenses.adobe.com
127.0.0.1 cvcms.dev
I have restarted apache after every change, i have made sure http.conf is linked to the httpd-vhosts file.
The issue is when i type in the domain cvcms.dev it shows the xampp splash page instead of the index.php in my cvcms folder.
Any ideas why?
Thanks
please remember to add the quotes to your virtual host document root path. At the same time what you need to to do enable them is to find httpd.conf , in this version it should be in your etc folder within your XAMPP's root folder.
Look out for :
# Virtual hosts
#Include etc/extra/httpd-vhosts.conf
Since '#' is a comment prefix, you have to uncomment "#Include etc/extra/httpd-vhosts.conf"
See if this works. Remember to restart your XAMPP's apache server to read the new settings you've just set. Cheers !
You can read more on this here.

Organize multiple websites on Macbook

What steps are needed to complete adding another website to OS X (Lion) ?
I want to have the 2 websites organized in 2 folders under 'Sites', but not sure how to get there. As can be seen in the image below, the MB currently has the 'default' (first) website spread out in Sites. I am concerned that putting this default site into a folder of Sites, call it 'siteA' will cause it to disappear.
These sites are not hosted on this MB. (OK, well they are, ...) It is being used for the development, viewing and testing within BBEdit.
After the steps below, the URL http://bella, replies Forbidden - You don't have permission to access / on this server. (??)
Suggestions welcomed. Thanks in advance.
So far, I've added or amended:
-- private/etc/hosts (added the following)
127.0.0.1 bella
-- private/etc/apache2/http.conf (uncommented 2nd line)
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
-- /private/etc/apache2/extra/httpd-vhosts.conf (added 2 VirtualHost blocks)
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/dolan2go/Sites/Bella"
ServerName bella
</VirtualHost>
The directory structure of my Macbook currently looks like:
Have to make a few modifications to get this to work. With the desire to have folders 'FirstSite' & 'Bella' in the 'Sites' folder. (My User directory structure has been altered because of a HD & SSD hardware mod)
Amend the hosts.conf file to: (last 2 lines - see note below)
127.0.0.1 bella.local
127.0.0.1 firstSite.local
Uncomment the line to use the vhosts.conf file (as in original question)
Amend the httpd-vhosts.conf to:
# Localhost first
<VirtualHost *:80>
DocumentRoot "/Volumes/HDD 1/<username>/Sites"
ServerName localhost
</VirtualHost>
# local test Sites
<VirtualHost *:80>
DocumentRoot "/Volumes/HDD 1/<username>/Sites/FirstSite"
ServerName firstSite.local
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Volumes/HDD 1/<username>/Sites/Bella"
ServerName bella.local
</VirtualHost>
# Allow from localhost only or other directives
<Directory "/Volumes/HDD 1/<username>/Sites/FirstSite">
Order Deny,Allow
Allow from 127.0.0.1
Deny from all
</Directory>
<Directory "/Volumes/HDD 1/<username>/Sites/Bella">
Order Deny,Allow
Allow from 127.0.0.1
Deny from all
</Directory>
Now I can access the local version of both sites with http://bella.local & http://firstSite.local (I decided to add the local to help distinguish between the local and remote versions.)
A reply by twtwtw 3/4 down the page at Local Web Server for Lion really helped clear the issue.

Resources