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

Neeraj1005's avatar

How to get rid of public URL in your laravel project deployed on server cPanel "yourcpanelname/supportcrm/public"

In cPanel I have uploaded my laravel project but now when I enter my cPanel url. It list me all structure like

app
public
routes
etc...

when I click on public then it runs but I want to access directly with site name..How can I do this.. should I have to create subdomain or is any other method.. because using creating subdomain its working...please let me know it there is any other suggestion instead of subdomain..

0 likes
15 replies
takdw's avatar

You can go to the Domains section of cPanel then edit the document root of your domain to point to the public directory of your project instead of the root directory.

Neeraj1005's avatar

@takdw I have one confusion Is it a good idea to chane .htaccess file and index file in laravel..? I google it most of article and video tutotrial say about change .htaccess and make change in index.php file... plz let me know...

takdw's avatar

That's not how I like to deploy my apps. I like to keep the file structure the same. Changing the document root is the easiest fix for me.

Snapey's avatar

its NOT a good idea to change index.php and htaccess. Those guides should be taken down as they promote poor security

ErikRobles's avatar

@Snapey Hello. Following takdw above, how do you remove /public from the url. ??? Thanks

malekTn's avatar

@neeraj1005 copy all the project and make it in a new folder ( exp: project), after that copy all files from public file and put them in the root folder of server .

You get this in root folder of server

project
index.php
.htaccess
composer.json 
.....

After that change this two lines in your index.php file

require __DIR__.'/"project"/vendor/autoload.php';
require __DIR__.'/"project"/vendor/autoload.php';

Neeraj1005's avatar

@malektn I think It is not a good way to changes with framework flow...?

@takdw @snapey @malektn Also I have found another solution from stackoverflow https://stackoverflow.com/a/54275198/8455396

Create .htaccess file in root directory and place code something like below


<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^ [N]

    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/ 

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
</IfModule>

In my localhost its running properly but my another problem is.. when error page occured how to hide you environment variable data...because in error page it show all data your database name with password

1 like
AbdulBazith's avatar

@neeraj1005 you can do like this,

say for example if your domain is xyz.com means, upload all your project files in that domain.

now move inside you public folder and cut all files and paste outside.

means: xyz.com->public->all files to xyz.com->those files

so the index files in your public will come outside. now open your index file and change it as,

require __DIR__.'/../vendor/autoload.php';


$app = require_once __DIR__.'/../bootstrap/app.php';



to



require __DIR__.'/vendor/autoload.php';


$app = require_once __DIR__.'/bootstrap/app.php';

This works fine.. There is no need of change in htaccess file

Snapey's avatar

Change the document root to be the public folder, as suggested by @takdw

Omer Mahdi's avatar

my hosting provider does not support changing the document root for the domain what should I do

CamKem's avatar

@Omer Mahdi Please do not post on old threads, if you have a question make a new post & people will help you.

Please or to participate in this conversation.