Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a Laravel 5 project in subdirectory of public root

I'd like to deploy a Laravel 5 app to a subdirectory of my web server root (public root being /public_html in this case as we're using Apache). The web server already has a non-Laravel site in the root public folder.

Most questions on this topic come down to using a subdomain instead of a subdirectory, however as we're using an organisational SSL cert without subdomain coverage we cannot do this.

I realise we could still plop the non-public resources above public_html, the public resources in a subdirectory and then hack at the paths required, but I haven't found any concrete instructions for how to achieve this. Is there a standard approach for this use case?

like image 605
codinghands Avatar asked Dec 30 '25 09:12

codinghands


1 Answers

You can create a sub-folder as public_html/new_project (or whatever name you give as per your coding conventions). And create another folder on the same level as the public_html for non-public resources as eg: new_project_resources.

  1. Now copy all everything except the public folder from your laravel project and upload it to the new_project_resources folder (on server).
  2. Open the public folder of your laravel project and copy everything and upload it to the public_html/new_project folder (on server).
  3. Now open index.php file from public_html/new_project and

    Change:  
    require __DIR__.'/../bootstrap/autoload.php';  
    To:  
    require __DIR__.'/../../new_project_resources/bootstrap/autoload.php';  
    And  
    Change:  
    $app = require_once __DIR__.'/../bootstrap/app.php';  
    To:  
    $app = require_once __DIR__.'/../../new_project_resources/bootstrap/app.php';  
    Save and Close.  
    
  4. Now go to new_project_resources folder and open server.php file

    Change:  
    require_once __DIR__.'../public/index.php';  
    To:  
    require_once __DIR__.'../public_html/new_project/index.php';  
    Save and close. 
    

    Things should work now from the subfolder. Hop it helps.

like image 145
Donkarnash Avatar answered Jan 03 '26 03:01

Donkarnash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!