About think PHP deployment nginx configuration

不言
Release: 2023-03-24 22:26:02
Original
2740 people have browsed it

This article mainly introduces the nginx configuration of think PHP deployment, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

The first question:
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 17Warning: require(/mnt/wwwroot/admincc/thinkphp/start.php): failed to open stream: Operation not permitted in /mnt/wwwroot/admincc/public/index.php on line 17Fatal 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
Copy after login

This is the error message displayed after turning on the php error prompt (if the prompt is not turned on, the browser will only display a 500 error, which is not easy to troubleshoot.)

Solution:

This happens The error is mainly controlled by the open_basedir parameter in fastcgi.conf. In my configuration file, the default value of this parameter is as follows:

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
Copy after login

The function of the open_basedir parameter is to limit the files that PHP can open to a specific directory. In the tree, the default $document_root is the /home/wwwroot/default directory configured in nginx.conf, and the directory of my project is under /mnt/wwwroot/admincc/public. Since the project directory is not included in open_basedir, it will If the above error is reported, the solution is very simple, just add the project home directory.

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/mnt/wwwroot:$document_root/:/tmp/:/proc/";
Copy after login

PS: Another solution is to comment out this parameter directly.

Second question:

Error message:

scandir() has been disabled for security reasons
Copy after login

The error message is that the scandir function is disabled for security reasons.

Solution:

Yes, as it prompts, this function is disabled by default in 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
Copy after login

Obviously, scandir is disabled, and the solution is simple, just delete scandir and restart php-fpm.

service php-fpm restart
Copy after login
第三个问题:

访问报404错误。

解决办法:

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

location / {            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;                break;
            }
        }
Copy after login

由于ThinkPHP的入口文件是index.php,所以要重写下url。
保存配置,记得重启nginx。

相关推荐:

thinkphp部署到万网云服务器上报连接不上mysql

The above is the detailed content of About think PHP deployment nginx configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template