Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of Mac built-in apache configuration

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Mac comes with apache, which can be directly used to build local web containers. The configuration process is basically the same as windows, but there are a few points to pay attention to (avoid trampling)

Apache

Sudo apachectl start [/ restart/stop] # enable, etc. Sudo apachectl-v # View version sudo / usr/sbin/httpd-k start # when there is an error in the configuration file, you can check the location of the error in this way

Remember to turn on an option before using it

Php is not enabled by default in apache under Mac. It needs to be enabled manually.

Sudo vi / etc/apache2/httpd.conf

LoadModule php5_module libexec/apache2/libphp5.so

Apache modifies web directory

The default directory is:

/ Library/WebServer/Documents

And often this directory is not convenient to use, first, permissions, after all, we do not want to make every change, we have to bring a sudo; second, Finder is not convenient to open. So you need to modify the web directory.

Sudo vi / etc/apache2/httpd.conf237 DocumentRoot "/ Users/username/wwwroot" 238

Configure vhost

Open the vhost extension first (just remove the comment #)

Sudo vi / etc/apache2/httpd.conf

Include / private/etc/apache2/extra/httpd-vhosts.conf

Edit the vhost file

Sudo vi / etc/apache2/extra/httpd-vhost.conf ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/ Users/username/wwwroot" ServerName localhost ErrorLog "/ private/var/log/apache2/local-error_log" CustomLog "/ private/var/log/apache2/local-access_log" common ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/ Volumes/FAT/bugs" ServerName wooyun.sb ErrorLog "/ private/var/log/apache2/wooyun-error_log" CustomLog "/ private/var / log/apache2/wooyun-access_log "common Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted

Only local access is allowed

For security purposes, I intend to configure the apache service to allow only native access. The online method is not very suitable. After many attempts, the following methods are feasible:

Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted # add access control Order Deny,Allow Deny from all # many methods given in the Order Deny,Allow Deny from all # network are not added here, only there are allow, and the actual measurement is not applicable. This line ~ Allow from 127.0.0.1 must be added.

Deal with some problems

1 、 403 Forbidden

If something goes wrong with the configuration of the log file log, 403 will occur. The solution is / var/log/apache2/ to clear the log in it.

It is also possible that the PHP extension is not enabled.

2. 403 Forbidden occurs when Vhost is configured

Note that configuration files are required to join

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report