Mac 自带Apache和PHP
默认路劲
- Apache服务器默认的web根目录在:
/Library/WebServer/Documents
- Apache的配置文件在:
/etc/apache2
常用命令
- 开启Apache:
sudo apachectl start
- 关闭Apache:
sudo apachectl stop
- 重启Apache:
sudo apachectl restart
- 查看Apache版本:
sudo apachectl -v
在terminal运行Apache启动命令
sudo apachectl start
启动浏览器,输入http://localhost
发现 It works!
Apache 启动成功,这时候使用的是默认服务器位置
配置实现个人服务器
创建个人服务器目录
在自己用户名下创建一个sites
文件夹-
找到配置文件给原来
httpd.conf
备份
进入Apache的配置文件:cd /etc/apache2
备份Apache的配置文件:sudo cp httpd.conf httpd.conf.bak
如果遇到错误想恢复配置文件:
sudo cp httpd.conf.bak httpd.conf
-
修改配置文件
进入/etc/apache2
目录下:sudo vim httpd.conf
- 修改服务器默认路径
查找DocumentRoot 将图片中红框路径 替换为sites
文件路径
添加黄颜色框的Indexes
- 修改服务器默认路径
-
加载php模块
查找php 将#删除
保存后退出:wq
不保存退出q!
备份php配置文件
进入/etc
目录下:cd /etc
备份php配置文件:sudo cp php.ini.default php.ini
重启Apache
sudo apachectl -k restart
1、警告
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MitakedeMacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
将#ServerName www.example.com:80
改为ServerName localhost:80