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

KoningKev's avatar

Switch from windows to linux (default localhost doesnt work, but using 127.0.0.1:8000 does.

Hey guys,

So i recently made the switch going from windows to Linux Fedora. I was having too many issues with windows that took a lot of time solving which took me away from being able to learn how to work with laravel. (botched installations, node issues etc etc. all my fault, but here we are.). I also generally enjoy linux more in its speed and overall looks.

The issue i am having, or more so not understanding is as follows:

If i artisan serve my application, i cant connect to it via the app url. I can manually enter the local host adress (127.0.0.1:8000). However, when i try to connect to it via the app url i get an error that the site cannot be reached.

I tried putting my app in a docker container and run it via there. Then i get everything to work, but i am unable to use registration/login forms.

I am a complete beginner with running this on linux and was simply wondering if anyone has tips or tricks getting it to work. Or if this is just normal and it only gets the url when the app goes in to a production mode?

Thanks in advance, looking foward to your response!

Kevin.

0 likes
9 replies
LaryAI's avatar
Level 58

Hi Kevin,

The issue you're experiencing is likely related to how the hostname localhost is resolved on your Linux system. When you use php artisan serve, it defaults to binding the server to 127.0.0.1, which is the loopback address. However, if localhost is not correctly mapped to 127.0.0.1 in your system's configuration, you might encounter the issue you're describing.

Here are a few steps you can take to resolve this:

  1. Check the /etc/hosts file:

    Open your terminal and check the contents of the /etc/hosts file. This file should have an entry that maps localhost to 127.0.0.1. You can view the file using a text editor or by running:

    cat /etc/hosts
    

    You should see a line like this:

    127.0.0.1   localhost
    

    If it's missing or incorrect, you can edit the file with a text editor (you might need superuser privileges):

    sudo nano /etc/hosts
    

    Add or correct the line to ensure it reads:

    127.0.0.1   localhost
    
  2. Clear DNS Cache:

    Sometimes, DNS caching can cause issues. You can try clearing the DNS cache. The method to do this can vary depending on your Linux distribution, but a common way is to restart the nscd service:

    sudo systemctl restart nscd
    

    If nscd is not installed, you can install it using your package manager, or you might be using a different caching service like systemd-resolved.

  3. Use php artisan serve with a specific host:

    You can explicitly tell Laravel to bind to localhost when you run the server:

    php artisan serve --host=localhost
    

    This ensures that the server is listening on localhost as well as 127.0.0.1.

  4. Check Firewall Settings:

    Ensure that your firewall settings are not blocking connections to localhost. You can check your firewall rules using:

    sudo iptables -L
    

    Or if you're using firewalld:

    sudo firewall-cmd --list-all
    

    Make sure that there are no rules blocking traffic to localhost.

By following these steps, you should be able to resolve the issue and access your Laravel application using localhost. If you continue to experience issues, consider checking your network settings or any additional software that might be affecting hostname resolution.

Good luck, and enjoy your development on Linux!

vincent15000's avatar

You just have to add a new host alias in the /etc/hosts file.

127.0.0.1        localhost
1 like
jayandholariya's avatar

Check Firewall/SELinux: Ensure your Fedora system’s firewall or SELinux isn’t blocking connections to your app. You can temporarily disable SELinux for testing

sudo setenforce 0

You can also use

php artisan serve --host=0.0.0.0 --port=8000

This makes your application accessible on:

http://127.0.0.1:8000

http://localhost:8000

2 likes
jlrdw's avatar

I suggest using either apache or nginx in development.

2 likes
KoningKev's avatar

Thanks everyone!

With some tinkering and trial and error i got it to work! Thanks for the support!

Please or to participate in this conversation.