Apache doesn't execute php files, but mod_php5 is enabled

10,024

Solution 1

Found the problem.

They were 2:

  • plesk, which configuration was confusing me and giving me back the file to download
  • the lack of NameVirtualHost 111.22.33.44:80 in my virtual hosts

so i've excluded all the include by plesk, and then the problem was clear; the virtual host could not be resolved because there was another ip-based virtual host before that.

Thank you all for the help.

Solution 2

Check if you have this files "php5.conf" and "php5.load" into "mods-available" (default path : /etc/apache2/mods-available)

If not, create them like so:

php5.conf :

<IfModule mod_php5.c>
    <FilesMatch ".ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch ".phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # 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/*/site>
            php_admin_value engine Off
        </Directory>
    </IfModule>
</IfModule>

php5.load :

# default PATH : /usr/lib/apache2/module/libphp5.so
LoadModule php5_module PATH/libphp5.so

Phpmyadmin add link of config file name "phpmyadmin.conf" into "/etc/apache2/conf.d" with the necessary instruction for enable php :

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        AddType application/x-httpd-php .php

        php_flag magic_quotes_gpc Off
        php_flag track_vars On
        php_flag register_globals Off
        php_value include_path .
    </IFModule>
</Directory>
Share:
10,024
apelliciari
Author by

apelliciari

After 5 years of full-time PHP web development, I'm now into Python+Django+Pandas+AngularJS. Head Of Innovation at Webranking

Updated on June 05, 2022

Comments

  • apelliciari
    apelliciari almost 2 years

    I don't understand why. Instead of execute php files, he services me as download.

    In the downloaded file there is php source.

    My test file is very simple, its called info.php

    <?php
    
    phpinfo();
    

    My virtual host:

    <VirtualHost some_ip:80>
    DocumentRoot /var/www/vhosts/my_vhost/htdocs
    ServerName www.my_vhost.com
    
    <Directory /var/www/vhosts/my_vhost/htdocs/>
        Options All -MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
    
    ErrorLog  /var/www/vhosts/my_vhost/logs/error.log
    LogLevel warn   
    CustomLog /var/www/vhosts/my_vhost/logs/access.log combined
    
    </VirtualHost>
    

    In the apache2 conf i have the line:

    AddType application/x-httpd-php .php
    

    Apache enabled modules:

    apache2ctl -M
    Loaded Modules:
     core_module (static)
     log_config_module (static)
     logio_module (static)
     mpm_prefork_module (static)
     http_module (static)
     so_module (static)
     actions_module (shared)
     alias_module (shared)
     auth_basic_module (shared)
     auth_digest_module (shared)
     authn_file_module (shared)
     authz_default_module (shared)
     authz_groupfile_module (shared)
     authz_host_module (shared)
     authz_user_module (shared)
     autoindex_module (shared)
     bw_module (shared)
     cgi_module (shared)
     dav_module (shared)
     dav_fs_module (shared)
     dav_lock_module (shared)
     dav_svn_module (shared)
     authz_svn_module (shared)
     deflate_module (shared)
     dir_module (shared)
     env_module (shared)
     fcgid_module (shared)
     include_module (shared)
     mime_module (shared)
     negotiation_module (shared)
     perl_module (shared)
     php5_module (shared)
     python_module (shared)
     reqtimeout_module (shared)
     rewrite_module (shared)
     setenvif_module (shared)
     ssl_module (shared)
     status_module (shared)
     suexec_module (shared)
     userdir_module (shared)
     wsgi_module (shared)
    Syntax OK
    

    What i have to try to debug and solve this?

    I have phpmyadmin installed too and it works correctly.