Set port for php artisan.php serve

Cover Image for Set port for php artisan.php serve
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

Setting a Custom Port for php artisan serve 🚀

So, you want to access different development sites on your localhost, each running on a different port? No worries! In this post, I'll walk you through the process of setting a custom port for php artisan serve command using some easy solutions. Let's dive in! 💻

The default port 🌐

By default, when you run the php artisan serve command, Laravel serves your application on localhost:8000. However, sometimes, you may need to use a different port to avoid conflicts or meet specific requirements.

Solution 1: Specify the port directly 🏁

You can simply specify the desired port when running the php artisan serve command by appending the --port flag followed by the port number. For example, to serve your application on localhost:8080, run the following command:

php artisan serve --port=8080

That's it! 🎉 Your Laravel application will now be accessible at localhost:8080.

Solution 2: Use the built-in server configuration ⚙️

If you frequently need to serve your application on a specific port, you can modify the default server configuration provided by Laravel. To do this, open the ./config/serve.php file in your Laravel project.

Within this file, you'll find an array that specifies the default options for php artisan serve. Locate the port key and update its value to your desired port number. For example:

<?php

return [
    'port' => 8080,
];

Save the changes, and now every time you run php artisan serve, Laravel will automatically use the port you specified in the configuration file.

Solution 3: Using the .env file 📁

If you prefer a more flexible approach and don't want to modify the server configuration, you can utilize your .env file. Open the .env file in your Laravel project and add the following line:

APP_URL=http://localhost:8080

Save the changes and run the php artisan serve command. Laravel will pick up the APP_URL value from the .env file, so your application will be served on the specified port.

Wrapping up 🎀

Congrats! You now know how to set a custom port for php artisan serve in Laravel. Whether you prefer specifying the port directly, modifying the server configuration, or using the .env file, you have different options to choose from based on your needs.

Now, go ahead and start serving your Laravel applications on the desired ports! 🚀 If you have any questions or run into any issues, feel free to leave a comment below. Happy coding! 😄


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my

Matheus Mello
Matheus Mello