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

Thiranjaya Munasinghe

I built a single page web app with vue js as the front-end library and laravel as the back-end framework. 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.

I copied content of laravel public folder and build files of vue js to the public_html folder in shared hosting. 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).

//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', '.*');
?>
Hamlet

First,You should separated laravel project to 2 folder

  1. Rename public to public_html,copy and overwrite to shared hosting public_html folder
  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. ex:/var/www/laravel/ , /var/www/public_html/
  3. Edit index.php in public_html

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

For laravel 5 add this :

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

Hope this solve your problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Laravel | Shared hosting routes not working properly

Laravel 5 – Clear Cache in Shared Hosting Server

Deploying Laravel 4 on shared hosting server (hostgator)

laravel + vue js API store function doesn't work on shared hosting but works well on localhost

Deployment of Laravel app with Vue component on shared hosting - vue components are not displaying

Deploying Laravel 7 and Vue SPA application into shared hosting

Laravel on shared hosting with Subdomain

htaccess with Laravel on shared hosting

.htaccess not working with laravel on production server-Shared hosting

Reloading .env variables without restarting server (Laravel 5, shared hosting)

Laravel9 deployment on shared hosting , New added API Routes not found Postman 404 Error

Laravel website 'uploaded on shared hosting' is showing directory structure instead of my specified web routes

Frontend Routes not showing in Laravel backend

How to get routes working on shared hosting space

Laravel and shared hosting CURL not working

Shared hosting: WordPress/laravel 5

Sending mail with Laravel on shared hosting

Deploying Laravel 5.4 to Shared Hosting

Laravel deployment shared hosting subdomain

Vue js SPA hosting

Laravel server hosting error

How to Protect Frontend Route in Vue.js and Laravel?

Hosting several websites on wamp with laravel breaks the routes

Laravel routes not updating on server

Shared Hosting Laravel 8 Hosting problem: Symlink is not working

Hosting two different applications running on Laravel 4 on shared hosting

Why new installed laravel not work on shared hosting?

Laravel, Using a cPanel shared hosting if possible?

Displaying laravel stored images on shared hosting