mac 安装 php 与 hyperf 框架依赖的扩展并启动 gptlink 项目
短信预约 -IT技能 免费直播动态提醒
m系列 mac 安装 php 与 hyperf 框架依赖的扩展并启动 gptlink 项目
gptlink 项目是一个前后端一体化的 chatgpt 开源项目
gptlink 项目地址:https://github.com/gptlink/gptlink
安装 php 8.0 版本:
brew install php@8.0
安装完成后提示如下:
To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php_module /opt/homebrew/opt/php@8.0/lib/httpd/modules/libphp.so SetHandler application/x-httpd-php Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.htmlThe php.ini and php-fpm.ini file can be found in: /opt/homebrew/etc/php/8.0/php@8.0 is keg-only, which means it was not symlinked into /opt/homebrew,because this is an alternate version of another formula.If you need to have php@8.0 first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/php@8.0/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/opt/homebrew/opt/php@8.0/sbin:$PATH"' >> ~/.zshrcFor compilers to find php@8.0 you may need to set: export LDFLAGS="-L/opt/homebrew/opt/php@8.0/lib" export CPPFLAGS="-I/opt/homebrew/opt/php@8.0/include"To start php@8.0 now and restart at login: brew services start php@8.0Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/php@8.0/sbin/php-fpm --nodaemonize==> scrcpyAt runtime, adb must be accessible from your PATH.You can install adb from Homebrew Cask: brew install --cask android-platform-toolszsh completions have been installed to: /opt/homebrew/share/zsh/site-functions
根据如上提示在 ~/.zshrc 文件中添加下面环境变量配置:
export PATH="/opt/homebrew/opt/php@8.0/bin:$PATH"export PATH="/opt/homebrew/opt/php@8.0/sbin:$PATH"
添加完成后重启命令行执行 php -v 如下说明 php 安装成功:
➜ php -vPHP 8.0.29 (cli) (built: Jun 15 2023 05:07:53) ( NTS )Copyright (c) The PHP GroupZend Engine v4.0.29, Copyright (c) Zend Technologies with Zend OPcache v8.0.29, Copyright (c), by Zend Technologies
安装 composer 包管理工具:
(它是 php 的包管理工具用来安装项目的依赖)
curl -sS https://getcomposer.org/installer | phpsudo mv composer.phar /usr/local/bin/composercomposer update
执行 composer update 时提示如下没有安装 php 的 swoole 扩展:
96qbhy/hyperf-auth[v2.0,...v2.7.1]require e ext-swoole >=4.4 -it is missing from your systemTo enable extensions, verify that they are enabled in your .ini files: - /opt/homebrew/etc/php/8.0/php.ini - /opt/homebrew/etc/php/8.0/conf.d/ext-opcache.ini
安装 swoole 扩展和 redis 扩展:
pecl install swoolepecl install redis
安装 swoole 扩展时会提示报错如下:(找不到 “pcre2.h” 文件)
/opt/homebrew/Cellar/php@8.0/8.0.29_1/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found#include "pcre2.h"
解决方法创建 pcre2.h 软链接到 /usr/local/include 文件夹下:
// 1. 执行下面代码查看 pcre2 安装的路径找到 pcre2.h 文件的路径,我这里找到的是 /opt/homebrew/include/pcre2.h, 你可以看看有没有这个文件brew info pcre2// 2. 创建 /usr/local/include 文件夹sudo mkdir /usr/local/include// 3. 创建软链接sudo ln -s /opt/homebrew/include/pcre2.h /usr/local/include/// 4. 添加这个环境变量,安装 php swoole 扩展编译时候需要export C_INCLUDE_PATH=/usr/local/include// 5. 再次执行 pecl install swoole 一路回车就行
最终 /opt/homebrew/etc/php/8.0/php.ini 增加的配置如下:
extension="redis.so"extension="swoole.so"swoole.use_shortname=Off // 需要手动添加
最终 composer 更新与安装:
composer updatecomposer install
依赖安装成功后启动项目:
启动项目前需启动mysql和redis服务并在 gptserver 文件夹下创建 .env 文件内容如下:
APP_NAME=chatgpt-linkAPP_ENV=prod# 数据库 通过 docker 启动命令:docker run -d -p 3306:3306 --name mysql57 -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=gptlink mysql:5.7DB_HOST=192.168.30.19 # 你本机电脑的 ip 地址:命令行输入 ifconfig 查看 en0DB_PORT=3306DB_DATABASE=gptlinkDB_USERNAME=rootDB_PASSWORD=123456#redis 通过 docker 启动命令:docker run -d --name redis -p 6379:6379 redisREDIS_HOST=192.168.30.19REDIS_AUTH=(null)REDIS_PORT=6379# 管理员账号密码ADMIN_USERNAME=adminADMIN_PASSWORD=admin888ADMIN_TTL=7200
启动php后端服务:
cd gptlink/gptserver// 初始化数据库php ./hyperf migrate// 启动本地后端服务php ./hyperf start// 端口在 http://127.0.0.1:9503, 前后端设置 proxy 代理到该端口开发
来源地址:https://blog.csdn.net/qq_41614928/article/details/131931073
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341