Mac下搭建lamp

Mac下搭建lamp

Mac 自带了Apache,并默认支持PHP环境,只需要配置Apache和PHP即可使用。需要单独安装mysql服务端。

  • Apache 基础配置
  • Apache支持PHP配置
  • Apache虚拟主机配置
  • *Mysql安装配置

Apache 基础配置

  1. 备份配置文件
sudo cp  /etc/apache2/httpd.conf  /etc/apache2/httpd.conf.bak
  • 1
  1. 修改网站目录
sudo vim /etc/apache2/httpd.conf
#搜索DocumentRoot,把 DocumentRoot "/Library/WebServer/Documents"中的目录修改为自己的网站目录
DocumentRoot "/Users/apple/Sites"
#把 <Directory "/Library/WebServer/Documents"]] > 改为 <Directory "/Users/apple/Sites"]] >
#修改运行Apache的用户和用户组,搜索Group和User
Group www
User www
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  1. 设置网站目录权限和属组
chmod 755 -R /Users/apple/Sites
Chown www:www -R /Users/apple/Sites
  • 1
  • 2

Apache支持PHP配置

  1. apache支持PHP
sudo vim /etc/apache2/httpd.conf
#找到 #LoadModule php5_module libexec/apache2/libphp5.so删除行首的 # 让服务器启动时加载php模块
#重启apache
sudo apachectl -k restart
  • 1
  • 2
  • 3
  • 4

Mysql安装配置

  1. 使用brew安装:brew install mysql 
    brew使用方法
  2. 重启mysql:sudo apachectl -k restart
  3. 在Apache网站根目录下写,访问是否出现PHP info页面
<?php
    phpinfo();
?>
原文地址:https://www.cnblogs.com/cangqinglang/p/9001797.html