2019最新的 Mac 下配置PHP运行环境

一、MAC自带apache

     1、终端查看当前版本  httpd -v

     2、配置文件与网站根目录默认所在位置 用command + shift + G  前往以下路径可以查看
           /etc/apache2/httpd.conf //配置文件
          /Library/WebServer/Documents //网站根目录

     3、服务基本操作
           sudo apachectl start // 开启Apache
           sudo apachectl stop // 关闭Apache
           sudo apachectl restart // 重启Apache

     4、一般把WebServer拖到这里方便以后使用

     2019最新的 Mac 下配置PHP运行环境

二、配置PHP

       1、编辑Apache配置文件,终端输入:sudo vi /etc/apache2/httpd.conf 找到#LoadModule php5_module libexec/apache2/libphp5.so,去掉#,键盘点击esc,然后写入并退出:wq

       2、复制一份php.ini.default命名 php.ini,以后就可以配置PHP了 终端输入sudo cp /etc/php.ini.default /etc/php.ini

       3、重启Apache,是其生效 终端输入sudo apachectl restart

       4、获取ThinkPHP http://www.thinkphp.cn/down.html

       5、将thinkphp_5 文件夹移到目录/Libirary/WebServer/Documents/。注意是在Documents目录里面的

       6、终端开启Apache sudo apachectl start

       7、打开浏览器访问 http://localhost/thinkphp_5/public/index.php ,发现无权限访问,回到终端cd /Libirary/WebServer/Documents/,然后执行ls -l 发现[email protected] 18 hanqing staff 612 3 25 16:35     thinkphp_5,果然没有权限 

       8、然后执行 chmod -R 755 thinkphp_5/   分配thinkphp_5文件夹755权限,回到浏览器刷新,可以访问了

三、创建第一个demoHello world!

       1、进入thinkphp_5的目录下,终端执行php think build --module demo 然后在thinkphp_5/application/下生成了demo项目

       2、修改thinkphp_5/application/demo/controller/index.php代码,return "hello world!";

       3、浏览器访问http://localhost/thinkphp_5/public/index.php/demo/index/index 就会发现返回的是hello world

四、安装部署phpMyAdmin

        1、官网上下一个phpMyAdmin. 链接为: https://www.phpmyadmin.net

        2、将下载下来的解压放在 /Library/WebServer/Documents/ 目录下,完整的目录   为:/Library/WebServer/Documents/phpmyadmin/,那么用命令行进入这个目录:cd /Library/WebServer/Documents/phpmyadmin/

       3、输入以下命令:

            cp config.sample.inc.php config.inc.php    //复制一份配置文件的模板

            vim config.inc.php    //进入到文件中

       4、进入文件后,按照下面进行修改:

            $cfg['blowfish_secret'] = '自己定字符串';         //用于Cookie加密,随意的长字符串

            $cfg['Servers'][$i]['host'] = '127.0.0.1';         //MySQL守护程序做了IP绑定

       5、接着我们就可以在浏览器中输入URL:http://localhost/phpmyadmin/

       6、打开页面后,输入用户名为:root,密码是MySQL的密码。

       7、如果出现以下界面登陆不了:

             mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
             mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
 

             2019最新的 Mac 下配置PHP运行环境

            解决方法:打开系统便好设置 -> MySQL -> instances -> initialize Database -> 输入root密码,选择第二项,点击OK。回到浏览器刷新就可以登陆了。