Mac系统下搭建PHP环境

Mac OS 10.12.1 自带Apache,Nginx和PHP

1.运行Apache

  • 查看Apache版本,在终端根目录输入如下命令:

    sudo apachectl -v
  • 终端会输出Apache的版本及built时间

    Server version: Apache/2.4.23 (Unix)
    Server built:   Aug  8 2016 16:31:34
  • 开启Apache

    sudo apachectl start

    开启后,可以通过浏览器访问localhost,页面显示“It works” 表示已经成功。

  • 关闭Apache

    sudo apachectl stop
  • 重启Apache

    sudo apachectl restart

2.配置PHP

  • 编辑Apache的配置文件,终端输入:

    sudo vi /etc/apache2/httpd.conf

    找到:

    #LoadModule php5_module libexec/apache2/libphp5.so

    去掉前面的“#”号注释,然后 :wq 保存退出即可

  • 复制一份php.ini.default并将其命名为php.ini即可

    sudo cp /etc/php.ini.default /etc/php.ini
  • 重启Apache,使其生效

    sudo apachectl restart

3.安装MySQL

  • 下载MySQL:http://dev.mysql.com/downloads/mysql/ 下载后双击安装,成功之后,会弹出提示框:

    2017-02-12T09:00:08.587153Z 1 [Note] A temporary password is generated for root@localhost: s;QVTg#=i7wP
    If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.

    这个临时密码不好记,可以把它改掉。

  • 以安全模式启动MySQL,并且跳过安全密码,终端输入如下命令:

    sudo mysqld_safe --skip-grant-tables &
  • 修改MySQL密码:

    原理是修改database:mysql 的table:user 中的User字段为root的密码,5.7版本的mysql的密码字段是authentication_string,低版本的叫password;

    update user set authentication_string=PASSWORD("your password") where User="root";
  • 刷新权限,退出重启:

    MySQL> flush privileges;
    MySQL> quit;
    终端:service mysql start

    密码修改完成,已经将密码修改为root了。

  • 打开系统偏好配置最下面那一行->MySQL,

    开启MySQL:Start MySQL Server
    关闭MySQL:Stop MySQL Server

    注意:Automatically Start MySQL Server On Startup是默认勾选的,勾选后打开电脑会默认开启MySQL,建议不需要的可以不用默认勾选

  • 嫌终端查看数据库不方便的,可以下载Navicat Lite管理软件,管理MySQL超级方便。

或者:

MAMPhttps://www.mamp.info/en/

一个帮助搭建php环境的工具 

原文:http://blog.csdn.net/cgema/article/details/72457985

参考:https://www.jianshu.com/p/f4fd87fea61c

原文地址:https://www.cnblogs.com/Dengxiaobo/p/8087785.html