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

waiyanhein's avatar

How to host laravel 5 project in subfolder of live server for staging and access from sub folder URL

Hi every one . I already developed a small laravel 5 project on my local machine as beta version . I need to show it to client via online . So I need to deploy it to company staging server as for staging . I will deploy it in the sub folder like this - {domain}/{project_name} . I want to also access that project from URL like this as well - {domain}/{project_name} . So please how can it be done ? Please help me I am new to Laravel . Can I have some .htaccess solution for this please ?

0 likes
8 replies
phildawson's avatar

Would it not be easier to do it properly and deploy to a subdomain? Seems a lil weird having the root as a public folder.

staging.domain.com/project-name ???
project-name.staging.domain.com
matus's avatar

Hi @waiyanhein,

I have got some experience with hosting laravel projects on shared hosting. Just copy the whole content of project/public folder a put it inside the project_name directory on the server. Then copy the rest of your project folder content inside laravel directory (which you create and put somewhere on your server, you do not have to copy node_modules directory). Afterwards go to project_name directory on the server and open index.php file. You need to change those 2 paths which are there so they point to the right location of autoload.php and app.php files on your server.

Hope I helped you a bit :)

1 like
waiyanhein's avatar

Thank you . But I just need to do it accessible by this way {domain}/{project_name}

arthurckh's avatar

Updated.. Before that, I suggest that using a sub-domain is a better solution than letting your Laravel app lives in sub-directory.

I have tried two methods

  1. Create .htaccess at root of your project to redirect to the public folder.
  2. Move all files in public folder to the root of your project and move all files in root of your project (excluded public folder) to the folder created by ourself. Lastly, re-point the autoload and app.php inside index.php.

both can be found online. And both works very fine.

However, the problems I have faced are: when you have gone far for your project. every links or urls you have coded must be added with {your subdirectory name} . (eg. form action in login.php "localhost/login" will be changed to "localhost/sub_dir_name/login)

because changing project to subdirectory, your laravel routing doesn't match the changed url anymore.

For the solution of these problems.

  1. All your routes in web.php (laravel 5.3) or routes.php ( 5.2 and below) must be grouped by prefix of "your sub directory name".
  2. Try to use laravel global helper class url() to every url like your css call, js call , form action. And modify url() function in directory vendor/laravel/framework/src/illuminate/foundation/helpers.php to add your subdirectory name automatically when calling url() function. (However, changing your library file in vendor is not recommended. you should write your own helper class to wrap that function and write your own code for that. But in this case, you will be using your own helper class but not url() anymore).

tested with laravel 5.3 and xampp.

Maybe my solution is not the best, if you have a better solution. Please share with me. [email protected]

Please or to participate in this conversation.