Add a virtual host in MAMP
MAMP is a local Web development solution.
- Apache config
- Find apache config file at ‘/Applications/MAMP/conf/apache/httpd.conf’, open it in any editor
- Find this line
#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
and delete"#"
, save fife.
- vhost config
- Find apache config file at ‘/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf’, open it in any editor
There are two vitual host examples look like this
1
2
3
4
5
6
7
8<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/Applications/MAMP/Library/docs/dummy-host.example.com" //where your document located
ServerName dummy-host.example.com //domain as you wish
ServerAlias www.dummy-host.example.com //alias optional
ErrorLog "logs/dummy-host.example.com-error_log" //error optional
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>My vitural host is like:
1
2
3
4
5
6
7<VirtualHost *:80>
DocumentRoot "/xxxx/xxxx/xxxx/xxxx/test"
ServerName api.com
ServerAlias api.com
ErrorLog "logs/api.com-error_log"
CustomLog "logs/api.com-access_log" common
</VirtualHost>DocuementRoot
can be changed atMAMP -> preference -> Web server
- Set the localhost(127.0.0.1) to the domain you wish
- In terminal or iTerm, run
$ sudo vi /etc/hosts
- Insert one line
127.0.0.1 api.com
- An easy test
- In your Vitual host DocumentRoot, Create
index.php
1
2
3
echo "Hello My Virtual Host"
- Restart MAMP
- api.com is ready for your service