Search code examples
phpvuejs2single-page-applicationlaravel-7inertiajs

web dev - server not pointing to laravel 7.3 public, displaying 'Index of /' page


I have created a new laravel project in a fresh public_html dir on my work's server using

composer create-project laravel/laravel public_html

I have created the .vue component and the controller to display the homepage upon visiting the site but instead all that is displayed is this: faulty display

here is the web.php file for the handling the request:

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', [HomepageContoller::class, 'index'])
   ->name('home');

here is the HomepageController class:

<?php

namespace App\HTTP\Controllers;

use Inertia\Inertia;

class HomepageContoller extends Controller {

    public function index() {
        return Inertia::render('Homepage/Index');
    }
}

?>

and here is the .vue component:

<template>
  <div>
    <h1>Brite Visual Products<h1>
  </div>
</template>

<script>
export default {
  metaInfo: { title: 'Brite Visual Products' },
}
</script>

everything is exactly where it belongs, nothing has been moved since the composer create-project call

UPDATE:

it seems as though the issue is just that the web root is being pointed at public_html/ and not public_html/public/

to fix that i will need to have higher permissions on my work's server, will post a full solution later


Solution

  • edit the following file

    vi /var/cpanel/userdata/username/domain.com
    

    Replace the "username" with your cPanel account username and "domain.com" with your primary domain name and "subdir" with your new directory.

    Find the following two lines in this file.

    documentroot: /home/username/public_html
    path: /home/username/public_html/cgi-bin
    

    Modify these two lines to change the document root of your primary domain to a sub-directory inside "public_html" directory.

    documentroot: /home/username/public_html/subdir
    path: /home/username/public_html/subdir/cgi-bin
    

    If the primary domain has an SSL certificate installed, edit the following file the same way as above.

    vim /var/cpanel/userdata/username/domain.com_SSL
    

    Save the file after changes are made and then delete the cache file for your primary domain.

    rm -vf /var/cpanel/userdata/username/domain.com_SSL.cache
    

    Run the following scripts to update the user data cache and rebuild apache configuration file.

    /scripts/updateuserdatacache
    /scripts/rebuildhttpdconf
    

    Restart Apache server to load changes.

    service httpd restart