64

I'm having a problem starting my Laravel installation. Whenever I type in the terminal php artisan serve, I get this error:

Failed to listen on localhost:8000 (reason:une tentative d'access un α socket de maniere interdite par ses autorisation d'access a 0t0 tent0e)

What's the problem, and how can it be fixed?

img problem https://i.stack.imgur.com/iIvn2.png

it's working now I just changed the listen port from 8000 to 8888 or any other port your services didn't use it

php artisan serve --port="8888"
starball
  • 20,030
  • 7
  • 43
  • 238
byacer
  • 643
  • 1
  • 5
  • 6

14 Answers14

147

Fixing Error: Failed to listen on localhost:8000 (reason: Address already in use)

List processes with php in it

ps -ef | grep php

Example output

501  **9347**     393    0  1:29PM ttys000    0:00.21 php artisan serve
501    9351    **9347**  0  1:29PM ttys000    0:02.01 /usr/local/php5-5.6.14-20151002-085853/bin/php -S localhost:8000 .../laravel/server.php
501    9781       393    0  1:56PM ttys000    0:00.00 grep php

Then kill the process

kill -9 9347

Community
  • 1
  • 1
mayorsanmayor
  • 2,870
  • 4
  • 24
  • 44
  • 23
    Use kill -9 9347 to force termination of the process. – user2340939 Jun 04 '16 at 08:29
  • This doesn't necessarily work if the application blocking you from using the port isn't php at all but some other application on your system. – Koen van den Heuvel Jan 10 '17 at 09:33
  • This works if you had a php artisan serve previously and you terminated it wrongly, as I did, for instance, by removing the folder while the server was executing. Then the only way to start serving again on ort 8000 is to kill the previous process. – Natxet Nov 14 '20 at 11:52
  • thanks my king, very helpful your answer =) – jonathasborges1 Oct 30 '22 at 00:08
34

Are there any other services running on port 8000?

You can use this command on Windows:

netstat -aon | more

or on Linux / OSX

sudo netstat -plnt

to see what services are running. Then disable the service that is running on port 8000 or use another port.

22

List process using ps -ef | grep php

Then below only works for me

kill -9 9347

which is a force kill of the process

501  9347   393   0  1:29PM ttys000    0:00.21 php artisan serve

Option 2:

If above not works, Change the default laravel serve port number if you can, like

php artisan serve --port=8088
Hemamalini
  • 741
  • 7
  • 9
10

8000 is the default port. Use instead of :

php artisan serve --port=8005
Nadim Tareq
  • 481
  • 6
  • 7
4

It is because something already running on that port and you can change the port by command itself, by running following command

php artisan serve --port 8001
Shahrukh Anwar
  • 2,544
  • 1
  • 24
  • 24
4

Use killall -9 php and if you want to close other services use killall -9 node or killall -9 mysql

Alex Quintero
  • 1,160
  • 10
  • 21
  • 1
    `killall -9 php` is very dangerous, for instance, it could kill your PHP storm also. It's better to first search for the process and kill it individually – Natxet Nov 14 '20 at 11:54
4

When php artisan serve command given, below mentioned problem occured.

macridmi1109@Ridmis-MacBook-Pro kcnk % php artisan serve

Laravel development server started on http://localhost:8000/

[Thu Aug 6 11:31:10 2020] Failed to listen on localhost:8000 (reason: Address already in use)

Then try this line of code,

macridmi1109@Ridmis-MacBook-Pro project_laravel % ps -ef | grep php

Result will be,

501 66167 1 0 11:24am ttys002 0:00.77 /usr/bin/php -S localhost:8000 /Users/macridmi1109/Documents/Laravel/project_laravel/server.php

501 66268 64261 0 11:31am ttys002 0:00.00 grep php

Finally run the below code and, then again php artisan serve

macridmi1109@Ridmis-MacBook-Pro project_laravel % kill 66167

SOLUTION EXPLAINED BELOW

I use the command, ps -ef | grep php. After that, you will be able to find Process ID. After recognising the correct Process ID, use this command kill 66167 (kill "Process ID"). Then try php artisan serve. This worked for me.

Happy Coding

macridmi1109
  • 61
  • 1
  • 5
1

The solution I found a problem we face several times in Ubuntu.

*Failed to listen on 127.0.0.1:8000 (reason: Address already in use)*

What we do, we change the port, right?

This problem can be solved also in few seconds following below steps.
1. Open Terminal
2. **sudo su**
3. **netstat -plnt**
_find the process running on port 8080_
4. **kill -9 PROCESSNUMBER**

For more details, see my blog, click here

1

For me, it was silly mistake. I have installed php in new machine but php.ini was missing. So, I have created php.ini file from php.ini-production file and then php artisan serve command worked fine as expected.

Devang Vaishnav
  • 73
  • 1
  • 1
  • 7
0

for me php -S localhost:8080 from the terminal in vs code will sometimes crash, but still be running in the background.

-9 to force kill did it for me thanks @hemss

I did

php -S localhost:8080

[Wed Dec 12 13:48:03 2018] Failed to listen on localhost:8080(reason: Address already in use)

then I..

sudo netstat -plnt

find the process running on port 8080

tcp        2      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      10312/php

then force kill it..

kill -9 10312

I get

[1]  + 10312 killed     php -S localhost:8080

then restart...

php -S localhost:8080
jasenmichael
  • 388
  • 5
  • 17
0

best way if you 8000 port is busy or you have more one project running is run your project in new port such as 8088 or another free port.

php artisan serve --port=8088
Omid Ahmadyani
  • 1,430
  • 13
  • 15
0

I got this problem too, and i succeed solved it in this way:

set: php.ini variables_order = "GPCS"

quangdang
  • 116
  • 7
0

I was implicitly specifing a --host=192.168.100.145:8000 which caused an error trying to connect to 192.168.100.145:8000:8000

fixed it with php artisan serve --host=192.168.100.145 --port=8000

PHANTOM-X
  • 502
  • 6
  • 16
-3

If you have all your configurations ok in the .env file then you should:

Use the answer from mayorsanmayor in this post to kill all php processes. Then php artisan config:clear

Finally, php artisan serve

Good luck!

Domingo
  • 165
  • 1
  • 4