Nginx部署ThinkPHP时报错500问题
nginx配置文件fastcgi.conf
找到fastcgi_param PHP_ADMIN_VALUE
这个参数,在这个参数的字符串中加入路径
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/mnt/hgfs/phpworkspace/:站点部署路径";
nginx配置文件fastcgi.conf
找到fastcgi_param PHP_ADMIN_VALUE
这个参数,在这个参数的字符串中加入路径
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/mnt/hgfs/phpworkspace/:站点部署路径";
thinkphp使用pgsql驱动时需导入vendor\topthink\think-orm\src\db\connector\pgsql.sql
,因postgresql 12+版本已移除pg_attrdef.adsrc
导致报错。
解决方式:
将pgsql.sql
中的pg_attrdef.adsrc
替换为pg_get_expr(pg_attrdef.adbin, pg_attribute.attrelid)
whereOr与where同时使用时,需使用闭包模式,避免sql语句错误。
$user = Db::name('user')->where('uuid', $where['uuid'])->find();
if($user['phone'] && $user['card_id']){
$map1 = [['phone', '=', $user['phone']]];
$map2 = [['card_id', '=', $user['card_id']]];
$model = $model->where(function ($query) use ($map1, $map2) {
$query->whereOr([$map1, $map2]);
});
}elseif($user['card_id']){
$model = $model->where('card_id', $user['card_id']);
}elseif($user['phone']){
$model = $model->where('phone', $user['phone']);
}else{
$model = $model->where('id', 0);
}
由于某些特殊原因,可能需要将thinkphp系统安装到二级目录中,可参考以下操作(仅供参考):
网站目录:/www/wwwroot/website
运行目录:/subdir/public
伪静态:
location ~ .*\.(txt|TXT|gif|GIF|jpg|JPG|jpeg|JPEG|png|PNG|bmp|BMP|swf|SWF|css|CSS|js|JS|ico|ICO|doc|DOC|xls|XLS|xlsx|XLSX|docx|DOCX|json|JSON|woff2|WOFF2|woff|WOFF|ttf|TTF|pdf|PDF|zip|ZIP|rar|RAR|7z|7Z|svg|cur|map|properties|bcmap|htm|gz|log)$
{
valid_referers xxx.cn *.yyy.cn;
if ($invalid_referer){
return 404;
}
rewrite ^/subdir/(.*)$ /$1 last; break;
}
set $flag "";
location /subdir/ {
index index.php;
if ($request_uri ~* (get_file|get_auth_file|download|auth_download)){
set $flag "${flag}1";
}
if ($http_referer !~* (xxx|yyy)){
set $flag "${flag}1";
}
if ($flag = '11'){
return 404;
}
if (!-e $request_filename){
rewrite ^/subdir/(.*)$ /index.php?s=$1 last; break;
}
}
Nginx配置:root /www/wwwroot/website/subdir/public;
ThinkPHP源码修改以支持二级目录访问
helper.php
中url
方法默认domain
参数为:trueUrl.php
中parseDomain
方法返回值为:return $scheme . $domain .'/subdir'
Route::buildUrl($data['avatar'])->suffix(false)->domain(true)->build();
THINKPHP5开发API接口路由容易影响后台管理系统访问,需在route.php中使用路由变量规则定义API路由Route::pattern('ver','^v\d+');
此时定义API路由Route::get(':ver/version', "api/common/get_version");
$page->rollPage=xxx;
function fix_pre($str, $fix='0', $len=2, $type=STR_PAD_LEFT){
$str = str_pad($str, $len, $fix, $type);
return $str;
}
{:fix_pre($seats['seats'], '0', 3)}
ThinkPHP的模板主题机制,如果只是在PC,只要需修改 DEFAULT_THEME
(新版模板主题默认是空,表示不启用模板主题功能)配置项就可以方便的实现多模板主题切换。
但对于移动端和PC端,也许你会设计完全不同的主题风格,且针对不同的来路提供不同的渲染方式,其中一种比较流行的方法是“响应式设计”,但就本人经
历而言,要实现完全的“响应式设计”并不是那么容易,且解决兼容问题也是个难题,假设是大型站点,比如:淘宝、百度、拍拍这些,响应式设计肯定是满足不了
需求的,而是需要针对手机访问用户提供单独的手机网站。 ThinkPHP
完全可以实现,而且相当简单。和TPM的智能模版切换引擎一样,只要对来路进行判断处理即可。