I need to add virtual host in Mac using MAMP Pro.
First step:(Edit hosts in /etc/hosts) like This
##
# 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
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
27.0.0.1 BSDs-iMac.local # added by Apache Friends XAMPP
127.0.0.1 symfony.local # MAMP PRO - Do NOT remove this entry!
::1 symfony.local # MAMP PRO - Do NOT remove this entry!
Next Step:(Open MAMP's vhosts file) and remove #
/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Next Step: (edit httpd conf)
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# 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>
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>
<VirtualHost *:80>
DocumentRoot "/Desktop/avinar/my-project/public"
ServerName symfony.local
</VirtualHost>
Last Step add virtual host into mamp pro like this:
Now when I check Url: symfony.local i see this error:
>
Forbidden
>
You don't have permission to access / on this server.
When I check this url: symfony.local/my-projet/public server work and i see page.
How do fix this problem?!
That virual host may be lacking a Directory directive:
<Directory "/Desktop/avinar/my-project/public">
Options -Indexes +MultiViews +FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
If it doesn't work, recursively set apache (or however the user may be called) as the owner (or owner group) of /Desktop/avinar/my-project.
I moved from linux to a mac. I have Apache and php setup.
Now apache seems to only load the first virtual host listed. It also only loads it in the browser via local host and not the sitename. Its been 3 days hunting the net or solutions nothing seems to work.
now if i make the document root for the virtual host eg. /Library/WebServer/Documents/ then it works. If i add an extra directory it fails eg. /Library/WebServer/Documents/livingahimsa.co.uk
here is the config: ( I have tried the doc root with quotes and without)
##
# 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
127.0.0.1 ahimsainvestments.com
127.0.0.1 livingahimsa.co.uk
127.0.0.1 ahimsavillage.com
255.255.255.255 broadcasthost
::1 localhost
and vhost:
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/ahimsainvestments.com
ServerName ahimsainvestments.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/livingahimsa.co.uk
ServerName livingahimsa.co.uk
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/ahimsavillage.com
ServerName ahimsavillage.com
pache2/httpd.conf
Can you tell me please what am I doing wrong in Virtual host settings?
I am editing two files:
Apache/conf/extra/httpd-vhosts.conf and Windows/System32/drivers/etc/hosts
httpd-vhosts.conf looks like
<VirtualHost 127.0.0.1>
ServerName scouttautomotive.com
ServerAlias www.scouttautomotive.com
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName bosp.sk
ServerAlias bosp.sk.localhost
DocumentRoot "C:/Apache24/htdocs/bosp/web"
</VirtualHost>
hosts file looks like
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 scouttautomotive.com
127.0.0.1 bosp.sk
What is wrong with it? I am realy confused cause bosp.sk virtual host works well.
After setting the domain ip to 127.0.0.1 to host file, You must restart your computer or flush dns cache to get that applied. Did you do?
So look at these config files and note that difference is only in the last letter of ServerName.
httpd-vhosts.conf
<VirtualHost 127.0.0.1>
ServerName scouttautomotive.com
ServerAlias scout.com.localhost
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName scouttautomotiv.com
ServerAlias drom.com.localhost
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
hosts
127.0.0.1 scouttautomotive.com
127.0.0.1 scouttautomotiv.com
First version redirects me to one hosting which offers this domain to sell. Second version works well as virtual host. Both are created in the same time. So it looks command ipconfig /flushdns may not be enough.
Another possible solutions can be find here https://serverfault.com/questions/452268/hosts-file-ignored-how-to-troubleshoot Good luck!
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
I have two websites www.test1.com and www.test2.com.I hosted both sites in windows wampp server with same IP called xx.xxx.xx.xx .But while opening both sites www.test1.com is comming.Here www.test1.com files are in 'test1' folder and www.test2.com are in 'test2' folder.
I Tried virtual host in wampp...but its not working...
This is my \wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf file
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test1"
ServerName test1
ServerAlias test1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test2"
ServerName localhost
ServerAlias test2.com
<Directory "c:/wamp/www/test2">
AllowOverride All
Require local
Require all granted
Allow from all
</Directory>
</VirtualHost>
This is my C:\Windows\System32\drivers\etc\hosts file
127.0.0.1 localhost
127.0.0.1 test1.com
127.0.0.1 test2.com
Both your domain names are going to the site defined first in the httpd-vhost.conf file because that is the default behaviour when Apache cannot find a site requested in the host definitions. It normally means you have done something wrong in the defining of your VHOSTS.
Your host definitions are a little wrong, and you are mixing Apache 2.2 and 2.4 security syntax which often causes problems, try these
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
<Directory "C:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test1"
ServerName test1.com
ServerAlias www.test1.com
<Directory "c:/wamp/www/test1">
AllowOverride All
Require local
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test2"
ServerName test2.com
ServerAlias www.test2.com
<Directory "c:/wamp/www/test2">
AllowOverride All
Require local
Require all granted
</Directory>
</VirtualHost>
Now so that you can see the sites locally on the WAMPServer PC the hosts file should look like this. Remember, these entries only effect the PC containing the HOSTS file, and have no effect on internet access or the ability of a remote user to use these domain name.
# IPV4 loopback
127.0.0.1 localhost
127.0.0.1 test1.com
127.0.0.1 test2.com
# IPV6 loopback
::1 localhost
::1 test1.com
::1 test2.com
The first line needs to be
NameVirtualHost *:80