我们尝试通过将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
我评论了在着陆时产生错误的代码。所以我们看了以下帖子
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
答案 0 :(得分:0)
启动laravel应用程序时,laravel在查找“真实根目录”时遇到问题。 您可能需要在config中更改引导目录和存储目录。