I am trying to run a laravel project in my local machine. It starts normally on http://127.0.0.1:8000 but when I try to open the url in the browser the port changes to 8001 and the new url is http://127.0.0.1:8001. When I try to open this in the browser, again the port changes to 8002.
Image showing the issue
composer.json
My PHP version is 7.4.1. If anyone else faced this issue earlier or knows how to fix this issue, please help in fixing this issue.
Thank you.
Update 1:
Noticed something. Whenever database related code is executed, this issue is popping up. For example, when I try to execute the following code shown in the image, it runs smoothly and I can see the output in the browser. Case when the code runs smoothly
But when I change the code to the following, the issue shows up.
Case when the issue shows up. This is not any database heavy query but why this issue? Any leads would be very helpful.
Update 2:
Found nothing in laravel logs but found the following in the apache error log which is given below:
2
Answers
Try this parameter I think help you
This highly, might be a problem to the code, you’ve write-ed, not a
Laravel
problem. I’ve faced issues like this before for a long time ago, so you might check :As I said, my first guess is the code, so you might need to share the code find out, what is happening.
Also conflicts in reserved ports will be avoided anyway, for example if you set your local environment server to something else(8080), same issue will happen again.
And sometime if you close your terminal without closing local environment, new
php artisan serve
will run the local environment anyway, for example, my terminal/IDE was closed but application was serving, and doingphp artisan serve
not forced me to close and run a new local environment like yours, it was trying to serve again, but old one was doing conflicts.So as I said again, it might be a code issue.
Double check your code or share it to find the issue.