Skip to content

Instantly share code, notes, and snippets.

@chinleung
Last active June 22, 2023 19:41
Show Gist options
  • Save chinleung/2e9f6a9496ded8cd6fadc829b0030229 to your computer and use it in GitHub Desktop.
Save chinleung/2e9f6a9496ded8cd6fadc829b0030229 to your computer and use it in GitHub Desktop.
Installing Laravel Nova in subfolder

Instsalling Laravel Nova in a subfolder

This is a guide that will show you how to install Laravel Nova in a subfolder of a domain.

Clone the repository

Clone the repository in the home directory of the cPanel user.

cd /home/user
git clone https://github.com/your/project.git /home/user/folder

Configure Laravel

This is just like you usually do, run the commands you need to make your Laravel install work. For example:

cd folder
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate

Create a symbolic link

Make a symbolic link with the newly created folder on your public_html folder.

cd /home/user/public_html
ln -s ../folder/public folder

This will give us access to https://domain.com/folder. At this point, you should be able to see your Laravel application.

Update Nova's axios base URL

This will tell Nova to use the subfolder domain for the /nova-api/ requests. Open vendor/laravel/nova/resources/js/util/axios.js and add a base url to the config.

const instance = axios.create({
    baseURL: 'https://domain.com/folder'
})

Install the npm dependencies

cd /home/user/folder/vendor/laravel/nova && yarn

Rename the webpack

Rename the webpack.mix.js.dist to webpack.mix.js to be able to make a production build.

mv webpack.mix.js.dist webpack.mix.js

Compile the Nova scripts

yarn production

Move the compiled scripts

Now that you've compiled the scripts, you have to move them to them into /home/user/folder/public/vendor/nova.

mv /home/user/folder/vendor/laravel/nova/public/* /home/user/folder/public/vendor/nova/

Now at this point, your Nova should be loading properly, but once you login, you will notice a 404 page.

Fix the base url

Open /home/user/folder/vendor/laravel/nova/resources/views/layout.blade.php and look for window.config = @json(Nova::jsonVariables(request())); to add the following on the next line:

window.config.base = '/folder' + window.config.base;

This will tell Nova that the base url of the admin is located under the subfolder.

@hlorofos
Copy link

Awesome guide, thanks!!!

@legreco
Copy link

legreco commented Jun 27, 2022

Does this works for latest Nova version? (Nova 4.0)

@chinleung
Copy link
Author

Does this works for latest Nova version? (Nova 4.0)

I haven't had the chance to test out Nova 4.0 yet. You can try it out. 😄

@RobbeReygel
Copy link

Since the introduction of Inertia in Nova 4 this patch no longer works.
Is there an updated patch for this available anywhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment