Try to run following commands
php artisan config:clear
php artisan cache:clear
php artisan route:clear
What exactly is the requested URL that's not found and are all other routes working fine ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello all, I'm working on a Laravel application and I'm encountering an error during login. I have deployed the application on the GCP compute engine and accessing the app via the external IP. When I try to log in, I see the following error message:
Not Found The requested URL was not found on this server.
Apache/2.4.52 (Ubuntu) Server at 34.30.69.122 Port 80
I tend to believe it might be that the database is maybe not connected because after logging in it should show the dashboard.
Try to run following commands
php artisan config:clear
php artisan cache:clear
php artisan route:clear
What exactly is the requested URL that's not found and are all other routes working fine ?
@gych no luck
@gych I would know if the other routes are working because on the login screen after typing the password and username I just get that error. am not sure if I badly configured my files or if's related to the database
@gych I think its related to the db after running this command :sudo php artisan migrate
APPLICATION IN PRODUCTION.
Do you really wish to run this command? (yes/no) [no] ❯ yes
ErrorException
Undefined array key "database"
at vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:76 72▕ { 73▕ $pdo = $this->createPdoResolver($config); 74▕ 75▕ return $this->createConnection( ➜ 76▕ $config['driver'], $pdo, $config['database'], $config['prefix'], $config 77▕ ); 78▕ } 79▕ 80▕ /**
+27 vendor frames
28 artisan:35 Illuminate\Foundation\Console\Kernel::handle() my@my-vm:/var/www/html$
@Danny971 Did you set the correct database credentials in the env file?
@gych I guess so.
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=test_db
DB_USERNAME=test_usr
DB_PASSWORD=root
@gych any ideas as to where I went wrong
@Danny971 by assuming you have a database installed and setup on localhost?
@Snapey yes on my compute engine vm should I change the database from local host to the internal ip
@Danny971 have you logged into the vm and created 'test_db' ?
and set a very strong password
@Snapey yes
@Danny971 Have you tried to login via the terminal with the created database credentials? To confirm that they are valid and work. I also strongly advise you to use a stronger password because its not that safe to use root as password.
@gych root isn't my password I just out it aa so for the post
@Danny971 Ok good and can you login with the credentials via the terminal ?
@gych yes I can login to the database and see my tables ectopic
@Danny971 Show your config/database.php file?
/var/www/html/config$ cat database.php
<?php
use Illuminate\Support\Str;
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST'),
'port' => env('DB_PORT', '3306'),
// 'database' => env('DB_DATABASE', 'forge'),
// 'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'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'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer body of commands than a typical key-value system
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
],
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
],
'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_CACHE_DB', '1'),
],
],
];
@Danny971 Why are these commented out? Uncomment and try again. Laravel needs to know the database and username to connect to.
Uncomment this
// 'database' => env('DB_DATABASE', 'forge'),
// 'username' => env('DB_USERNAME', 'forge'),
@gych did this and still no luck
@Danny971 Try to run php artisan config:clear after you've changed this
I was doing some debugging and I notice something
on the compute engine i added the following line of code in the controller that manages my login
$dbConnection = Config::get('database.default');
$dbConfig = config("database.connections.$dbConnection");
dd($dbConfig);
and I get this
array:13 [▼ // app/Http/Controllers/AuthManager.php:25
"driver" => "mysql"
"url" => null
"host" => "localhost"
"port" => "3306"
"password" => "specialpassword"
"unix_socket" => ""
"charset" => "utf8mb4"
"collation" => "utf8mb4_unicode_ci"
"prefix" => ""
"prefix_indexes" => true
"strict" => true
"engine" => null
"options" => []]
notice we did not see database name or username
but when i test the same code on the localhost I see the username and database name listed . so this is can conclude that the database is not being linked properly but the password and all other parameters are correct in the .env file
which indicates those lines are still commented out in your database.php , or you are using an old cached version of config
@Snapey I uncommented it
@Danny971 then what?
@Snapey do you want me to share my screen team viewer or google meets
@Danny971 no, I want you to take hints and resolve it for yourself. Just because you asked a question does not mean that you get to stop thinking. You could have easily spotted that the two missing elements were those that you were told to uncomment 4 DAYS AGO.
ok, so you clearly did not uncomment those lines. Check the file on the server.
@Snapey I sware I uncomment it
@Danny971 Did you also clear the config with php artisan config:clear
Did you also clear the config with php artisan config:clear
On the GCP server
@Snapey no I did not do that part
here is my database.php now
/var/www/html/config$ cat database.php
<?php
use Illuminate\Support\Str;
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'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'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => 'prefer',
],
@Snapey just did it and still nothing
@Danny971 add a method to your controller again
dd(config('database'));
here is the result
array:4 [▼ // app/Http/Controllers/AuthManager.php:25
"default" => "mysql"
"connections" => array:4 [▼
"sqlite" => array:5 [▼
"driver" => "sqlite"
"url" => null
"database" => "crf_db"
"prefix" => ""
"foreign_key_constraints" => true
]
"mysql" => array:13 [▼
"driver" => "mysql"
"url" => null
"host" => "localhost"
"port" => "3306"
"password" => "specialpassword"
"unix_socket" => ""
"charset" => "utf8mb4"
"collation" => "utf8mb4_unicode_ci"
"prefix" => ""
"prefix_indexes" => true
"strict" => true
"engine" => null
"options" => []
]
"pgsql" => array:12 [▼
"driver" => "pgsql"
"url" => null
"host" => "localhost"
"port" => "3306"
"database" => "crf_db"
"username" => "cfr_usr"
"password" => "specialpassword"
"charset" => "utf8"
"prefix" => ""
"prefix_indexes" => true
"search_path" => "public"
"sslmode" => "prefer"
]
"sqlsrv" => array:10 [▼
"driver" => "sqlsrv"
"url" => null
"host" => "localhost"
"port" => "3306"
"database" => "crf_db"
"username" => "cfr_usr"
"password" => "specialpassword"
"charset" => "utf8"
"prefix" => ""
"prefix_indexes" => true
]
]
"migrations" => "migrations"
"redis" => array:4 [▼
"client" => "phpredis"
"options" => array:2 [▼
"cluster" => "redis"
"prefix" => "laravel_database_"
]
"default" => array:6 [▼
"url" => null
"host" => "127.0.0.1"
"username" => null
"password" => null
"port" => "6379"
"database" => "0"
]
"cache" => array:6 [▼
"url" => null
"host" => "127.0.0.1"
"username" => null
"password" => null
"port" => "6379"
"database" => "1"
]
]
]
i noticed that the username and database name is no present under the my sql section but it is present in othe others
@Danny971 When I run the same code dd(config('database')) I am seeing the username and password present in the cached config.
Since you have made changes to your setup have you run php artisan optimize or composer dump-autoload recently?
gych posted three commands a couple weeks ago and two of them might help here.
php artisan config:clear
php artisan cache:clear
@ryangurnick now I see the database and username but still wont login
@Danny971 Does wont work mean it is not showing up when running dd(config('dashboard'))?
@Danny971 Can you tryin changing DB_HOST=localhost to DB_HOST=127.0.0.1 in your .env file.
Then run php artisan optimize from your terminal within the application directory. That might help...
@ryangurnick I mean not being able to login in
@ryangurnick did that no luck still wont login in
if you see username, why post a dump with it missing?
i noticed that the username and database name is no present under the my sql section but it is present in othe others
What relevance is that at all? your database is mysql. only that section is of interest. Where is username
before you had username and password missing, but now only username. WHAT ON EARTH ARE YOU DOING?
another critical question here, Is your database hosted on the SAME server as your website?
@Snapey that was earlier on, now I can see the username and database name. both laravel app and database are on the same compute engine vm
@gych @snapey @ryangurnick I just did another test both on compute engine and on my local host
here is the code i placed in my login function in my AuthManager.php
$data = DB::table('users') ->get();
dd($data);
it show me all the users and data related to the user on the local host but on the compute engine vm i get
could not find driver
SELECT * FROM `users`
so this tell me the db is not connected to the laravel application
Please or to participate in this conversation.