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

frumentius's avatar

Laravel 5.4 error 'The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.' When deploying to Shared Hosting

When I deploy my laravel 5.4 project to shared hosting, I got 'Whoops there is something wrong' message, so I checked the log, and it recorded this error 'production.Error The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.'

I've been searching on the web for solution, mainly the solution is to run this three command;

php artisan key:generate php artisan config:clear php artisan config:cache

but the problem is my shared hosting does not allow SSH access or terminal or any kind in order to run those commands.

Is there any workaround to solve this problem?

0 likes
24 replies
Snapey's avatar

Copy the key from your local development environment

Yorki's avatar

You might generate it manually or in localhost then just copy to APP_KEY

Snapey's avatar

How are you copying the project to the server?

Simple answer is to run php artisan config:cache locally before copying to the server

Yorki's avatar

You might remove bootstrap/cache/config.php file.

@Snapey what? You know how does caching of config works? It does use var_export. Unless you have exactly the same config as on production it won't be applicable.

frumentius's avatar

@snapey How I copy project to server;

  1. upload the content of public folder to htdocs folder in hosting
  2. create new folder 'laravel' in htdocs folder in hosting, then upload the rest of project folder and files (except public folder) to that 'laravel' folder
  3. change the the require __DIR__.'/../bootstrap/autoload.php'; and $app = require_once __DIR__.'/../bootstrap/app.php'; in index.php to require __DIR__.'/laravel/bootstrap/autoload.php'; and $app = require_once __DIR__.'/laravel/bootstrap/app.php';respectively
  4. change the APP_URL, Database Credentials in eveironment

as for running php artisan config:cache locally; yup also done that, but it shows even weirder error that says "cant find path C:\wamp\www" even tough it run on the hosting not on local

@Yorki if I dont run php artisan config:cache locally that file config.php would not exist, but if I run the command and then delete the file on server, still the same error

Snapey's avatar

ok, so instead of cache, you need to clear all and run composer dump

  • php artisan cache:clear
  • php artisan config:clear
  • composer dump

and then upload the files BEFORE accessing the project locally

frumentius's avatar

hi @Snapey I just did Your last suggestion and reupload but still the same error, unfortunately that did not solve it.

Yorki's avatar

Can you confirm that .env file is properly included? Do some debug with test.php. Sometimes shared hostings act weird if it comes to environment variables. Some of them are set from their panels.

getenv('APP_KEY');
Yorki's avatar

Just create test.php file in your public html directory where .env file exist. Then access this file and see if it gets environment variable

//test.php

var_dump(getenv('APP_KEY'));
rumm.an's avatar

Does your shared hosting provider allow you to change the document root of your site? If you can do that, you can simply upload your local project (including .env file) to server with no change in any of files.

Snapey's avatar

Where is your public folder?

You didn't load everything into public did you? thats a NO NO NO!

frumentius's avatar

@Yorki as i mention above .env is placed in htdocs/laravel/ while the content of public folder that contain index.php I uploaded it in htdocs/ so where should I put this test.php file? In htdocs/laravel/ where .env file exist, or in just htdocs/ where the files from public folder uploaded?

@rumm.an unfortunately not, I only allowed to upload in htdocs folder which I assume the same with public_html folder in other hosting.

Yorki's avatar

Move your .env file to htdocs/.env and try again

frumentius's avatar

@Yorki I get even more confuse, sorry please bear with me. If I move .env to htdocs/ should I also move all the other folder and files in htdocs/laravel/ into htdocs/, if so then it will mix up with all the content from public folder, is it ok to do that?

Yorki's avatar

You should move only your .env file to htdocs or try to change environment path. To do this add following line in your index.php

$app->useEnvironmentPath(__DIR__ . '/laravel');

Also create .htaccess in htdocs/laravel directory and put this content to prevent direct access to your framework files

Deny from all
frumentius's avatar

@Yorki I just did your second suggestion, adding $app->useEnvironmentPath(__DIR__ . '/laravel'); in my index.php but it still the same error. And I also create a test.php in htdocs/ an it returns 'bool(false)'

Yorki's avatar

Ohh sorry, remove $app->useEnvironmentPath(__DIR__ . '/laravel'); from your index.php file and put this in constructor of your kernel

//app/Http/Kernel.php

public function __construct(Application $app, Router $router)
{
    $app->useEnvironmentPath(dirname(__DIR__, 2) . '/laravel');

    parent::__construct($app, $router);
}
Snapey's avatar

I agree it sounds like your .env file is just not being found by Laravel framework.

Its a dangerous path to go down to try and install the framework in a public folder.

If you can save files above htdocs then I would put everything above htdocs and then put the content of public into the htdocs folder. Everything in Laravel can then operate as intended with no hacks to secure the site.

Yorki's avatar

@Snapey I assume he can't put anything above htdocs, many of shared hosting have this restrictions. I agree that putting framwork files in public directory is dangerous.

frumentius's avatar

@Yorki I just did what you last suggest with the kernel, then it returns nothing, only a white blank page.

@Yorki & @Snapey yup I can not put anything above htdocs because the host sepcifically says that I should not place any thing in there, because it will regularly clean/remove anything above htdocs

@rumm.an I suppose to create symlink need to have access to SSH or terminal or any kind of command line base, unfortunately the hosting does not give access to that.

Please or to participate in this conversation.