How to run "php artisan serve" on local network - laravel

enter image description hereMe and a classmate are working on an online shop. We must share our progress and started using Dropbox but it was too slow. We tried connecting our PCs through a local network, he shared the project in a "Public Access" folder so I can read and edit files but when I run the php artisan serve command I have this message saying UNC routes are not supported.
I have a similar problem with the npm run dev/watch because it searches for a file in "C:" but I'm not on C:
I tried changing the command to php artisan serve --host 0.0.0.0 --port 80 and also changing the host and port as well but it didn't worked. Also tried to run both commands on PowerShell, I read that it support UNC routes but it threw the same error. I'm desperate 'cause it's been like 4 hours and the Dropbox files aren't ready. About the npm problem I didn't find a useful answer. Sorry for the bad english

for windows
php artisan serve --host your-ip-add --port 8000
e.g
php artisan serve --host 192.168.1.001 --port 8000
For linux use
sudo before command
and try to be on same network

Related

Vite network URL opens Vite development server in Laravel application

When I run vite run dev --host in my Laravel project, I get below screen on my external network URL:
My external URL is: http://192.168.1.6:5173
➜ Local: http://localhost:5173/
➜ Network: http://192.168.1.6:5173/
Project runs fine on my app URL defined in Laravel's .env file viz. http://trip.dev
I am expecting http://192.168.1.6:5173/ to work same as http://trip.dev
I tried php artisan serve (as suggessted in the above screen to run the local development server), but it keep showing me the same screen.
Can some one help me in this?
You should run php artisan serve --port=8000 in a command prompt and run vite run dev --host or npm run dev in other command prompt.
now, you need to open http://YOUR_IP_IN_NETWORK:8000; for example if your ip is 192.168.1.6, you should open http://192.168.1.6:8000.
tip:
Make sure you use #vite('...path...') in your code to use vite.

Change from Laravel LocalHost Server to APP_URL .test

So I use the command PHP artisan serve to run a server and I can view my Laravel site at http://127.0.0.1:8000/ but I want to run my website at the
APP_URL= 'http://projectName.test' how can I do this? I see a lot of videos online where it just spins up that way automatically.
MySQL
Win11
XAMP
You can set up a virtual host to run the project on the custom URL in localhost.
this link is an example of defining a virtual host.
Use this:
php artisan serve --host=projectName.test --port=80
Also this is serve manual:
Description:
Serve the application on the PHP development server
Usage:
serve [options]
Options:
--host[=HOST] The host address to serve the application on [default: "127.0.0.1"]
--port[=PORT] The port to serve the application on
--tries[=TRIES] The max number of ports to attempt to serve from [default: 10]
--no-reload Do not reload the development server on .env file changes
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
change host file parameter like:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 projectName.test
change directory to root project and run:
php artisan serve --host=projectName.test --port=80
Take a peek at Laragon. I think Laragon is a better choice than XAMPP. And in your case, using Laragon don't require you to run php artisan serve to run the app. Just turn on the Laragon, and your app will be able to be accessed from http://your-app.test (suffix can be changed). No additional configuration or changes needed.

Why is command php artisan serve not working anymore?

I am new to laravel development and have been migrating my web app to laravel for the past two weeks but suddenly my local server has stopped responding.
localhost:8000 does not load any page, previously it loaded my app's home page. Now, it looks like it is in an infinite request loop or something as indicated by the circle on the top of the tab.
I've tried the following solutions but still no luck:
php -S localhost:8000 -t public/
as referred here Why command "php artisan serve" not working
I have also tried other ports but I cannot successfully make a request to the server on those ports either
php artisan serve --port=8888
I have also run the code below to see which ports are active and kill those ports with the command below but starting the server after that still does not respond.
ps -ef | grep php
sudo kill some number
I think my issue is something deeper than switching the ports up because regardless of the port, I still do not get a server response.
However, if I whip up MAMP I do get a response from that server, if that helps.
Any thoughts?
If you had infinite request loop try another port like this:
php artisan serve --port: 8090

Laravel-Php artisan serve url (127.0.0.1:8000) vs localhost/laravelproject/public

I want to access my laravel project.I run php artisan serve and access the 127.0.0.1:8000 in browser.
But i learned that I can also check my project using the localhost/laravelproject/public url whithout running php artisan serve.
Question: What is the point of using php artisan serve?
No point in two different methods like you mentioned run laravel by "php artisan serve" and by "project url" followed by localhost. But advantage of "php artisan serve" is you can run you laravel project without putting in htdocs/www directory i.e servers root directory. You can put laravel project anywhere where you want and run through the artisan command.
I found some information you may find interesting:
https://www.quora.com/How-can-I-use-php-artisan-serve
But in simple words, php artisan serve is an easy way to create a php server and that is what laravel needs to run.
You could do the same with "php -S 8080 (which would start a php web server (single threaded) in the current directory on port 8080)"
Also if you have already a php server running with apache or nginx it would not be necessary any of the commands.
Hope you find this helpful.
The `Serve command is just a shortcut for the PHP Builtin Webserver, something PHP has out of the box, so the point of using it is to start testing your application as fast as you could, you just need to install PHP, Composer and your application is up (if you don't need anything else, of course). But if you already have Nginx installed, there is no point at all, just use it.
It's not wise to use the Builtin Webserver in production.

How to run multiple Laravel projects at same time?

To run one laravel project we only need to type "php artisan serve". and it will be available on port 8000.
But sometimes we need to run multiple projects at the same time. How can we do this?
tl;dr one cannot have more than one listener per TCP port at the same time. If you need more web server instances: try another port:
php artisan serve --port=8001
then go to http://localhost:8001
References:
Can two applications listen to the same port?
https://laravel.com/docs/8.x
You can also run web server on multiple port in PHP application by the following command.
php -S localhost:8000
php -S localhost:8080
First run your first laravel project blog as follows:
Open your command prompt and go to your drive where your laravel project exist.
And type php artisan serve
C:\xampp\htdocs\blog>php artisan serve
Now type http://localhost:8000 in browser and your blog project will run.
Again open another command prompt and again go to your another laravel project bloganother
C:\xampp\htdocs\bloganother>php artisan serve --port=8080
Now go to your browser and type http://localhost:8080 in your browser your another project will also run.
1- First thing you need to mention port number in .env file.
APP_URL=http://127.0.0.1:8001
2- Run php artisan serve --port=8001
Run first laravel project (with url: http://localhost:8000)
php artisan serve
Run another laravel project (with port specific url: http://localhost:8001)
php artisan serve --port=8001
Run one more laravel project (with port specific url: http://localhost:8002)
php artisan serve --port=8002

Resources