简体   繁体   English

php代码写为纯文本输出,为什么?

[英]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. 我已经在Linux上安装了Apache服务器和php5,但无法执行并在浏览器中显示一个简单的php文件。 What I see in browser is this: 我在浏览器中看到的是:

<?php echo 'hello';?>

Why is the php code not executed? 为什么未执行php代码?

Here is the content of /etc/apache2/sites-available/default file: 这是/etc/apache2/sites-available/default文件的内容:

<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 我已经将我的测试php文件放在/var/www/public

Consider these: 考虑这些:

  • Is PHP installed? 是否已安装PHP?
  • Is relevant apache module enabled (eg mod_php)? 是否启用了相关的Apache模块(例如mod_php)?
  • What is the file permission of PHP file? PHP文件的文件权限是什么? Can it be executed by the web server user? Web服务器用户可以执行吗?
  • Is there any error message at apache or php error log? 在apache或php错误日志中是否有任何错误消息?

Well you have the container missing for one,, here is a conditional with the echo call back. 好吧,您有一个缺少的容器,这是带有回声回调的条件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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