【发布时间】:2020-02-07 18:34:27
【问题描述】:
我们尝试通过将 laravel 文件夹上传到 linux 服务器来部署我们的 laravel 服务器。我们将公共文件夹放在 public_html/laravelsite 中,其他所有内容放在名为 laravelsite 的文件夹中。我们添加了
$this->app->bind('path.public', function() {
return base_path().'/../public_html';
});
到我们的 AppServiceProvider。但是在浏览器中查看该站点时,我们会收到以下错误。
app.css:1 加载资源失败:服务器响应状态 500 个(内部服务器错误)bootstrap.js:1
加载资源失败: 服务器响应状态为 500(内部服务器错误) app.js:1
加载资源失败:服务器响应状态为 500 (内部服务器错误)bootstrap.js:1
加载资源失败:服务器响应状态为 500 (内部服务器错误)app.js:1
加载资源失败:服务器响应状态为 500 (内部服务器错误)app.css:1
app.css:1 加载资源失败:服务器响应状态 500 个(内部服务器错误)app.css:1
我在landing.blade中注释了产生错误的代码所以我们看了下面的帖子
How can I change the public path to something containing an underscore in Laravel Mix?
但这样做对我们来说并不奏效。
landing.blade(着陆页)
<!DOCTYPE html>
<!-- hidden override for w3 style this has to be removed before this goes in production !!!!!!!! -->
<html style="overflow:hidden">
<head>
<meta property="og:image" content="/favicon.png" />
<title>Laravel Site</title>
<meta name="description" content="Welcome to out Laravel Site. Come on in!" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{csrf_token()}}">
<!-- This is the first error -->
<link href=" {{ mix('css/app.css') }}" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Raleway:800' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Raleway:500' rel='stylesheet' type='text/css'>
<link href=" {{ asset('css/animate.css') }}" rel="stylesheet">
<link href=" {{ asset('css/text-editor.css') }}" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons' rel="stylesheet">
<script src="https://d3-geomap.github.io/d3-geomap/vendor/d3.geomap.dependencies.min.js"></script>
<script src="https://d3-geomap.github.io/d3-geomap/js/d3.geomap.min.js"></script>
</head>
<body style="background-color: #f2f2f2;">
<div id="app">
<app></app>
</div>
<!-- This is the second error -->
<script src="{{ mix('js/bootstrap.js') }}"></script>
<!-- This is the third error -->
<script src="{{ mix('js/app.js') }}"></script>
</body>
</html>
webpack.mix
let mix = require("laravel-mix");
mix.setPublicPath("public_html/laravelsite/");
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.webpackConfig({
resolve: {
extensions: [".js", ".vue", ".json"],
alias: {
vue$: "vue/dist/vue.esm.js",
"@": __dirname + "/resources/assets/js"
}
}
});
mix
.js("resources/assets/js/app.js", "public_html/laravelsite/js")
.setResourceRoot("")
.js("resources/assets/js/bootstrap.js", "public_html/laravelsite/js")
.sass("resources/assets/sass/app.scss", "public_html/laravelsite/css");
它正在尝试加载位于 http://websitename.com/css/app.css 的文件,因此它可能正在查看 public_html 文件夹。但在该文件夹中,我们还有另一个名为 laravelsite 的文件夹,所以它应该在寻找 http://websitename.com/laravelsite/css/app.css
【问题讨论】:
-
我们尝试了 npm install 并运行 dev,但没有成功
-
将您的公用文件夹内容放在 public_html 文件夹中。 public_html 文件夹外的其他文件夹。然后更新 index.php 文件的正确路径 th boostrap 和供应商。最后 xraeate 到您的存储文件夹的符号链接
-
@kas 我们已经完成了所有这些操作
-
实际上你不需要指向 public_html 的路径,除了 symlink 像我的 appservice provider 或 webpack.mix