简体   繁体   中英

php code is written to output as plain text, why?

I've installed apache server and php5 on linux, but am not able to get a simple php file executed and shown in browser. What I see in browser is this:

<?php echo 'hello';?>

Why is the php code not executed?

Here is the content of /etc/apache2/sites-available/default file:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/public
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And I have place my test php file in /var/www/public

Consider these:

  • Is PHP installed?
  • Is relevant apache module enabled (eg mod_php)?
  • What is the file permission of PHP file? Can it be executed by the web server user?
  • Is there any error message at apache or php error log?

Well you have the container missing for one,, here is a conditional with the echo call back.

if($result) {
       echo "success";
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM