If you need to well set-up and maintain a local server environment on your Mac then look no further than MAMP. MAMP comes with Apache, MySQL and PHP and provides a local server environment independent of that installed as default on macOS. And it ’ s free .
however, out-of-the-box you ’ re limited to a single local host. This can prove inconvenient when developing multiple sites each requiring their own local host. The most commodious and price effective manner to overcome this limitation is to use virtual hosts.

therefore, how are virtual hosts configured under MAMP ? There is a pro interpretation of MAMP which allows easy configuration of virtual hosts but, unlike it ’ second baby brother, it ’ s not free. The entirely very alternative is to get your hands cheating and configure virtual hosts manually. This is not equally unmanageable as it may sound and can be accomplished fairly well .
As an model I ’ meter going to configure a virtual host for a locate that has a solution directory of /Users/steve/Sites/mysite1 containing a simple index file and I ’ ll identify the virtual horde local.mysite1 .

Dummy Tab
Dummy Content
Dummy Content

code






	
	Index.html
	
	


	 This is the contents of /Users/steve/Sites/mysite1/index.html


index.html in the directory /Users/steve/Sites/mysite1

I ’ thousand going to detail four exchangeable methods of configuring this virtual host all of which accomplish the same thing. Which method you decide upon is in truth a matter of personal choice but, whichever you choose you ’ ll first need to edit your Mac ’ s hosts file and then decide how you want to configure the default virtual host .

1. Editing The hosts File

Your Mac ’ randomness hosts file is hidden and located in the /private/etc directory. The easiest means to edit this file is by using an editor such as nano from the command line in Terminal .
loose Terminal and type :

Dummy Tab
Dummy Content
Dummy Content

code

sudo nano /private/etc/hosts

Press ↵. You ’ ll be prompted for your admin password. Your hosts file should resemble something similar to 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

Type elevation + / to go to the end of the file. We need to add a credit line for each virtual host we want to configure. The comment line beginning # is optional .

Dummy Tab
Dummy Content
Dummy Content

code

# Virtual Hosts
127.0.0.1 local.mysite1

The file should now resemble 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

# Virtual Hosts
127.0.0.1 local.mysite1

Type control condition + o then ↵ to save the file, then control + x to exit nano .

2. Handling http Requests For localhost

In a vanilla installation of MAMP without any virtual host configurations, Apache serves hypertext transfer protocol requests for localhost from the directory defined in Preferences… > Web Server > Document Root. By nonpayment this is /Applications/MAMP/htdocs. once a virtual master of ceremonies has been configured this behavior changes. nowadays when Apache receives an hypertext transfer protocol request in the form of a url it attempts to locate the matching virtual host shape. If it ’ s unable to locate this configuration it uses the first virtual master of ceremonies configuration it finds. To restore the original default behaviour we need to ensure the first virtual horde shape is configured as the default option .

# 000-default [default virtual host configuration]

	ServerName localhost
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Applications/MAMP/htdocs"
	
		Options Indexes FollowSymLinks Includes execCGI
		AllowOverride None
		Order Allow,Deny
		Allow From All
	

A default virtual host configured to serve requests from the directory /Applications/MAMP/htdocs

If you want files served from another location just change the DocumentRoot and Directory directives. This doesn ’ thymine have to be within the /Applications/MAMP directory .

# 000-default [default virtual host configuration]

	ServerName localhost
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Users/steve/Sites/000-default"
	
		Options Indexes FollowSymLinks Includes execCGI
		AllowOverride None
		Order Allow,Deny
		Allow From All
	

A default virtual host configured to serve requests from the directory /Users/steve/Sites/000-default

Remember to place a valid index file – as defined by the DirectoryIndex directing – in this directory otherwise Apache will display the directory ’ south contents. This is besides true when using /Applications/MAMP/htdocs as by default it doesn ’ thymine contain a valid index file .
To serve the same page – index.php – as is served when clicking Open WebStart page in MAMP use the keep up :

# 000-default [default virtual host configuration]

	ServerName localhost
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Applications/MAMP/bin/mamp"
	
		Options Indexes FollowSymLinks Includes execCGI
		AllowOverride None
		Order Allow,Deny
		Allow From All
	

A nonpayment virtual server configured to serve requests from the directory /Applications/MAMP/bin/mamp

