我已经安装了 apache、php-fpm 和 mod_fcgid,并尝试写入文件。
我已经创建了 PHP 池,这是配置文件:
[test.internal.innovisage.com]
...
user = test
group = test
...
listen.owner = test
listen.group = test
...
listen = /run/php-fpm/test.internal.innovisage.com.sock
这是我的 Apache 配置文件:
<Directory /var/www/html/test.internal.innovisage.com/public_html>
Require all granted
</Directory>
<virtualhost *:80>
ServerName test.internal.innovisage.com
ServerAlias test.internal.innovisage.com
DocumentRoot /var/www/test.internal.innovisage.com/public_html
ErrorLog /var/log/httpd/test.internal.innovisage.com-error.log
CustomLog /var/log/httpd/test.internal.innovisage.com-access.log combined
DirectoryIndex index.php
<IfModule mod_fcgid.c>
Options +ExecCGI
FcgidConnectTimeout 20
AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php
Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
ProxyPassMatch " ^/(.*\.php(/.*)?)$" "unix:/run/php-fpm/example.com.sock|fcgi://localhost/var/www/html/example.com/public_html/"
</IfModule>
</virtualhost>
以下是池列表:
[root@almalinux-8 test]# ps aux | grep test.intern
test 2814 0.0 0.3 425492 12344 ? S 18:06 0:00 php-fpm: pool test.internal.innovisage.com
test 2815 0.0 0.3 425492 12344 ? S 18:06 0:00 php-fpm: pool test.internal.innovisage.com
test 2816 0.0 0.3 425492 12344 ? S 18:06 0:00 php-fpm: pool test.internal.innovisage.com
test 2817 0.0 0.3 425492 12344 ? S 18:06 0:00 php-fpm: pool test.internal.innovisage.com
test 2818 0.0 0.3 425492 12344 ? S 18:06 0:00 php-fpm: pool test.internal.innovisage.com
它说脚本所有者是测试。
<?php
echo "<p>Current User ID: ".getmyuid()."</p>";
echo "<p>Current Script Owner: ".get_current_user()."</p>";
phpinfo();
?>
当运行脚本时测试用户从命令行,它写入文件。但是,当从 Web 浏览器运行时,它不会创建该文件。
我还需要更改什么才能将脚本写入文件吗?
答案1
我错过了在这里修改这一行。
ProxyPassMatch " ^/(..php(/.)?)$" "unix:/run/php-fpm/example.com.sock|fcgi://localhost/var/www/html/example.com/public_html/"
将其替换为正确的域,我现在可以将文件写入所有允许的位置。
ProxyPassMatch " ^/(..php(/.)?)$" "unix:/run/php-fpm/test.internal.innovisage.com.sock|fcgi://localhost/var/www/test.internal.innovisage.com/public_html/"