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

Joat's avatar
Level 1

php artisan error

Please, i have been encountering this error in my command prompt while trying to serve my project, ps i'm new to laravel.

PS C:\ UniServerZ \www \chat-app > php artisan serve Failed to listen on 127.0.0.1:8000 (reason: ?) Failed to listen on 127.0.0.1:8001 (reason: ?) Failed to listen on 127.0.0.1:8002 (reason: ?) Failed to listen on 127.0.0.1:8003 (reason: ?) Failed to listen on 127.0.0.1:8004 (reason: ?) Failed to listen on 127.0.0.1:8005 (reason: ?) Failed to listen on 127.0.0.1:8006 (reason: ?) Failed to listen on 127.0.0.1:8007 (reason: ?) Failed to listen on 127.0.0.1:8008 (reason: ?) Failed to listen on 127.0.0.1:8009 (reason: ?) Failed to listen on 127.0.0.1:8010 (reason: ?)

i dont think any of the port is being used. even if i change the port, i still get that kind of error. i dont know what im doing wrong at all.

note: i'm using Uniserver.

Please i need a solution. Thanks

0 likes
15 replies
Joat's avatar
Level 1

@vincent15000 I dont have them used, basically all the ports i tried are showing this.

Nakov's avatar

What about if you run php -S localhost:8000 -t public/ ?

1 like
Joat's avatar
Level 1

@Nakov I have run that, the terminal showed me this,

PS C:\ UniServerZ \www \ chat-app > php -S localhost : 8000 - t public /
[Fri Sep 20 16:00:27 2024] PHP 8.3.0 Development Server (http: // localhost : 8000) started [Fri Sep 20 16:00:44 2024] [::1]:61634 Accepted [Fri Sep 20 16:00:44 2024] [::1]:61635 Accepted [Fri Sep 20 16:00:50 2024] [::1]:61635 [500]: GET / [Fri Sep 20 16:00:50 2024] [::1]:61635 Closing [Fri Sep 20 16:02:41 2024] [::1]:61634 Closed without sending a request; it was probably just an unused speculative preconnection [Fri Sep 20 16:02:41 2024 ] [::1] : 61634 Closing

then when i went to localhost:8000 i'm seeing some kind of internal server error

this is the context;

could not find driver ( Connection : mysql, SQL : select * from sessions where id = hLITbounk3e5RiYBwEfJ9L6RmRUYWMJnV6BH4CoT limit 1)

Nakov's avatar

@Joat You need to run this two commands:

php artisan make:session-table
 
php artisan migrate

if you want to use database for the session driver.

1 like
Joat's avatar
Level 1

@Nakov It says migration already exists , nothing to migrate

1 like
Joat's avatar
Level 1

it's making reference to this line of code in vendor \ laravel \framework \ src \ ...... Connection.php

        throw new QueryException(
            $this->getName(), $query, $this->prepareBindings($bindings), $e
        );

then im seeing this error in the localhost:8000

could not find driver (Connection: mysql, SQL: select * from sessions where id = k8AydJa4eCnEY9liMtWOSqTtA0jz0zrALO7pwffW limit 1)

1 like
Joat's avatar
Level 1

@vincent15000 when i run that command of artisan migrate,

i get this error

Illuminate\Database\QueryException

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it (Connection: mysql, SQL: select table_name as name, (data_length + index_length) as size, table_comment as comment, engine as engine, table_collation as collation from information_schema.tables where table_schema = 'chatapp' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)

at vendor\laravel\framework\src\Illuminate\Database\Connection.php:825 821▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
822▕ ); 823▕ } 824▕ ➜ 825▕ throw new QueryException(
826▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 827▕ ); 828▕ } 829▕ }

1 vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:66 PDOException::("SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it")

2 vendor \laravel\framework \src\Illuminate\Database\Connectors \Connector.php:66 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=chatapp", "root", Object(SensitiveParameterValue), [])

1 like
vincent15000's avatar

@Joat That's another problem, Laravel seems to not being able to access the database.

Have you checked your credentials for the database in the .env file ?

Nakov's avatar

@joat since you said you are new to Laravel.. Have you tried with watching some course to learn the basics first instead of directly jumping and facing these type of beginner errors.

For example you can watch: https://laracasts.com/series/30-days-to-learn-laravel-11 it is a free course and it will cover lots of things. Also try to read the error, because it is English language. Try using another tool like Laravel Herd for Windows instead of WAMP..

Looks like the services you need to use are not available, so a connection cannot be made.

You can change in your .env file the DATABASE_CONNECTION=sqlite instead of mysql run php artisan migrate then, Laravel will offer to create the file for you, and you will be up and running.

1 like
Joat's avatar
Level 1

@Nakov Thank you for this resource, i have started the course already..

Snapey's avatar

Are you using a firewall?

Try changing your database connection to localhost instead of 127.0.0.1

1 like
hackerdintro's avatar

am having this same issue and i have already used the suggestion @nakov made to change in my.env file the DATABASE_CONNECTION=sqlite instead of mysql and i run php artisan migrate and this new error surface, 'could not find driver (Connection: sqlite, SQL: select name from sqlite_master where type = 'table' and name not like 'sqlite_%' order by name)',

vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:66 PDOException::("could not find driver")

2 vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:66 PDO::__construct()

now am lost and dont know where to focus now.

Please or to participate in this conversation.