so far we ’ ve added the name of a virtual server – local.mysite1 – to the /private/etc/hosts file and looked at how we might want to handle hypertext transfer protocol requests for localhost. Next we ’ ra going to configure the default virtual master of ceremonies and the virtual host for local.mysite1 using one of the keep up methods .
METHOD 1 – Add virtual master of ceremonies configurations to the existing Applications/MAMP/conf/apache/httpd.conf shape file .
METHOD 2 – Add virtual host configurations to the existing Applications/MAMP/conf/apache/extra/httpd-vhosts.conf shape file .
METHOD 3 – Add virtual host configurations to a new configuration file outside of the Applications/MAMP directory .
METHOD 4 – Create a new directory outside of the Applications/MAMP directory and populate it with individual virtual host configuration files .
To edit or create these files we can use any text editor such as Atom, BBEdit or TextEdit .

3.1 METHOD 1
Add virtual host configurations to /Applications/MAMP/conf/apache/httpd.conf

Open the file /Applications/MAMP/conf/apache/httpd.conf and voyage to the end .

#
# Uncomment the next line if Apache should not accept SSLv3 connections, to learn more google for "POODLE SSLv3".
# SSLProtocol All -SSLv2 -SSLv3

At the end of the file add the pursuit :

Dummy Tab
Dummy Content
Dummy Content

code

# Virtual Host Configurations

NameVirtualHost *

next, add the shape for the nonpayment virtual host. I ’ ve decided to use MAMP ’ s WebStart page .

Dummy Tab
Dummy Content
Dummy Content

code

# 000-default [default virtual host configuration]

	ServerName localhost
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Applications/MAMP/bin/mamp"
	
		Options -Indexes FollowSymLinks Includes +execCGI
		AllowOverride None
		Order Allow,Deny
		Allow From All
	

finally, add the virtual host shape for local.mysite1 .

Dummy Tab
Dummy Content
Dummy Content

code

# local.mysite1

	ServerName local.mysite1
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Users/steve/Sites/mysite1"
	
		Options Indexes FollowSymLinks Includes execCGI
		AllowOverride All
		Order Allow,Deny
		Allow From All
	

Save and close /Applications/MAMP/conf/apache/httpd.conf .

3.2 METHOD 2
Add virtual host configurations to /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Open the file /Applications/MAMP/conf/apache/httpd.conf and voyage to the end .

#
# Uncomment the next line if Apache should not accept SSLv3 connections, to learn more google for "POODLE SSLv3".
# SSLProtocol All -SSLv2 -SSLv3

At the goal of the file add the follow :

Dummy Tab
Dummy Content
Dummy Content

code

# Virtual Host Configurations

NameVirtualHost *

Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Unlike method 1 – where virtual hosts are configured in /Applications/MAMP/conf/apache/httpd.conf – in method acting 2 an Include argument points to another charge that will hold the virtual host configurations .
Save and close up /Applications/MAMP/conf/apache/httpd.conf .
Open the file /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and delete all of the stream contented .
future, add the configuration for the default virtual host. As with method acting 1, I ’ ve decided to use MAMP ’ s WebStart page .

Dummy Tab
Dummy Content
Dummy Content

Code

# 000-default [default virtual host configuration]

	ServerName localhost
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Applications/MAMP/bin/mamp"
	
		Options -Indexes FollowSymLinks Includes +execCGI
		AllowOverride None
		Order Allow,Deny
		Allow From All
	

finally, add the virtual host shape for local.mysite1 .

Dummy Tab
Dummy Content
Dummy Content

code

# local.mysite1

	ServerName local.mysite1
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Users/steve/Sites/mysite1"
	
		Options Indexes FollowSymLinks Includes execCGI
		AllowOverride All
		Order Allow,Deny
		Allow From All
	

Save and close /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf .

3.3 METHOD 3
Add virtual host configurations to a new configuration file outside of the /Applications/MAMP directory

This method acting is virtually identical to method 2. however, unlike method 2 – where virtual hosts are configured in /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf – in method acting 3 virtual hosts are going to be configured in a fresh configuration file outside of the /Applications/MAMP directory. I ’ ve chosen /Users/steve/Dropbox/httpd-vhosts.conf .
Open the file /Applications/MAMP/conf/apache/httpd.conf and navigate to the end .

#
# Uncomment the next line if Apache should not accept SSLv3 connections, to learn more google for "POODLE SSLv3".
# SSLProtocol All -SSLv2 -SSLv3

At the end of the file add the follow :

Dummy Tab
Dummy Content
Dummy Content

code

# Virtual Host Configurations

NameVirtualHost *

Include /Users/steve/Dropbox/httpd-vhosts.conf

Save and close /Applications/MAMP/conf/apache/httpd.conf .
Open a new vacate file .
Add the shape for the default virtual host. As in the previous methods I ’ ve decided to use MAMP ’ s WebStart page .

