Rootop 服务器运维与web架构

2023-07-20
发表者 Venus
Session cannot be started和Cannot modify header information警告已关闭评论

Session cannot be started和Cannot modify header information警告

代码:

[root@docker-server]# cat index.php

<?php
session_start();
header("by: aaa");

Warning: session_start(): Session cannot be started after headers have already been sent in D:\phpstudy_pro\WWW\pt\t.php on line 3
在调用session_start()前不能有任何输出,包括空格和空行,否则会报上面错。

Warning: Cannot modify header information – headers already sent by (output started at D:\phpstudy_pro\WWW\pt\t.php:1) in D:\phpstudy_pro\WWW\pt\t.php on line 4
在调用 header()前不能有任何输出,包括空格和空行,否则会报上面错。

2023-07-13
发表者 Venus
nginx加nextcloud重复跳转到登录页面已关闭评论

nginx加nextcloud重复跳转到登录页面

nextcloud文档中关于nginx的配置:https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html

原先环境为apache+php-fpm,现在将apache替换为nginx。

nginx和php运行用户已经修改为 www 用户(原先为apache)。

问题现象:
登录nextcloud又跳转回登录页面。

php-fpm是使用了remi源安装

网上说可能是session目录权限问题,根据此线索排查。
开始修改了php.ini

[root@localhost ~]# cat /etc/opt/remi/php73/php.ini | grep session.save_path | grep -Ev "^;|^$"
session.save_path = "/var/lib/php/session"

初始值是/tmp 目录,以为www用户没有权限写入,就改了个目录并赋予www用户权限,还是要重复登录。

查看www.conf配置文件发现这里的参数是另一个目录,这里的优先级高于php.ini,所以上面的改动是无效的。

[root@localhost ~]# cat /etc/opt/remi/php73/php-fpm.d/www.conf | grep session
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/opt/remi/php73/lib/php/session

将 /var/opt/remi/php73/lib/php/session 此目录属主属组改为www即可。或者指定其他目录并设置权限。

问题原因就是php运行用户www没有对此目录写入权限,就无法创建服务端的session文件。

2023-07-11
发表者 Venus
systemd管理服务启动已关闭评论

systemd管理服务启动

# 开机服务启动目录

/etc/systemd/system/multi-user.target.wants/

# 服务启动配置目录

/usr/lib/systemd/system/

/lib/systemd/system目录 等同于 /usr/lib/systemd/system目录,因为/lib 目录是 /usr/lib 目录的软连接

[root@web ~]# ll /lib
lrwxrwxrwx. 1 root root 7 May 24  2022 /lib -> usr/lib

# yum安装的nginx enable时,就是软连接启动文件到多用户启动目录下,类似之前的/etc/rc.local实现开机启动服务。

[root@web ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

# disable就是移除开机启动

[root@web ~]# systemctl disable nginx
Removed symlink /etc/systemd/system/multi-user.target.wants/nginx.service.

# ssh服务

[root@web ~]# ll /etc/systemd/system/multi-user.target.wants/sshd.service 
lrwxrwxrwx. 1 root root 36 May 24  2022 /etc/systemd/system/multi-user.target.wants/sshd.service -> /usr/lib/systemd/system/sshd.service

[root@web ~]# ll /usr/lib/systemd/system/sshd.service 
-rw-r--r-- 1 root root 373 Nov 24  2021 /usr/lib/systemd/system/sshd.service

# 将openresty创建服务,由systemctl控制启动

[Unit]
Description=nginx service
After=network.target

[Service]
Type=forking
ExecStartPre=/home/software/openresty/nginx/sbin/nginx -t
ExecStart=/home/software/openresty/nginx/sbin/nginx
ExecReload=/home/software/openresty/nginx/sbin/nginx -s reload
ExecStop=/home/software/openresty/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

很多 unit 文件中只有 ExecStart 命令,没有ExecStop、ExecReload命令也能实现关闭和重启

例如,关闭防火墙服务执行systemctl stop firewalld。

执行后,如果没有配置ExecStop,Systemd 默认将发送SIGTERM信号到主进程,并等待TimeoutStopSec配置的时间后查看进程是否已终止,如果没配置这个时间默认是90s。

90s以后,systemd 会检查进程有没有停止成功,如果还没停止,则 systemd 会发送SIGKILL信号来强杀进程完成该任务。
如果主进程 fork 了其他子进程,则 systemd 也会一并停止它们,因为它们都位于同一个 cgroup 中。

ExecStop=除非您有其他关闭服务的方法,否则您无需指示。

2023-07-10
发表者 Venus
var_dump()打印美化已关闭评论

var_dump()打印美化

# 安装xdebug模块
wget -c https://xdebug.org/files/xdebug-3.2.1.tgz
tar zxvf xdebug-3.2.1.tgz 
cd xdebug-3.2.1/
/usr/local/php/bin/phpize 
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

# 查看编译后的模块是否存在
ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20220829/
-rwxr-xr-x 1 root root 1978456 Jul 10 10:40 xdebug.so

# 开启模块
vi /usr/local/php/etc/php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20220829/"
zend_extension = xdebug.so

# 重启
service php-fpm restart