简体   繁体   English

托管Vue js前端和laravel后端(api路由)到共享服务器?

[英]Hosting a Vue js frontend and laravel backend(api routes) to a shared server?

I built a single page web app with vue js as the front-end library and laravel as the back-end framework. 我构建了一个单页Web应用程序,其中vue js作为前端库,laravel作为后端框架。 Its now time to host it on a shared hosting service and have not found any clear steps on how to do this successfully with the Api Routes of the loading as programmed. 它现在是时候将它托管在一个共享的托管服务上,并且没有找到任何明确的步骤,如何成功地使用编程的加载Api路由。

I copied content of laravel public folder and build files of vue js to the public_html folder in shared hosting. 我复制了laravel公共文件夹的内容,并将vue js的文件构建到共享主机中的public_html文件夹中。 Then it's loading the frontend without data from the backend. 然后它在没有来自后端的数据的情况下加载前端。 Should I have to use two separate ip addresses for backend and frontend or is it possible to use same shared hosting storage for deploy my Vue js frontend and laravel backend(api routes). 我是否必须为后端和前端使用两个单独的IP地址,或者是否可以使用相同的共享主机存储来部署我的Vue js前端和laravel后端(api路由)。

//index.php of laravel
<?php
require __DIR__.'/../jewelpack_app/vendor/autoload.php';
$app = require_once __DIR__.'/../jewelpack_app/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
?>
//web.php of laravel routes
<?php
Route::get('/{any}', function(){
   return view('index');//pointing to the index file of the frontend
})->where('any', '.*');
?>

First,You should separated laravel project to 2 folder 首先,你应该将laravel项目分成2个文件夹

  1. Rename public to public_html,copy and overwrite to shared hosting public_html folder 将public重命名为public_html,复制并覆盖到共享主机public_html文件夹
  2. Create a new folder called 'laravel' , copy the rest project data to it and move into hosting using FTP where the same path with your public_html. 创建一个名为“laravel”的新文件夹,将其余的项目数据复制到其中,然后使用FTP进入托管,其中与public_html的路径相同。 ex:/var/www/laravel/ , /var/www/public_html/ 例如:/ var / www / laravel /,/ var / www / public_html /
  3. Edit index.php in public_html 在public_html中编辑index.php

$app = require_once DIR.'/../bootstrap/app.php'; to $app = require_once DIR.'/../laravel/bootstrap/app.php'; $app = require_once DIR.'/../laravel/bootstrap/app.php';

For laravel 5 add this : 对于laravel 5,添加:

$app->bind('path.public', function() { return __DIR__; });

Hope this solve your problem. 希望这能解决你的问题。

Actually problem was with the my domain. 实际上问题在于我的域名。 I used my tempory webpage url for the hosting process. 我使用我的临时网页网址进行托管过程。 After I register my domain it all works fine. 注册我的域名后,一切正常。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM