Loading... ## 安装brew 执行命令,等待安装成功。可能需要科学上网 ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" ``` ## 安装php 这里我们以安装`php7.2`为例,执行 ```bash brew search php ``` 查看可供安装的php版本。然后执行 ```bash brew install php@7.2 ``` 等待安装。其中可能会报错`php@7.2 has been disabled because it is deprecated upstream!`,这是因为php7.2不再有安全更新了,homebrew不提供安装。所以,我们执行 ```bash brew install shivammathur/php/php@7.2 ``` 来安装php7.2。耐心等待安装完毕即可。最后,我们需要将php添加到环境变量中。在安装完php之后,有如下提示 ```bash If you need to have php@7.2 first in your PATH, run: echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc ``` 所以,我们只需要运行下方的命令即可 ```bash export PATH="/usr/local/opt/php@7.2/bin:$PATH" >> ~/.zshrc export PATH="/usr/local/opt/php@7.2/sbin:$PATH" >> ~/.zshrc ``` ### 关键文件路径 php.ini ```bash /usr/local/etc/php/7.2/ ``` php安装路径 ```bash /usr/local/opt/php@7.2 ``` ## 安装nginx 执行命令,等待安装完成即可 ```bash brew install nginx ``` 这里安装的nginx是没有配置php fastcgi的,所以我们需要手动配置 打开nginx.conf文件,将下方的配置取消注释即可 ```nginx server { #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # include fastcgi_params; #} } ``` ```nginx server { location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` ### 关键文件路径 nginx.conf ```bash /usr/local/etc/nginx/nginx.conf ``` servers ``` /usr/local/etc/nginx/nginx.conf/servers ``` ## 安装redis 执行命令,等待安装完成即可 ```bash brew install redis ``` ## 安装php redis扩展 - ### 进入php的安装路径下的bin目录 ```bash cd /usr/local/opt/php@7.2/bin ``` - ### 下载phpredis ```bash git clone https://github.com/nicolasff/phpredis.git ``` - ### 进入phpredis文件夹 ```bash cd /usr/local/opt/php@7.2/bin/phpredis ``` - ### 使用 phpize 命令编译生成 configure 配置文件 ```bash /usr/local/opt/php@7.2/bin/phpize --with-php-config=/usr/local/opt/php@7.2/bin/php-config ``` - ### 配置 phpredis 命令 执行完上一步的命令,会在当前文件夹生成一个configure文件,继续执行 ```bash ./configure --with-php-config=/usr/local/opt/php@7.2/bin/php-config ``` - ### 编译安装 ```bash make && make install ``` - ### 给php添加扩展 打开php.ini文件,添加 ```ini extension = redis.so ``` 最后修改:2022 年 05 月 09 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 4 如果觉得我的文章对你有用,请随意赞赏
1 条评论