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

screwtape_mk's avatar

laravel on shared hosting

I have a shared hosting account and they have a wizard on cpanel for installing laravel. The problem is the installation seems to have all happened under public_html folder and therefore the laravel default home pages is at mysite.com/public (example site)

will moving all the files from there to the root folder solve my issues? or will i have to make changes to .htaccess or any other settings for that matter

0 likes
11 replies
LaraBABA's avatar

Yes that's right, to secure Laravel install it below the public_html, then what is inside the laravel/public folder should be above the public_html.

You then need to create a symlink the public to the storage folder as:

ln -s /home/accountname/laravel/storage/app/public/ /home/accountname/public_html/storage

You may need to change the paths in the public_html/index.php to:

require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
screwtape_mk's avatar

Im using laravel 7. Not sure what folder you're referring to here: /home/accountname/laravel/storage/app/public/ .

Unless what you are saying is after moving the public folder to above public_html i should then create a symlink to /public_html/storage in the following way:

ln -s  /home/mysite/public/  /home/mysite/public_html/storage
screwtape_mk's avatar

so is this accessible as a subdomain? what does it mean when it says Your laravel code base should be located in a folder that is not accessible from the web?

How do you then make it accessed through your main site e.g mysite.com

jlrdw's avatar

Your laravel code base should be located in a folder that is not accessible from the web?

It means main laravel should not be under public_html or htdocs.

Use the folder structure in the guide.

https://i.imgur.com/Oo6k4Fp.jpg

And htaccess add the line:

    RewriteEngine On
    RewriteBase /laravel54/   //Change this line to your use case

toetet's avatar
toetet
Best Answer
Level 1

First, upload laravel project to /home/account_name/project_name, not public_html. Then, Move /home/account_name/project_name/public contents to public_html.

Edit this 2 line of code public_html/index.php from

require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

to

require __DIR__.'/../project_name/vendor/autoload.php';
$app = require_once __DIR__.'/../project_name/bootstrap/app.php';

and add this code in public_html/index.php

$app->bind('path.public', function() {
    return __DIR__;
});

After that, replace public_html/.htaccess with

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

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    #RewriteRule ^(.*)/$public / [L,R=301]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

And edit project_name/server.php from

if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

to

if ($uri !== '/' && file_exists(__DIR__.'/../public_html'.$uri)) {
    return false;
}

require_once __DIR__.'/../public_html/index.php';

And the last, check your PHP version in cpanel. I used php7.3 as described above in .htaccess.

Well. I hope this will help you.

1 like
screwtape_mk's avatar

I am getting error:500 wonder what might i be missing?

Snapey's avatar

Is is a laravel 500 error page or one from your webserver?

screwtape_mk's avatar

Should i be changing artisan file in /home/account_name/project_name/? There is a this part there:

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

$app = require_once __DIR__.'/bootstrap/app.php';
screwtape_mk's avatar

Nah its not necessary! I was just having errors running migrations on cmd line but all good now, it was my cli php version that needed to change

Please or to participate in this conversation.