Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

oliverbusk's avatar

React site in a sub-folder (on Forge)

Hi.

I have a standard laravel app running at "site.mydomain.com". I need to add a documentation site, and I haven't found any I like in Laravel/PHP - but there's a ton in Next.js.

Is it possible to add the Next.js site to a subfolder, so that becomes "site.mydomain.com/docs" for example?

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, it is possible to add a Next.js site to a subfolder in Laravel Forge. Here's how you can do it:

  1. First, make sure you have Next.js installed in your Laravel project. You can do this by running the following command in your project's root directory:
npm install next
  1. Create a new folder in your Laravel project's public directory. Let's call it docs.

  2. Inside the docs folder, create a new file called index.js with the following content:

import { render } from 'react-dom';

const Docs = () => {
  return <h1>Welcome to the documentation site!</h1>;
};

render(<Docs />, document.getElementById('root'));
  1. In your Laravel project's routes/web.php file, add the following route:
Route::get('/docs/{path?}', function () {
    return view('docs');
})->where('path', '.*');
  1. Create a new file called docs.blade.php in your Laravel project's resources/views directory with the following content:
<!DOCTYPE html>
<html>
<head>
    <title>Documentation</title>
    <link rel="stylesheet" href="{{ asset('css/app.css') }}">
</head>
<body>
    <div id="root"></div>
    <script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
  1. In your Laravel project's webpack.mix.js file, add the following code:
mix.react('public/docs/index.js', 'public/js/app.js')
   .sass('resources/sass/app.scss', 'public/css/app.css');
  1. Run the following command to compile your assets:
npm run dev
  1. Finally, you can access your Next.js documentation site at site.mydomain.com/docs.

Note: This solution assumes that you have already set up Laravel Forge and have a working Laravel project.

Please or to participate in this conversation.