A virtualmin subdomain of a virtual server has a simple php file in it but it downloads instead of running

I'm not sure what info you want from me to get me educated on this problem, so I'll let you ask for it first. This subdomain worked when I was a Webmin only server.

Status: 
Active

Comments

Howdy -- do other websites on this particular server work as expected?

And if you look in Server Configuration -> PHP Options, what PHP version is it set to use?

WNYmathGuy's picture
Submitted by WNYmathGuy on Mon, 01/29/2018 - 18:42 Pro Licensee

It appears that they all do the same thing; main virtual servers and subdomains. I was going through this before when I was just experimenting a bit over a week ago and I switched the PHP script execution mode to Apache from FCGId. Miraculously the PHP pages would load instead of download. I felt like I was doing a "no-no" hack at the time. I want to do things the Virtualmin way now so as to not make diagnosing problems difficult in the future.

My Server Configuration -> PHP Versions says "Your system only has PHP version 7.0.22 installed, so selecting a different version for each directory is not possible."

My Server Configuration -> Website Options has PHP script execution mode set to FCGId

That all helps -- what is the output of this command:

find /etc/apache2 -type f | xargs grep -i sethandler

WNYmathGuy's picture
Submitted by WNYmathGuy on Tue, 01/30/2018 - 13:21 Pro Licensee

/etc/apache2/mods-available/info.conf: SetHandler server-info
/etc/apache2/mods-available/proxy_balancer.conf: #    SetHandler balancer-manager
/etc/apache2/mods-available/ldap.conf: SetHandler ldap-status
/etc/apache2/mods-available/status.conf: SetHandler server-status
/etc/apache2/mods-available/php7.0.conf:    SetHandler application/x-httpd-php
/etc/apache2/mods-available/php7.0.conf:    SetHandler application/x-httpd-php-source
/etc/apache2/conf-available/php7.0-cgi.conf:    SetHandler application/x-httpd-php
/etc/apache2/conf-available/php7.0-cgi.conf:    SetHandler application/x-httpd-php-source
/etc/apache2/conf-available/php7.0-fpm.conf:        SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
/etc/apache2/conf-available/localized-error-pages.conf:#   SetHandler directive in a <Location /> context somewhere. Adding
/etc/apache2/conf-available/localized-error-pages.conf:# SetHandler none

Okay, that helps -- can you edit these two files:

/etc/apache2/mods-available/php7.0.conf
/etc/apache2/conf-available/php7.0-cgi.conf

And in those files, comment out any lines beginning with "SetHandler"?

After doing that, restart Apache.

Once that is complete, are you then able to access the PHP scripts in question?

WNYmathGuy's picture
Submitted by WNYmathGuy on Tue, 01/30/2018 - 16:36 Pro Licensee

Here's what they look like now:

/etc/apache2/mods-available/php7.0.conf

<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
#    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
    SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
    Require all denied
</FilesMatch>

# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>

/etc/apache2/conf-available/php7.0-cgi.conf

# This file replaces old system MIME types and sets them only in the
# Apache webserver

# application/x-httpd-php                        phtml pht php
# application/x-httpd-php3                       php3
# application/x-httpd-php4                       php4
# application/x-httpd-php5                       php
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
#    SetHandler application/x-httpd-php
</FilesMatch>
# application/x-httpd-php-source                 phps
<FilesMatch ".+\.phps$">
    SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
    Require all denied
</FilesMatch>

# To enable PHP CGI site-wide, just uncomment following lines, however
# as a security measure, it's recommended to enable PHP just in the
# specific virtual servers or just specific directories

#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#<Directory "/usr/lib/cgi-bin">
#    AllowOverride None
#    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
#    Order allow,deny
#    Allow from all
#</Directory>
#Action application/x-httpd-php /cgi-bin/php7.0

Yes! It did solve that problem. Can you guess at where I went wrong yet? Did I tweak too many things in my Plans and Templates for virtual servers and such?

I'm unfortunately not quite sure why that issue popped up.

Those lines are normally commented out during the Virtualmin installation.

Was an alternate PHP version perhaps installed after the Virtualmin installation?

WNYmathGuy's picture
Submitted by WNYmathGuy on Tue, 01/30/2018 - 19:08 Pro Licensee

Maybe. I tend to just add things when I get complaints from trying to put software I want on the server. I don't document those struggles too well. I may have done that though.