SYSTEM INFORMATION:
OS type and version: Ubuntu Linux 20.04.4
Webmin version: 1.991
Virtualmin version: 7.0-4
When executing a file_put_contents
inside a php script to save a test file, it is always created with user and group assigned to www-data instead of the domain’s owner
The PHP script execution mode is FCGId
I’ve commented out the SetHandler
lines in the php .conf files relative to cgi configuration (is it necessary to do the same in the fpm ones?):
grep SetHandler etc/apache2/conf-available/php*.*
etc/apache2/conf-available/php7.4-cgi.conf:# SetHandler application/x-httpd-php
etc/apache2/conf-available/php7.4-cgi.conf:# SetHandler application/x-httpd-php-source
etc/apache2/conf-available/php7.4-fpm.conf: SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
etc/apache2/conf-available/php7.4-fpm.conf:# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
etc/apache2/conf-available/php8.0-cgi.conf:# SetHandler application/x-httpd-php
etc/apache2/conf-available/php8.0-cgi.conf:# SetHandler application/x-httpd-php-source
etc/apache2/conf-available/php8.0-fpm.conf: SetHandler "proxy:unix:/run/php/php8.0-fpm.sock|fcgi://localhost"
etc/apache2/conf-available/php8.0-fpm.conf:# SetHandler "proxy:unix:/run/php/php8.0-fpm.sock|fcgi://localhost"
etc/apache2/conf-available/php8.1-cgi.conf:# SetHandler application/x-httpd-php
etc/apache2/conf-available/php8.1-cgi.conf:# SetHandler application/x-httpd-php-source
etc/apache2/conf-available/php8.1-fpm.conf: SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
etc/apache2/conf-available/php8.1-fpm.conf:# SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
This is my virtual server configuration (i’ve removed my actual IP and replaced my domain with fakedomain.com
). The #1002
parameter of SuexecUserGroup
is the correct ID of the user and group of the domain’s owner:
cat /etc/apache2/sites-available/fakedomain.com.conf
<VirtualHost [my actual ip]:80>
SuexecUserGroup "#1002" "#1002"
ServerName fakedomain.com
ServerAlias www.fakedomain.com
ServerAlias mail.fakedomain.com
ServerAlias webmail.fakedomain.com
ServerAlias admin.fakedomain.com
DocumentRoot /home/fakedomain/public_html/public
ErrorLog /var/log/virtualmin/fakedomain.com_error_log
CustomLog /var/log/virtualmin/fakedomain.com_access_log combined
ScriptAlias /cgi-bin/ /home/fakedomain/cgi-bin/
DirectoryIndex index.php index.php4 index.php5 index.htm index.html
<Directory /home/fakedomain/public_html/public>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php7.4
AddHandler fcgid-script .php8.0
AddHandler fcgid-script .php8.1
FCGIWrapper /home/fakedomain/fcgi-bin/php8.0.fcgi .php
FCGIWrapper /home/fakedomain/fcgi-bin/php7.4.fcgi .php7.4
FCGIWrapper /home/fakedomain/fcgi-bin/php8.0.fcgi .php8.0
FCGIWrapper /home/fakedomain/fcgi-bin/php8.1.fcgi .php8.1
</Directory>
<Directory /home/fakedomain/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.fakedomain.com
RewriteRule ^(?!/.well-known)(.*) https://fakedomain.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.fakedomain.com
RewriteRule ^(?!/.well-known)(.*) https://fakedomain.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php7.4
RemoveHandler .php8.0
RemoveHandler .php8.1
RedirectMatch 301 ^/(?!.well-known)(.*)$ https://fakedomain.com/$1
IPCCommTimeout 41
FcgidMaxRequestLen 1073741824
</VirtualHost>
<VirtualHost [my actual ip]:443>
SuexecUserGroup "#1002" "#1002"
ServerName fakedomain.com
ServerAlias www.fakedomain.com
ServerAlias mail.fakedomain.com
ServerAlias webmail.fakedomain.com
ServerAlias admin.fakedomain.com
DocumentRoot /home/fakedomain/public_html/public
#LogLevel alert rewrite:trace6
ErrorLog /var/log/virtualmin/fakedomain.com_error_log
CustomLog /var/log/virtualmin/fakedomain.com_access_log combined
ScriptAlias /cgi-bin/ /home/fakedomain/cgi-bin/
DirectoryIndex index.php index.php4 index.php5 index.htm index.html
<Directory /home/fakedomain/public_html/public>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php7.4
AddHandler fcgid-script .php8.0
AddHandler fcgid-script .php8.1
FCGIWrapper /home/fakedomain/fcgi-bin/php8.0.fcgi .php
FCGIWrapper /home/fakedomain/fcgi-bin/php7.4.fcgi .php7.4
FCGIWrapper /home/fakedomain/fcgi-bin/php8.0.fcgi .php8.0
FCGIWrapper /home/fakedomain/fcgi-bin/php8.1.fcgi .php8.1
</Directory>
<Directory /home/fakedomain/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^/(.*) https://fakedomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} =webmail.fakedomain.com
RewriteRule ^(?!/.well-known)(.*) https://fakedomain.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.fakedomain.com
RewriteRule ^(?!/.well-known)(.*) https://fakedomain.com:10000/ [R]
# Any other non canonical domain? -> Redirect to canonical
#RewriteCond %{HTTP_HOST} !=fakedomain.com
#RewriteRule ^/?(.*) https://fakedomain.com/$1 [R=301,L]
RemoveHandler .php
RemoveHandler .php7.4
RemoveHandler .php8.0
RemoveHandler .php8.1
SSLEngine on
SSLCertificateFile /home/fakedomain/ssl.cert
SSLCertificateKeyFile /home/fakedomain/ssl.key
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCACertificateFile /home/fakedomain/ssl.ca
IPCCommTimeout 41
FcgidMaxRequestLen 1073741824
</VirtualHost>
Any help will be appreciated, thanks