You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu+Nextcloud环境下非root用户运行PHP触发段错误求助

问题:启用缓存后非root用户运行PHP程序触发段错误

我配置了一台搭载Ubuntu-22.04、Nextcloud-24.0.4、Apache-2.4.52和php-8.1.2的服务器,除www-data用户启动的后台任务外,其余功能均正常。启用缓存后,非root用户运行PHP程序会立即触发Segmentation fault(段错误)。我已排查日志、修改php.ini(如memory_limit、apc.enable_cli等)及Nextcloud的config.php,但问题仍未解决。


加载的Apache和PHP模块信息

Apache模块

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 headers_module (shared)
 http2_module (shared)
 mime_module (shared)
 mpm_event_module (shared)
 negotiation_module (shared)
 proxy_module (shared)
 proxy_fcgi_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)

PHP模块

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
imagick
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

更新:核心转储信息及分析请求

GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/php8.1...
(No debugging symbols found in /usr/bin/php8.1)
[New LWP 85430]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `php -f /var/www/nextcloud/cron.php'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f8e5c2dacfb in _IO_new_fclose (fp=0x0) at ./libio/iofclose.c:48
48  ./libio/iofclose.c: No such file or directory.
(gdb) bt
#0  0x00007f8e5c2dacfb in _IO_new_fclose (fp=0x0) at ./libio/iofclose.c:48
#1  0x00005621ae81ee00 in ?? ()
#2  0x00005621ae74ec9c in ?? ()
#3  0x00005621ae747dea in php_module_startup ()
#4  0x00005621ae8939f1 in ?? ()
#5  0x00005621ae5f2559 in ?? ()
#6  0x00007f8e5c285d90 in __libc_start_call_main (main=main@entry=0x5621ae5f23d0, argc=argc@entry=3,
    argv=argv@entry=0x7ffedd005dd8) at ../sysdeps/nptl/libc_start_call_main.h:58
#7  0x00007f8e5c285e40 in __libc_start_main_impl (main=0x5621ae5f23d0, argc=3, argv=0x7ffedd005dd8, init=<optimized out>,
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffedd005dc8) at ../csu/libc-start.c:392
#8  0x00005621ae5f2915 in _start ()

分析建议

从核心转储来看,段错误发生在_IO_new_fclose(fp=0x0)——即尝试关闭一个空指针指向的文件流,问题出现在php_module_startup()阶段,结合"启用缓存后非root用户触发"的前提,重点排查以下方向:

  • OPcache权限问题:检查Zend OPcache缓存目录(默认/var/cache/php/opcache)的权限,非root用户需具备读写权限:

    ls -ld /var/cache/php/opcache
    # 若权限错误,执行以下命令修复
    chown -R www-data:www-data /var/cache/php/opcache
    chmod -R 750 /var/cache/php/opcache
    
  • OPcache配置冲突:检查php.ini或/etc/php/8.1/cli/conf.d/*opcache.ini中的关键参数:

    • 确保opcache.enable_cli = 1(CLI模式启用OPcache)
    • 若指定了opcache.file_cache,确认目录存在且权限正确
    • 避免opcache.memory_consumption、opcache.max_accelerated_files设置过大导致内存溢出
  • 扩展兼容性排查:临时禁用igbinary、redis、imagick等第三方扩展(重命名对应.ini文件),逐步测试非root用户运行PHP是否正常,定位冲突扩展。

  • 文件系统权限修复:确保Nextcloud目录及PHP相关文件权限正确:

    chown -R www-data:www-data /var/www/nextcloud
    find /var/www/nextcloud -type d -exec chmod 750 {} \;
    find /var/www/nextcloud -type f -exec chmod 640 {} \;
    
  • 重装PHP修复损坏包:若以上方法无效,可能是PHP安装包损坏,尝试重装:

    apt purge php8.1*
    apt autoremove
    apt install php8.1 php8.1-fpm php8.1-cli php8.1-common php8.1-opcache php8.1-redis php8.1-imagick php8.1-mysql php8.1-gd php8.1-intl php8.1-mbstring php8.1-xml php8.1-zip
    

内容的提问来源于stack exchange,提问作者franzu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 06:45:15