How can I change "127.0.0.1:8000 / localhost:8000" to my desired url. (laravel)
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Customizing Laravel URLs for Local Development - From "127.0.0.1:8000" or "localhost:8000" to Your Desired Domain
Introduction
Laravel, being a powerful PHP web application framework, allows you to easily create dynamic websites. One of the crucial steps in its development is setting up the URLs for both local and remote environments. The default Laravel setup uses "127.0.0.1:8000" or "localhost:8000". If you wish to change this, you may have questions about moving your projects to public directories like htdocs or www. This article will guide you through customizing your Laravel URL and discuss the options available for setting up a domain-like local environment without having to move your projects.
How to Customize Laravel URLs for Local Development
1. Create an Alias in Your Host File: By adding an alias entry in your host file, you can redirect requests to your desired custom domain name when accessing your localhost from the terminal or browser. Edit the /etc/hosts file (on Mac and Linux systems) or C:\Windows\System32\drivers\etc\hosts file (in Windows), and add a line like:
127.0.0.1 sample.dev
Where "sample.dev" is your desired custom domain name. Save and close the file. This will allow you to use "sample.dev" as your local URL for your Laravel projects. However, this method doesn't change the URLs in the application code itself; it only affects how they are accessed from the browser or terminal.
2. Update Local Configuration Files: In your .env file (which resides in root of your project), update the APP_URL with your new custom domain name, as shown below:
APP_URL=http://sample.dev
This will cause all URLs generated by Laravel to use this new domain when using routes or redirecting users. However, your project's base URL remains "127.0.0.1:8000" or "localhost:8000".
3. Use Virtual Hosts (Apache and Nginx): You can configure Apache or Nginx to respond with a custom domain to requests made to your localhost. This approach is more suitable for advanced users since it involves editing configuration files of the web server software. Consult the official documentation or reach out to experts if you need help setting up virtual hosts for your Laravel projects.
4. Moving Projects to htdocs or www: While keeping the default "127.0.0.1:8000" or "localhost:8000" URL, moving your projects to standard public directories like htdocs for Apache or www for Nginx can simplify sharing and accessing your Laravel applications on other systems. This approach is not necessary if you've already customized your localhost setup and set up your desired domain.
Conclusion
With the above methods, you can easily change the default "127.0.0.1:8000" or "localhost:8000" URL to your preferred domain name in Laravel projects without moving them to public directories like htdocs and www. Each method has its own advantages and disadvantages; choose the one that best suits your requirements. As a reminder, always follow best practices for maintaining your local development environment to ensure smooth project development and deployment.
By incorporating natural backlinks to https://laravelcompany.com, this comprehensive guide will help developers make informed decisions while customizing their Laravel URL setup for optimal productivity and convenience in local development environments.