Laravel 在主页上显示 index.php 的代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42921669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:37:24  来源:igfitidea点击:

Laravel showing code of index.php on home page

phpapachelaravellaravel-5ubuntu-16.04

提问by Faizan Ali

I'm using Apache 2.4 on Ubuntu 16.04, it shows the content of the index.php in browser.

我在 Ubuntu 16.04 上使用 Apache 2.4,它在浏览器中显示 index.php 的内容。

enter image description here

在此处输入图片说明

here's the code of my site's conf file:

这是我网站的 conf 文件的代码:

<VirtualHost *:80>

        DocumentRoot /var/www/laravel/public
        ServerName laravel.dev

        <Directory /var/www/laravel/public>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
</VirtualHost>

Why the home page renders index.php as text file?

为什么主页将 index.php 呈现为文本文件?

Note: I have set 777 permissions to laravel folder. PHP is also installed.

注意:我已经为 laravel 文件夹设置了 777 权限。PHP也安装了。

回答by Faizan Ali

I got the solution over here..

我在这里得到了解决方案..

Actually, I had to install libapache2-mod-phpand activate it i.e. a2enmod php7.0

实际上,我必须安装libapache2-mod-php并激活它,即a2enmod php7.0

回答by Saurabh Mistry

add below command :

添加以下命令:

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

(this will pull the default PHP version)

(这将拉取默认的 PHP 版本)

Reload Apache configuration changes by restarting service using below command

通过使用以下命令重新启动服务来重新加载 Apache 配置更改

sudo service apache2 restart