启动Apache
系统设置偏好(System Preferences) -> 共享(Sharing)-> Web共享(Web Sharing)
终端下运行检查apache是否已成功使能
$user@MacBook-Pro apache % apachectl -v
Server version: Apache/2.4.53 (Unix)
Server built: Jun 17 2022 19:40:05
启动apache
$user@MacBook-Pro apache % sudo apachectl start
浏览器中输入“localhost",如看到一个内容为“it works!”的页面,则Apahce已正常运行。
如访问异常,需查看log目录分析问题
cd /var/log/apache2
cat error_log
修改web根目录
系统默认的目录为
/Library/WebServer/Documents/
假设更改目录至
/Users/$USER/Documents/apache
先访问apache配置文件
/etc/apache2/httpd.conf
其中修改
DocumentRoot "/Users/$USER/Documents/apache"
<Directory "/Users/$USER/Documents/apache">
Options Indexes FollowSymLinks Multiviews
MultiviewsMatch Any
AllowOverride None
Require all granted
Require host ip
</Directory>
然后为该文件夹添加权限
chmod o+rw ~/Documents