Abaij
Abaij

Reputation: 873

Get php_network_getaddresses: getaddrinfo failed: Name or service not known in laravel 5.8

I get the following error when I upload my app to my hosting.

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from `sessions` left join `proyek` as `p` on `p`.`id_proyek` = `sessions`.`project_id` where `user_id` is null limit 1)

I don't know why this error comes up while in my localhost works well. I believe that it is caused by $session = Session::where('user_id', Auth::id())->first(); in AppServiceProvider.php. I know it because when I commented it out, the app is working well. Here is the code:

    <?php
    // app/Providers/AppServiceProvider.php

    namespace App\Providers;

    use App\Models\Session;

    use Illuminate\Support\Facades\Auth;
    use Illuminate\Support\ServiceProvider;

    class AppServiceProvider extends ServiceProvider
    {
        /**
         * Bootstrap any application services.
         *
         * @return void
         */
        public function boot()
        {

            view()->composer('*', function ($view) {

                $session = Session::where('user_id', Auth::id())->first();

                $view->with('active_project', $session);
            });
        }

        /**
         * Register any application services.
         *
         * @return void
         */
        public function register()
        {
            //
        }
    }

I have tried to run php artisan config:clear, php artisan cache:clear but still get it.

Upvotes: 2

Views: 6903

Answers (1)

Abaij
Abaij

Reputation: 873

Apparently the problem is caused by misconfiguration in my database.php file. My host was set to host => 'http://mysqlserver.com'. I changed it to host => 'mysqlserver.com' then it works. Hope it will help for them who did a stupid thing like me.

Upvotes: 4

Related Questions