Laravel虚拟主机显示公共内容而不是应用程序

时间:2017-12-21 05:06:58

标签: php apache .htaccess laravel-5

我在服务器中有一个laravel 5.4应用程序,当我尝试测试我的应用程序时,我得到了这个结果。

enter image description here

我的虚拟主机文件

/* Get total number of records */
$sql = "SELECT count(*) FROM VideoUploads";
$retval = $conn->query($sql);
if(! $retval )
{
  die($mysqli->error.__LINE__);
}

$rec_count = $retval->fetch_row();
$rec_count = $rec_count[0];

//getting all data from table
$sql = "SELECT * FROM VideoUploads ORDER BY slno DESC";

$retval = $conn->query($sql);
if(! $retval )
{
 die($mysqli->error.__LINE__);
}

//creating an array for response
 $response = array();

 if ($retval->num_rows > 0) {
 $response["wallpapers"] = array();
 $response["success"] = 1;
 $response["count"]= $rec_count;
 while ($row = $retval->fetch_array()) {
        // temp wallpaper array
        $wallpaper = array();
        $wallpaper["slno"] = $row["slno"];
        $wallpaper["video_url"] = "http://xxxwebsiteurlxxx/".$row["video_url"];
        $wallpaper["downloads"] = $row["downloads"];
        $wallpaper["views"] = $row["views"];


        // push all data into final response array
        array_push($response["wallpapers"], $wallpaper);
    }

    // echoing JSON response
   echo str_replace('\/','/',json_encode($response));
   //echo str_replace('\/','/',json_encode($response,JSON_PRETTY_PRINT));

} else {
    // no wallpapers found
    $response["success"] = 0;
    $response["message"] = "No Wallpapers found";
}

我的index.php文件

<VirtualHost *:80>
ServerName plataformafoodif.cl
DocumentRoot "/var/www/html/Plataforma-FoodIf/public"
ServerAlias www.plataformafoodif.cl
 <Directory "/var/www/html/Plataforma-FoodIf/public">
   Options All
   AllowOverride All
   Allow from all
 </Directory>
</VirtualHost>

我的.htaccess文件

<?php

 require __DIR__.'/../bootstrap/autoload.php';
 $app = require_once __DIR__.'/../bootstrap/app.php';

我的主人档案

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


</IfModule>

同样在我的.env上我有

# Generated by SolusVM
127.0.0.1       localhost localhost.localdomain
::1     localhost localhost.localdomain
# 168.232.167.108       FRESBOX.CL
168.232.167.108 plataformafoodif.cl

任何帮助都会非常感激,我花了很多时间来解决这个问题

2 个答案:

答案 0 :(得分:0)

您好,可以试试这个: -

<VirtualHost *:80>
ServerName plataformafoodif.cl
DocumentRoot "/var/www/html/Plataforma-FoodIf/public"
ServerAlias www.plataformafoodif.cl
 <Directory "/var/www/html/Plataforma-FoodIf">
   Options All
   AllowOverride All
   Allow from all
 </Directory>
</VirtualHost>

并且您还必须配置apache2.config文件。

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

您可以在apache2.conf文件中找到上面的代码,您可以在其中添加第三个目录的路径。

然后重新加载apache服务器。我希望这可以帮助你解决问题。

答案 1 :(得分:0)

最后是这个

<IfModule dir_module>
   DirectoryIndex index.html
</IfModule>

我已经更改为index.php以匹配我在public上的文件,我还添加了php模块行

LoadModule php7_module modules/libphp7.so

感谢您的帮助