Loading

MAC开发环境搭建(PHP 7.2 /5.6切换、xdebug)

1.brew安装:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

 /Library/WebServer/Documents  /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/var
/usr/local/opt
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/Cellar
/usr/local/Caskroom
/usr/local/Homebrew
/usr/local/Frameworks

Press RETURN to continue or any other key to abort

2.apache/php开启

sudo apachectl start

eg:
sudo apachectl restart|stop
httpd -v

测试:浏览器输入localhost,出现It Works字符串说明Apache已经成功启动了,一般Apache的默认根目录为:/Library/WebServer/Documents

开启自带PHP,只需添加Apache对PHP的支持就好了

sudo vim /etc/apache2/httpd.conf

去掉“LoadModule php7_module libexec/apache2/libphp7.so”注释符号,重启apache服务,再在/Library/WebServer/Documents编写php文件测试即可。

php 5.6安装和切换

安装php 5.6

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6

php 5.6会安装到/usr/local/php5/中,
用 /usr/local/php5/entropy-php.conf 中的LoadModule配置替换 httpd.conf中的配置

LoadModule php7_module libexec/apache2/libphp7.so 
LoadModule php5_module /usr/local/php5/libphp5.so

Include /private/etc/apache2/other/*.conf

根据(切换到/private/etc/apache2/other/,切换版本同时,切换响应的php配置文件):

重启apache,对错误文件排查:

sudo /usr/sbin/httpd -k start

3.利用brew安装mysql

brew install mysql
mysql.server start

初始化mysql配置

mysql_secure_installation

配置说明:

cometdeMacBook-Pro:~ comet$ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N   // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
Please set the password for root here.

New password:             // 设置密码

Re-enter new password:     // 再一次确认密码
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    // 移除不用密码的那个账户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n  //不接受root远程登录账号

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  //删除text数据库
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

一些问题:
mysql安装了最新8.0.11后,创建用户并授权后,授权的用户连接数据库(如通过phpmyadmin)时提示:

The server requested authentication method unknown to the client

这是主要新版的mysql的账号密码解锁机制和之前的不一致,导致phpmyadmin等访问错误。
解决办法:
删除创建的用户和授权,并找到mysql配置文件并加入:

default_authentication_plugin=mysql_native_password

变为原来的验证方式,然后从新创建用户并授权即可。

通过原来的密码验证方式修改用户密码:

mysql -uroot -p
 
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

4.安装redis

brew install redis

默认配置文件路径:usr/local/etc/redis.conf
启动redis命令:

redis-server /usr/local/etc/redis.conf

开机启动:

brew services start redis

修改redis.conf文件,设置redis密码:
GDTce120f@3l

5.Xdebug设置

通过phpinfo()信息查找php.ini路径,添加xdebug配置:

[Xdebug]
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so"
;自动跟踪,可关闭(关闭后提升性能)
xdebug.auto_trace=On
;性能分析,可关闭(关闭后提升性能)
xdebug.profiler_enable=On
xdebug.remote_enable=1
xdebug.remote_autostart = 1
xdebug.remote_host= localhost
xdebug.remote_port= 9000
xdebug.remote_handler = dbgp
xdebug.idekey = PHPSTORM

PHPStrom也设置相关配置:

  • 进入File>Settings>PHP>Debug,看到XDebug选项卡,port填9000,其他默认
  • 进入File>Settings>PHP>Debug>DBGp Proxy,IDE key 填 PHPSTORM,host 填localhost,port 填80

PHPStrom调试步骤:

  • 打断点,右上角类似电话的图标点击处于打开监听调试状态;
  • 在浏览器或postman输入需要访问的url地址;
  • 按F8进入下一步,F7进入函数内部,F9运行到下一个断点处;

Chrome浏览器配置Xdebug helper:
https://chrome.google.com/webstore/search/xdebug?hl=zh-CN

posted @ 2021-03-03 17:11  集君  阅读(272)  评论(0编辑  收藏  举报