PHP not interpreted, showing in view source

后端 未结 6 1923
春和景丽
春和景丽 2021-01-17 10:31

I\'m hoping that this will be a useful page for getting started running php code as well as solve the current problem I\'m having some very simple code as follows:



        
相关标签:
6条回答
  • 2021-01-17 10:42

    If you have the contents of the web page in user directory like:

    /home/*/public_html
    

    Then you need to enable executing those, it's disabled by default:

    # 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>
    

    Just comment out this piece of code located in the file:

    /etc/apache2/mods-enabled/php7.3.conf
    

    Adjust the path and file name to your system, PHP version, etc.

    0 讨论(0)
  • 2021-01-17 10:44

    In my case I had the /var/www/ folder with wrong permissions.

    I had to run:

    sudo chown -R www-data /var/www/
    sudo chgrp -R www-data /var/www/
    
    0 讨论(0)
  • 2021-01-17 10:45

    Are you sure you have php installed? If it is you need to make sure that apache is associating .php files with the php handler. Look for an entry similar to the following in /etc/apache/apache.conf

     LoadModule php5_module modules/libphp5.so
    

    and

     application/x-httpd-php        php php5
    

    upon changing the file you will need to restart apache via sudo service httpd restart

    0 讨论(0)
  • 2021-01-17 11:03

    If you are using php7 make sure you installed this module.

    sudo apt-get install libapache2-mod-php7.0
    

    Replace 7.0 with the version of php you are using.

    To find version of php, use

    php -v 
    
    0 讨论(0)
  • You probably need addHandler or addType in either the .htaccess file or Apache config itself: e.g. AddType application/x-httpd-php .php

    0 讨论(0)
  • 2021-01-17 11:08

    You can install libapache2-mod-php5 using

    apt-get install libapache2-mod-php5
    

    Worked for me.

    0 讨论(0)
提交回复
热议问题