thinkphp6已确认兼容php8.2版本:ThinkPHP6.1.2版本发布——兼容PHP8.2 · ThinkPHP
一、gitee创建仓库
1、打开Gitee - 基于 Git 的代码托管和研发协作平台网站
2、右上角新建仓库
3、填写仓库信息,空仓库即可,因为thinkphp会生成.gitignore和README.md防止等下冲突
4、点击创建后,复制
二、电脑本地安装thinkphp6最新稳定版
#安装thinkphp命令,tp6test.com是你项目的名称,可以按实际情况修改
composer create-project "topthink/think:^6.1" tp6test.com
#进入项目目录
cd tp6test.com
#查看安装的thinkphp版本,会发现输出了version 6.1.4
php think -v
#初始化git(让这个文件夹变成能被 Git 管理的项目)
git init
#给本地项目,绑定一个远程仓库地址(也就是在码云上创建的仓库)
git remote add origin https://gitee.com/laocaibulao/tp6test.com.git
#把项目所有文件添加到 Git 暂存区(. 表示当前目录所有文件)
git add .
#提交暂存区文件到本地仓库,备注提交信息(比如“初始化项目”)
git commit -m "初始化项目"
#推送到 Gitee 仓库(首次推送需加 -u 关联分支,后续推送直接 git push 即可)
git push -u origin master
推送成功后 在Gitee - 基于 Git 的代码托管和研发协作平台 就能看到仓库里面已经有代码了
三、nginx配置thinkphp6的域名
1、编辑/etc/hosts 填入本地域名127.0.0.1 www.tp6test.com
2、配置nginx:
1、如果忘记nginx装哪里,可以用命令:brew info nginx找到
例如,我的目录在cd /usr/local/etc/nginx/servers/
2、忘记电脑有哪个版本PHP,可以用命令:brew list | grep php
3、需要查看PHP8.2的端口号是多少,例如我的:cat /usr/local/etc/php/8.2/php-fpm.d/www.conf
listen = 127.0.0.1:9000 可以看到PHP-FPM 正在本机的 9000 端口等待 Nginx 发来的请求。
server {
listen 80;
server_name www.tp6test.com;
root /Users/boolean/myphp/online/tp6test.com/public;
index index.php index.html;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
# 2. 禁止访问敏感目录(安全防护)
location ~ ^/(app|application|config|runtime|extend|vendor)/ {
deny all; # 直接拒绝访问
return 403;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#
location ~ \.php$ {
root /Users/boolean/myphp/online/tp6test.com/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 传递 PATH_INFO 给 ThinkPHP(必须配置)
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
3、重启
重启PHP8.2(如果没改配置不用这步):brew services restart php@8.2
重启nginx:sudo nginx -s reload