Laravel应用程序不在xampp或live server上运行,但在php artisan server上运行良好

Laravel应用程序不在xampp或live server上运行,但在php artisan server上运行良好,php,laravel,mongodb,.htaccess,xampp,Php,Laravel,Mongodb,.htaccess,Xampp,我的laravel应用程序在xampp或live服务器上无法运行,但在PHP artisan serve提供的链接上运行良好。每当我在xampp上运行此应用程序时,它都会返回404错误。我还有其他的laravel应用程序,它们在xampp上也可以正常工作,但这一个除外。 我无法找到任何解决方案来解释为什么我的laravel没有在托管服务器或xampp上运行。我已经尝试了在相关问题中找到的所有解决方案,但没有发现任何有用的 我已尝试在更改现有.htaccess后运行该应用程序 根文件夹中的文件

我的laravel应用程序在xampp或live服务器上无法运行,但在PHP artisan serve提供的链接上运行良好。每当我在xampp上运行此应用程序时,它都会返回404错误。我还有其他的laravel应用程序,它们在xampp上也可以正常工作,但这一个除外。 我无法找到任何解决方案来解释为什么我的laravel没有在托管服务器或xampp上运行。我已经尝试了在相关问题中找到的所有解决方案,但没有发现任何有用的

  • 我已尝试在更改现有.htaccess后运行该应用程序 根文件夹中的文件
  • 在公开更改.htaccess文件后,我尝试运行该应用程序 文件夹
  • 我试着在删除两个和其中一个后运行应用程序
  • 我已尝试使用重新安装和更新依赖项 作曲家
我应该怎么做才能让它运行

当我尝试通过xampp运行它时,我看到的是错误,但当通过它运行web应用程序时,总是出现文件夹结构

现在,我的根文件夹中有一个htaccess文件。以下是其代码:

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

    RewriteEngine On

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

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
my package.json文件的代码:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "fideloper/proxy": "^4.0",
        "jenssegers/mongodb": "^3.6",
        "jeroennoten/laravel-adminlte": "^3.6",
        "laravel/framework": "^6.0",
        "laravel/tinker": "^1.0",
        "laravel/ui": "^1.1",
        "yajra/laravel-datatables-oracle": "~9.0"
    },
    "require-dev": {
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": [
                "laravel/dusk"
            ]
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}
{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.21.1",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.13",
        "popper.js": "^1.12",
        "resolve-url-loader": "^4.0.0",
        "sass": "^1.20.1",
        "sass-loader": "7.*",
        "vue": "^2.5.17",
        "vue-template-compiler": "^2.6.10"
    }
}
myserver.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';

我也遇到了这个问题。我做了一些研究,发现在xampp上运行Laravel的唯一可行方法是:

  • 在laravel设置的父文件夹中,我创建了一个名为“laravel”的文件夹,并将所有内容移动到其中
  • 我进入laravel/public,从中取出所有文件,并将其放入父目录,从而得到以下文件夹结构:(在我的htdocs中)
  • 进入index.php并将加载文件的代码行改为从新路径加载文件(例如):
  • 启动apache并检查localhost,它应该可以工作

  • 您需要编辑apache配置,指向
    DocumentRoot
    指向
    laravel\u root/public
    非常感谢,它确实解决了我的问题。在那之后,为了弄清楚实际的问题可能是什么,我把我的整个项目改回了以前我问这个问题时的样子,然后更改了我的应用程序文件夹的名称,这样做也解决了这个问题。不客气,老兄!但是,请注意,虽然此解决方案是这样工作的,但由于公用文件夹已移出,您将无法再使用“php artisan Service”启动Laravel。
    <?php
    
    /**
     * Laravel - A PHP Framework For Web Artisans
     *
     * @package  Laravel
     * @author   Taylor Otwell <taylor@laravel.com>
     */
    
    define('LARAVEL_START', microtime(true));
    
    /*
    |--------------------------------------------------------------------------
    | Register The Auto Loader
    |--------------------------------------------------------------------------
    |
    | Composer provides a convenient, automatically generated class loader for
    | our application. We just need to utilize it! We'll simply require it
    | into the script here so that we don't have to worry about manual
    | loading any of our classes later on. It feels great to relax.
    |
    */
    
    require __DIR__.'/../vendor/autoload.php';
    
    /*
    |--------------------------------------------------------------------------
    | Turn On The Lights
    |--------------------------------------------------------------------------
    |
    | We need to illuminate PHP development, so let us turn on the lights.
    | This bootstraps the framework and gets it ready for use, then it
    | will load up this application so that we can run it and send
    | the responses back to the browser and delight our users.
    |
    */
    
    $app = require_once __DIR__.'/../bootstrap/app.php';
    
    /*
    |--------------------------------------------------------------------------
    | Run The Application
    |--------------------------------------------------------------------------
    |
    | Once we have the application, we can handle the incoming request
    | through the kernel, and send the associated response back to
    | the client's browser allowing them to enjoy the creative
    | and wonderful application we have prepared for them.
    |
    */
    
    $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
    
    $response = $kernel->handle(
        $request = Illuminate\Http\Request::capture()
    );
    
    $response->send();
    
    $kernel->terminate($request, $response);
    
    |-.htaccess  
    |-favicon.ico  
    |-index.php  
    |-robots.txt  
    |-web.config   
    \---laravel
    
    if (file_exists(__DIR__.'/laravel/storage/framework/maintenance.php'))   
    {  
        require __DIR__.'/laravel/storage/framework/maintenance.php';  
    }