1. Preparation
In this section i'm used local.mysite.dev for sampleStart Apache
1. Go to System Preferences
2. Select "sharing"
3. Check the box "Web Sharing" -- for starting the apache
2. Edit the Host file
For editing you can use nano or mate text editor for command linesudo nano /etc/hostsor
sudo nano /private/etc/hostsYou can see the following codes:
# # 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 localhostadd new host local.mysite.dev at end of line
# # 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 127.0.0.1 local.mysite.dev
3. Switch in the httpd.conf file
sudo nano /etc/apache2/httpd.conffind the "# Virtual hosts" string using ctl + w and type "# Virtual hosts" without (")
# Virtual hosts #Include /private/etc/apache2/extra/httpd-vhosts.confun comment the code to enable the VHost
# Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf
4. Add virtual host in apache
sudo nano /private/etc/apache2/extra/httpd-vhosts.confadd these codes:
# # 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 anyblock. # < VirtualHost *:80> ServerName localhost DocumentRoot "/Library/WebServer/Documents" < /VirtualHost> < VirtualHost *:80> ServerAdmin local@mysite.dev DocumentRoot "/Library/WebServer/Documents/mysite/webroot/" ServerName local.mysite.dev < directory "/Library/WebServer/Documents/mysite/webroot/"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all < /directory> ErrorLog "/private/var/log/apache2/local.mysite.dev.com-error_log" < /VirtualHost>
5. Restart Apache
finally, restart the Apachesudo apachectl restartOpen your browser the type the url (http://local.mysite.dev) --for example