Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel共享主机,index.php不指向根目录,而是停留在公共htmls上_Php_Laravel_Shared Hosting - Fatal编程技术网

Laravel共享主机,index.php不指向根目录,而是停留在公共htmls上

Laravel共享主机,index.php不指向根目录,而是停留在公共htmls上,php,laravel,shared-hosting,Php,Laravel,Shared Hosting,我一直在使用cpanel在共享主机上部署我的Laravel应用程序。但是,我发现以下错误: [08-Sep-2018 07:38:43 UTC] PHP Fatal error: require(): Failed opening required '/home/daankraa/public_html/../../supersax/vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear')

我一直在使用cpanel在共享主机上部署我的Laravel应用程序。但是,我发现以下错误:

[08-Sep-2018 07:38:43 UTC] PHP Fatal error:  require(): Failed opening required '/home/daankraa/public_html/../../supersax/vendor/autoload.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in /home/daankraa/public_html/index.php on line 24
从这里我可以看到,它不想切换到根目录,但一直在寻找:

/home/daankraa/public_html/../../supersax/vendor/autoload.php in public_html.
我尝试了点向上移动一个目录,但它不想。我怎样才能解决这个问题

提前谢谢

Daan

1)拷贝 .htaccess从公用文件夹访问根目录

(二) 将server.php重命名为index.php

php文件将位于根目录中


简单:)

将所有内容从public目录移动到根目录,并根据如下方式修改公用文件夹的index.php文件:

    require __DIR__.'/vendor/autoload.php';

    $app = require_once __DIR__.'/bootstrap/app.php';
index.php

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

这里有一个非常简单的方法,对我来说很有用:

  • 在public_html文件夹中创建一个.htaccess文件(该文件与.env文件的级别相同)

  • 在.htaccess文件中复制并粘贴以下代码

     <IfModule mod_rewrite.c>
       <IfModule mod_negotiation.c>
           Options -MultiViews -Indexes
       </IfModule>
     RewriteEngine on
     # serve existing files in the /public folder as if they were in /
     RewriteCond %{DOCUMENT_ROOT}public%{REQUEST_URI} -f
     RewriteRule (.+) /public/$1 [L]
     # route everything else to /public/index.php
     RewriteRule ^ /public/index.php [L]
     </IfModule>
    
    
    选项-多视图-索引
    重新启动发动机
    #将/public文件夹中的现有文件视为处于/
    RewriteCond%{DOCUMENT\u ROOT}public%{REQUEST\u URI}-f
    重写规则(+)/public/$1[L]
    #将所有其他内容发送到/public/index.php
    重写规则^/public/index.php[L]
    
  • 保存文件。这就是你现在可以访问你的网站的全部内容

  • 注意:由于某些原因,如果它不起作用,您的文档根目录可能会不同,您将不得不使用公用文件夹的完整路径来替换:{document_root}为完整路径/var/www/example.com/web,您可以通过在laravel的公共文件夹中创建一个名为get_doc_root.php的文件来获得完整路径,并在该文件中粘贴代码

    <?php
    echo getcwd();
    

    是否已将index.php从公用文件夹移动到根目录中?这就是index.php在public\u html中的原因吗?
    /home/daankraa/public\u html/
    是指向laravel项目的路径吗?如果是这样,那么路径应该是这样的:
    /home/daankraa/vendor/autoload.php
    我的根目录中没有任何server.php。检查应用程序根目录如果server.php不在那里,然后在根目录中创建index.php粘贴index.php文件code如果应用程序根文件夹中没有server.phpadd index.php,请检查新答案