Fokwa Best
Fokwa Best

Reputation: 3515

Unable to start laravel development server on linux

I am using laravel 5 for my project and everything has been working fine but recently I am facing this problem which I done understand.

devboy@devboy-hp ~/sonel_ims_project/ims_eneo $ php artisan serve
Laravel development server started on http://localhost:8000/
[Fri Nov 13 12:00:56 2015] Failed to listen on localhost:8000 (reason: Address already in use)

I have tried devboy@devboy-hp ~ $ sudo netstat -plnt and get

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1840/dnsmasq    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1985/cupsd      
tcp        0      0 127.0.0.1:8888          0.0.0.0:*               LISTEN      7563/php-5.6.3  
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1656/master     
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      6966/httpd      
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      740/smbd        
tcp        0      0 127.0.0.1:6942          0.0.0.0:*               LISTEN      7442/java       
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      6931/php-5.6.3  
tcp        0      0 0.0.0.0:6667            0.0.0.0:*               LISTEN      1539/ircd       
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      740/smbd        
tcp        0      0 127.0.0.1:63342         0.0.0.0:*               LISTEN      7442/java       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6966/httpd      
tcp6       0      0 :::21                   :::*                    LISTEN      7337/proftpd: (acce
tcp6       0      0 ::1:631                 :::*                    LISTEN      1985/cupsd      
tcp6       0      0 :::3128                 :::*                    LISTEN      1416/squid3     
tcp6       0      0 :::25                   :::*                    LISTEN      1656/master     
tcp6       0      0 :::445                  :::*                    LISTEN      740/smbd        
tcp6       0      0 :::3306                 :::*                    LISTEN      7343/mysqld     
tcp6       0      0 :::139                  :::*                    LISTEN      740/smbd  

Then I change port like so php artisan serve --port="8888" but get similar error like below after a while:

Laravel development server started on http://localhost:8888/
[Fri Nov 13 12:01:02 2015] Failed to listen on localhost:8888 (reason: Address already in use)

The first time it happened, it was java using port 8000, so I killed the process and started the server and it worked. Upon stopping and restarting, I get the same error. What could be the problem (as I said everything has been working fine except now and I have not done any major update)?

Upvotes: 4

Views: 19089

Answers (7)

Haron
Haron

Reputation: 2619

This can happen when there is already an app running on 127.0.0.1:8000

You can close that app then it will work or not available on the current host.

OR if you want to run multple apps then use shown below way:

You can use this command to run sudo php artisan serve --port=8082 for Linux

                        php artisan serve --port=8082 for window

Upvotes: 0

Shabeer K
Shabeer K

Reputation: 1617

Run this comment

sudo netstat -plnt

The output will show like this

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name 
tcp       14      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      3648/php7.3  

Then kill the port:8000 using this comment

 kill -9 3648

Upvotes: 1

Tadiwanashe
Tadiwanashe

Reputation: 1304

Well the problem might be it didnt stop the expected way previously eg via CTRL+C so what you can do is to check for running php processes and kill them 1 by 1.

i) Run ps -A from the terminal then identify the php process ids (most of the times they are two)

ii) Run sudo kill -9 pid# corresponding to the php pids.

iii) Run php artisan serve and it will work.

Upvotes: 0

Gujarat Santana
Gujarat Santana

Reputation: 10544

Your previous deployment in your local is already running that's why you can't run php artisan serve. You can solve your issue by following this command in your terminal:

  1. ps -ef | grep php you'll see this list:

    gujarat 6690 3500 0 05:55 pts/1 00:00:00 php artisan serve
    gujarat 6694 6690 0 05:55 pts/1 00:00:00 sh -c '/usr/bin/php5' -S localhost:8000 '/home/gujarat/WebDevelopment/quickstart-basic'/server.php
    gujarat 6695 6694 0 05:55 pts/1 00:00:00 /usr/bin/php5 -S localhost:8000 /home/gujarat/WebDevelopment/quickstart-basic/server.php
    gujarat 7436 3500 0 06:26 pts/1 00:00:00 grep --color=auto php

  2. Now kill it using: sudo kill 6690 if still exist then use this sudo kill -9 6690 you'll see this result:

    [1]+ Killed php artisan serve

Now you can serve your local using php artisan serve again

Upvotes: 10

Fokwa Best
Fokwa Best

Reputation: 3515

This is exactly what I did for the problem.

  1. I exit PHPStorm
  2. sudo netstat -plnt
  3. kill 7563 (Process using port 8888)
  4. kill 6931 (Process using port 8000)
  5. sudo /opt/lampp/lampp restart (Restart my server altogther)
  6. php artisan serve
  7. Launch PhpStorm

Now everything is working fine. What caused the problem anyway?

Upvotes: 3

Sudhakar Annadurai
Sudhakar Annadurai

Reputation: 136

please restart apache server

sudo apache restart

And once again run your project in another port

php artisan serve --port=2020

Upvotes: 3

user2182349
user2182349

Reputation: 9782

Using lsof, you can see what is listening on the port.

sudo lsof -i :80

Change the 80 to whichever port you're interested. You need to be root or sudo.

Upvotes: 1

Related Questions