Dummy Tab
Dummy Content
Dummy Content

code

# 000-default [default virtual host configuration]

	ServerName localhost
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Applications/MAMP/bin/mamp"
	
		Options -Indexes FollowSymLinks Includes +execCGI
		AllowOverride None
		Order Allow,Deny
		Allow From All
	

finally, add the virtual horde configuration for local.mysite1

Dummy Tab
Dummy Content
Dummy Content

code

# local.mysite1

	ServerName local.mysite1
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Users/steve/Sites/mysite1"
	
		Options Indexes FollowSymLinks Includes execCGI
		AllowOverride All
		Order Allow,Deny
		Allow From All
	

Save and close the file using the lapp directory path and file diagnose as specified in the Include statement. In my example : /Users/steve/Dropbox/httpd-vhosts.conf .

3.4 METHOD 4
Create a new directory outside of the /Applications/MAMP directory and populate it with individual virtual host configuration files

As the head suggests we ’ re first going to create a modern directory outside of the /Applications/MAMP directory. I ’ ve chosen /Users/steve/Dropbox/vhosts. Each virtual host shape will have its own individual configuration file placed in this fresh directory .
We ’ rhenium going to start in the same way as in the previous 3 methods .
Open the file /Applications/MAMP/conf/apache/httpd.conf and navigate to the end .

#
# Uncomment the next line if Apache should not accept SSLv3 connections, to learn more google for "POODLE SSLv3".
# SSLProtocol All -SSLv2 -SSLv3

At the end of the file add the follow :

Dummy Tab
Dummy Content
Dummy Content

code

# Virtual Host Configurations

NameVirtualHost *

Include /Users/steve/Dropbox/vhosts/*.conf

Unlike in methods 2 and 3 where we ’ rhenium including a individual file, here we ’ re including all of the .conf files that ’ ll be placed in the /Users/steve/Dropbox/vhosts directory .
Save and cheeseparing /Applications/MAMP/conf/apache/httpd.conf .
Open a raw blank file .
Add the shape for the default option virtual host. As in the previous methods I ’ ve decided to use MAMP ’ s WebStart page .

Dummy Tab
Dummy Content
Dummy Content

code

# 000-default [default virtual host configuration]

	ServerName localhost
	DocumentRoot "/Applications/MAMP/bin/mamp"
	
		Options -Indexes FollowSymLinks Includes +execCGI
		AllowOverride None
		Order Allow,Deny
		Allow From All
	

Save this file as 000-default.conf in the like directory as specified in the Include argument. In my exercise : /Users/steve/Dropbox/vhosts .
adjacent, open another raw blank file .
Add the virtual host shape for local.mysite1

Dummy Tab
Dummy Content
Dummy Content

code

# local.mysite1

	ServerName local.mysite1
	DirectoryIndex index.html index.htm index.php
	DocumentRoot "/Users/steve/Sites/mysite1"
	
		Options Indexes FollowSymLinks Includes execCGI
		AllowOverride All
		Order Allow,Deny
		Allow From All
	

Save this file as local.mysite.conf in the lapp directory as specified in the Include instruction. In my case : /Users/steve/Dropbox/vhosts .

Testing The Virtual Host Configurations

Having created the virtual host configurations, check the syntax by opening Terminal and typing :

Dummy Tab
Dummy Content
Dummy Content

code

sudo /Applications/MAMP/Library/bin/apachectl -S

This will parse the shape files and show any syntax errors or if there are none, the virtual host configurations :

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:*                    is a NameVirtualHost
	     default server 000-default (/Users/steve/Dropbox/vhosts/000-default.conf:2)
	     port * namevhost 000-default (/Users/steve/Dropbox/vhosts/000-default.conf:2)
	     port * namevhost local.mysite1 (/Users/steve/Dropbox/vhosts/local.mysite1.conf:2)
Syntax OK

If there are no syntax errors, reload the configuration files for MAMP ’ s Apache in Terminal by typing :

Dummy Tab
Dummy Content
Dummy Content

code

sudo /Applications/MAMP/Library/bin/apachectl -k graceful

last, open the newly-configured sites in a browser using hypertext transfer protocol : //localhost and hypertext transfer protocol : //local.mysite1 .
http://localhost in a browser windowhttp://localhost in a browser window
hypertext transfer protocol : //localhost in a browser window

http://local.mysite1 in a browser windowhttp://local.mysite1 in a browser window
hypertext transfer protocol : //local.mysite1 in a browser window

reference : https://themedipia.com
Category : Website hosting

Leave a Reply

Your email address will not be published.