dsfsfs 发表于 2018-12-12 14:07:09

记一次php项目上线遇到的坑

  最近上线了一个项目的后台程序(基于ThinkPHP),期间遇到了不少坑,特此记录。
1,系统环境:CentOS Linux release 7.4.1708 (Core) 内核版本:3.10.0-693.el7.x86_64
2,软件环境 nginx-1.12.0,PHP-5.5.38,MySQL-5.5.56

第一个坑:

Warning: require(): open_basedir restriction in effect. File(/mnt/wwwroot/admincc/thinkphp/start.php) is not within the allowed path(s): (/mnt/wwwroot/admincc/public/:/tmp/:/proc/) in /mnt/wwwroot/admincc/public/index.php on line 17
Warning: require(/mnt/wwwroot/admincc/thinkphp/start.php): failed to open stream: Operation not permitted in /mnt/wwwroot/admincc/public/index.php on line 17
Fatal error: require(): Failed opening required '/mnt/wwwroot/admincc/public/../thinkphp/start.php' (include_path='.:/usr/local/php/lib/php') in /mnt/wwwroot/admincc/public/index.php on line 17
  这个是打开php错误提示后显示的错误信息(如果不打开提示,浏览器只会显示500错误,不便于排查。)

解决办法:
  出现这种错误主要受fastcgi.conf中open_basedir参数控制,在我的配置文件中,这个参数的默认值是这样的:

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
  open_basedir参数的作用就是将php能打开的文件限制在特定的目录树中,默认的$document_root是nginx.conf中配置的/home/wwwroot/default目录,而我项目的目录是在/mnt/wwwroot/admincc/public下,由于项目目录没有包含在open_basedir中,因此会报如上的错,解决方法也就很简单了,将项目家目录加入即可。

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/mnt/wwwroot:$document_root/:/tmp/:/proc/";
  PS:还有一种解决方法是直接把这个参数注释掉。

第二个坑:
  错误提示:

scandir() has been disabled for security reasons
  好不容易过了第一关,又卡在了这,不过没关系,出了问题就要解决啊。错误提示是说scandir函数因为安全原因被禁用了。

解决办法:
  没错,就像它提示的这个函数默认在php.ini中是禁用的。

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
  很明显,scandir被禁用了,解决方法也简单,把scandir去掉,重启php-fpm就好。

service php-fpm restart
第三个坑:
  走到这按说应该可以了,但是重启之后访问却报404错误。

解决办法:
  这个的原因在于nginx的配置有问题,在vhost/admincc.conf(站点虚拟主机的配置文件)中添加如下配置即可:

location / {
if (!-e $request_filename) {
rewrite^(.*)$/index.php?s=/$1last;
break;
}
}
  由于ThinkPHP的入口文件是index.php,所以要重写下url。
保存配置,重启nginx,再刷新,终于大功告成。
通过这次项目上线,感觉对php项目的理解又进了一步,哈哈,继续加油!



页: [1]
查看完整版本: 记一次php项目上线遇到的坑