Mac上安装PHP、Apache、MySQL

时间:2024-01-09 16:56:56

Mac自带php5.6版本,要升级到php7.3 步骤如下

1,brew 安装php ,如果没有安装,访问https://brew.sh/index_zh-cn安装
在终端输入以下内容,不用指定安装php版本,会自动升级到最新版本,同时brew会自动update

brew install php

2,查看php版本

php -v

PHP 7.3.0 (cli) (built: Dec  7 2018 11:01:10) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies

with Zend OPcache v7.3.0, Copyright (c) 1999-2018, by Zend Technologies

Mac上自带了Apache

1,查看版本

sudo apachectl -v

Server version: Apache/2.4.33 (Unix)

Server built:   Apr  3 2018 17:54:07

//开启

 sudo apachectl start

//停止

sudo apachectl stop

//重启

sudo apachectl -k restart

3.Mac上安装mysql8

安装

brew install mysql
mysql -u root -p

但是又报错:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

依次执行

unset TMPDIR
bash mysql_install_db --verbose --user=root --basedir="$(brew --prefix mysql)"--datadir=/usr/local/var/mysql --tmpdir=/tmp
bash mysql.server start

登录修改root密码:

ALTER user 'root'@'localhost' IDENTIFIED BY ''

我这里初安装root密码为空,如果当前root用户authentication_string字段下有内容,先将其设置为空

mysql -uroot -p
use mysql;
update user set authentication_string='' where user='root'

到这里在命令行上操作没有问题了。使用navicat连接

Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image not found

依次执行:

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; #修改加密规则 
 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; #更新一下用户的密码 
FLUSH PRIVILEGES; #刷新权限 
alter user 'root'@'localhost' identified by '';

再次连接,success