AH01071: Got error ‘Primary script unknown

Apache2debian-jessiephp-fpmvirtualmin

Debian Linux 8.10, Apache version 2.4.10, FPM/FastCGI.

I have created a 1st virtual host. After hours, I could get it working.
Then I have created another virtual host, with almost the same config => I get a "File not found." in the browser and a 404.

Look to Apache Error LOG:

AH01071: Got error 'Primary script unknown' 

I have compared the configurations files, side by side, with the vhost that works and I do not see major differences.

/etc/php5/fpm/pool.d/152…….94.conf

[152........94]
user = vhostthatNOTworks
group = vhostthatNOTworks
listen = 8002
pm = dynamic
pm.max_children = 9999
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 5
php_admin_value[upload_tmp_dir] = /home/vhostthatNOTworks/tmp
php_admin_value[session.save_path] = /home/vhostthatNOTworks/tmp

Except, on the working vhost: listen = 8000

On the bad vhsot: listen = 8002

This value has been set by virtualmin. I don't know why there is a difference, and if it has an importance?

/etc/apache2/apache2.conf (comments removed):

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

.conf of vhost that works:

<VirtualHost 188.165.53.208:80>
SuexecUserGroup vhostthatworks vhostthatworks
ServerName vhostthatworks.fr
ServerAlias www.vhostthatworks.fr
ServerAlias webmail.vhostthatworks.fr
ServerAlias admin.vhostthatworks.fr
DocumentRoot /home/spip31/public_html
ErrorLog /var/log/virtualmin/vhostthatworks.fr_error_log
CustomLog /var/log/virtualmin/vhostthatworks.fr_access_log combined
ScriptAlias /cgi-bin/ /home/vhostthatworks/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/spip31/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddType application/x-httpd-php .php
</Directory>
<Directory /home/vhostthatworks/cgi-bin>
allow from all
AllowOverride All         Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.vhostthatworks.fr
RewriteRule ^(.*) https://vhostthatworks.fr:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.vhostthatworks.fr
RewriteRule ^(.*) https://vhostthatworks.fr:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
<FilesMatch \.php$>
SetHandler proxy:fcgi://localhost:8000
</FilesMatch>
</VirtualHost>
<VirtualHost 188.165.53.208:443>
SuexecUserGroup vhostthatworks vhostthatworks
ServerName vhostthatworks.fr
ServerAlias www.vhostthatworks.fr
ServerAlias webmail.vhostthatworks.fr
ServerAlias admin.vhostthatworks.fr
DocumentRoot /home/spip31/public_html
ErrorLog /var/log/virtualmin/vhostthatworks.fr_error_log
CustomLog /var/log/virtualmin/vhostthatworks.fr_access_log combined
ScriptAlias /cgi-bin/ /home/vhostthatworks/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/spip31/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
</Directory>
<Directory /home/vhostthatworks/cgi-bin>
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.vhostthatworks.fr
RewriteRule ^(.*) https://vhostthatworks.fr:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.vhostthatworks.fr
RewriteRule ^(.*) https://vhostthatworks.fr:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
SSLEngine on
SSLCertificateFile /home/bilp/SSL/domain.crt
SSLCertificateKeyFile /home/bilp/SSL/domain.key
SSLCertificateChainFile /home/bilp/SSL/intermediate.pem
SSLCACertificateFile /home/bilp/SSL/root.cer
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
<Directory /home/vhostthatworks/public_html>
Options +Indexes +IncludesNOEXEC +SymLinksifOwnerMatch +ExecCGI
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddType application/x-httpd-php .php
</Directory>
<FilesMatch \.php$>
SetHandler proxy:fcgi://localhost:8000
</FilesMatch>
</VirtualHost>

.conf of vhost that does NOT work:

<VirtualHost *:80>
SuexecUserGroup "#1003" "#1003"
ServerName vhostthatNOTworks.fr
ServerAlias www.vhostthatNOTworks.fr
ServerAlias webmail.vhostthatNOTworks.fr
ServerAlias admin.vhostthatNOTworks.fr
DocumentRoot /home/spip31/public_html
ErrorLog /var/log/virtualmin/vhostthatNOTworks.fr_error_log
CustomLog /var/log/virtualmin/vhostthatNOTworks.fr_access_log combined
ScriptAlias /cgi-bin/ /home/vhostthatNOTworks/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/spip31/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
</Directory>
<Directory /home/vhostthatNOTworks/cgi-bin>
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.vhostthatNOTworks.fr
RewriteRule ^(.*) https://vhostthatNOTworks.fr:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.vhostthatNOTworks.fr
RewriteRule ^(.*) https://vhostthatNOTworks.fr:10000/ [R]
AddType application/x-httpd-php .php
AddType application/x-httpd-php5.6 .php5.6
<Directory /home/vhostthatNOTworks/public_html>
Options +Indexes +SymLinksifOwnerMatch +ExecCGI
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddType application/x-httpd-php .php
</Directory>
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
<FilesMatch \.php$>
SetHandler proxy:fcgi://localhost:8002
</FilesMatch>
</VirtualHost>
<VirtualHost 188.165.253.141:443>
SuexecUserGroup "#1003" "#1003"
ServerName vhostthatNOTworks.fr
ServerAlias www.vhostthatNOTworks.fr
ServerAlias webmail.vhostthatNOTworks.fr
ServerAlias admin.vhostthatNOTworks.fr
DocumentRoot /home/spip31/public_html
ErrorLog /var/log/virtualmin/vhostthatNOTworks.fr_error_log
CustomLog /var/log/virtualmin/vhostthatNOTworks.fr_access_log combined
ScriptAlias /cgi-bin/ /home/vhostthatNOTworks/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/spip31/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
</Directory>
<Directory /home/vhostthatNOTworks/cgi-bin>
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.vhostthatNOTworks.fr
RewriteRule ^(.*) https://vhostthatNOTworks.fr:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.vhostthatNOTworks.fr
RewriteRule ^(.*) https://vhostthatNOTworks.fr:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
SSLEngine on
SSLCertificateFile /home/bilp/SSL/domain.crt
SSLCertificateKeyFile /home/bilp/SSL/domain.key
SSLCertificateChainFile /home/bilp/SSL/intermediate.pem
SSLCACertificateFile /home/bilp/SSL/root.cer
<Directory /home/gloriette_bilp/public_html>
Options +Indexes +IncludesNOEXEC +SymLinksifOwnerMatch +ExecCGI
allow from all
AllowOverride All     Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddType application/x-httpd-php .php
</Directory>
<FilesMatch \.php$>
SetHandler proxy:fcgi://localhost:8002
</FilesMatch>
</VirtualHost>

Apparently, PHP-FPM does listen to the ports (8000 for vhostthatNOTworks and 8002 for vhostthatNOTworks):
netstat -ltnp

tcp        0      0 0.0.0.0:8001            0.0.0.0:*               LISTEN      2308/php-fpm.conf)
tcp        0      0 0.0.0.0:8002            0.0.0.0:*               LISTEN      2308/php-fpm.conf)

Can someone help me?

Best Answer

This is silly. I think this error is rather related to Virtualmin than Apache2. A reboot was all I needed. Apache2 restart didn't work. Should be something about the way Virtualmin handle Apache2.

Source: [Solved] AH01071: Got error 'Primary script unknown\n'