Install and configure the Apache server on Mac OS X
Note: When the Mac system is installed, it has its own Apache server. Next, it is configured and started to run. The next thing to do is:
1. Configure the apache configuration file
2. Set Virtual Hosts
Start and view apache
Open the terminal and enter the following command:
$ Sudo apachectl start
$ Sudo apachectl-v
Configure the apache main configuration file
The main configuration file of apache is in the path/etc/apache2 /.
Back up the original file first
$ Sudo cp/etc/apache2/httpd. conf/etc/apache2/httpd. conf. backup
Modify the main configuration file
$ Vi/etc/apache2/httpd. conf
To facilitate reference to the default configuration, I will comment out the modified items as follows:
...
<Directory/>
# AllowOverride none
# Require all denied
Require all granted
AllowOverride all
</Directory>
...
# Virtual hosts
# Include/private/etc/apache2/extra/httpd-vhosts.conf
Include/private/etc/apache2/extra/httpd-vhosts.conf
...
Ps: in some old versions of configuration, allow can find many tutorials on the Internet, so I will not explain them here.
Set VM
The default apache root directory is under/Library/WebServer/. After the virtual host is configured, you can ignore the default website root directory, create different website directories in the appropriate places as needed.
Modify the httpd-vhosts.conf file at/etc/apache2/extra.
Back up original files
$ Sudo cp/etc/apache2/extra/httpd-vhosts.conf/etc/apache2/extra/httpd-vhosts.conf.backup
$ Sudo vi/etc/apache2/extra/httpd-vhosts.conf
Set the virtual host (the local access domain name of this site is mysite. local, and the root directory is/var/wwwroot/abc)
...
<VirtualHost *: 80>
ServerAdmin webmaster@mysite.local
DocumentRoot "/var/wwwroot/abc"
ServerName mysite. local
ErrorLog "/private/var/log/apache2/mysite. local-error_log"
CustomLog "/private/var/log/apache2/mysite. local-access_log" common
</VirtualHost>
...
Modify the hosts file at/etc/
$ Sudo vi/etc/hosts
Bind a custom domain name to 127.0.0.1
...
127.0.0.1 localhost mysite. local
...
Restart the Apache server
Sudo apachectl restart
This article permanently updates the link address: