4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

・Address already in useの解決方法

Last updated at Posted at 2020-04-27

はじめに

PHPを学習していた時に、サーバーを起動したら...
以下のように出たので、対処法をまとめておきます
初めて書いて読みにくいかもしれませんが誰かの助けになれば、幸いです

[vagrant@localhost]$ php -S 192.168.33.10:8000
Failed to listen on 192.168.33.10:8000 (reason: Address already in use)

原因

PHPのサーバーを切らすにputtyのターミナル閉じてしまったことで、
サーバーは使われている状態になり、起動時にエラーが起きてしまった

解決してからもこれをやるとコマンドを打つのがなかなか面倒くさいので、
サーバーは切ってから閉じることを強くおすすめします

解決方法

# rootユーザーでログインしてプロセスの確認
//rootログインがめんどくさい方はコマンドを打つ時にsudoを付けてください
[vagrant@localhost ~]$ ps -a


# portがわかる場合は以下で確認
[vagrant@localhost ~]$ lsof -i:8000


# lsofできない場合は以下でインストール
[vagrant@localhost ~]$ yum -y install lsof


# 上記のコマンドを打つと以下のようにPIDを含んだ起動しているサーバー情報が表示されます
COMMAND  PID    USER     FD   TYPE  DEVICE  SIZE/OFF NODE  NAME
php      10721  vagrant  3u   IPv4  20710     0t0    TCP   192.168.33.10:irdmi (LISTEN)


# kill (PID番号)を入力してプロセスを終了
[vagrant@localhost ~]$ kill 10721


# 改めてコマンドを打つと起動します
[vagrant@localhost ~]$ php -S 192.168.33.10:8000 
PHP 5.6.40 Development Server started at Mon Jan  6 12:21:24 2020 Listening on http://192.168.33.10:8000


# killしても解決できない場合は kill -9 (PID番号)で強制終了してください
[vagrant@localhost ~]$ kill -9 10721 

おわりに

今回はkillコマンドについて書きましたがもっと知りたい方は
killの文字をクリックしてもっと詳しい情報を確認してください
ご指摘がございましたら、コメントしていただければ幸いです!!
最後まで読んで頂きありがとうございました

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?