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

enli0r's avatar
Level 3

Connection refused on deployed Laravel 11 App

I deployed Laravel app on infinityfree.com and I get this error: SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select * from sessions where id = xKNBtRsZTlb7lTyTuuTpYJvoLcsWkCaLkHAcAaay limit 1)

My database is imported from local phpmyadmin.

I changed my .env file to match my new database credentials and I guarantee that they are correct.

APP_NAME=AnswerFinder
APP_ENV=production
APP_KEY=base64:K5XZh3UywToemqlEPwbF3X0R7KMlHkxjzbkTjGo7REs=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=https://my infinityfree url

DB_CONNECTION=mysql
DB_HOST=sql303.infinityfree.com
DB_PORT=3306
DB_DATABASE= my infinityfree db name
DB_USERNAME= my infinityfree  db username
DB_PASSWORD= my infinityfree  pw

My config/database.php file:

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DB_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'laravel'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', 'Albatraoz01'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => env('DB_CHARSET', 'utf8mb4'),
            'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

My file structure in infinityfree looks like this:

  • /htdocs
    • /answerfinder (folder containing all the files from my project except public folder)
    • files from public folder

I have uploaded Laravel 7 and Laravel 8 apps likes this so I don't really know what the problem is now. This is Laravel 11 app so they might have changed something.

I would like to mention that because this is free hosting, I don't have terminal and every change has to be done locally and then uploaded with FileZilla again or using some php script.

0 likes
4 replies
JussiMannisto's avatar

This caught my eye:

APP_ENV=production
...
APP_DEBUG=true

You should NEVER have APP_DEBUG on in production. If there's an exception, lots of sensitive information will be shown to the user. Older versions would straight dump your environment variables on screen. So a bad actor could just send a GET request to a POST route, causing an exception, and steal all your credentials. There are bots that try this all the time.

From the official documentation:

During local development, you should set the APP_DEBUG environment variable to true. In your production environment, this value should always be false. If the value is set to true in production, you risk exposing sensitive configuration values to your application's end users.

1 like
enli0r's avatar
Level 3

@JussiMannisto Thanks for the advice. I was switching this from false to true on random because I had tried everything. I left it on true by accident. Also, this is for university project, so there isn't really any sensitive information on there.

jlrdw's avatar

Try using file for session.

Please or to participate in this conversation.