This article show us how to use mac own local web sever apache to build our own static website. 😄.
macOS PHP best practice (one)
最简单直接的方式还是使用 Mac 上自带的 Apache 和 PHP。
启动 Apache
- 启动:
apache $sudo apachectl start
启动后,在浏览器中输入
localhost,可以看到页面上显示It works!。(/Library/WebServer/Documents/下的index.html.en文件)Apache的默认根目录是/Library/WebServer/Documents/。
添加apache对php的支持
- 打开
http.conf配置文件:
sudo vim /etc/apache2/httpd.conf
- 找到以下代码
LoadModule php5_module libexec/apache2/ libphp5.so并去掉注释(去掉前面的==#==号),wq保存退出。
重启 Apache,进行php类型文件的调试
- 重启:
sudo apachectl restart
在
Apache的根目录/Library/WebServer/Documents/下新建project文件夹并写一个php文件输出hello world。此时,在浏览器打开 http://localhost/project/test.php 就可以正常看到hello world了~如果有权限问题,使用下列命令:
sudo chown yourname:staff project
其中 yourname 是你自己的名字。
使用homebrew安装mysql
- 安装homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 安装mysql
brew install mysql
- 启动mysql
mysql.server start
Apache 常用命令
- 启动 Apache 服务
sudo apachectl start
- 重新启动 Apache 服务
sudo apachectl restart
- 关闭 Apache 服务
sudo apachectl stop
- 查看 Apache 版本
httpd -v