I just started to learn more about Laravel and I am confused about servers. When I run 'php artisan serve' in my project's folder, I can access my web project via localhost:8000. When I run npm run dev I can access via localhost:5173 - but I am not directed to my web project's landing page but to the welcome page of Laravel Vite. For me running 'php artisan serve' is the right option. So, now to my question(s): Did I do some kind of misconfiguration when setting up the project? Where is the difference between those two servers? Thank you for your answers! Robert
Php artisan serve - hosts your project on your local server. And 'npm run dev' command complies vite and it will track and update frontend modifications without reload.
Related
I have a Laravel Web Application, and it works just fine locally, using a local .env file that references the local database.
I have the same Laravel Web Application deployed in production, where I find a .env, which is different from the one that I use locally.
Both the scenarios work perfectly, but when I wanted to perform a test with the remote database (that I can access from my local IP address), I copied the remote .env and renamed it .env.production.
How can I run the php artisan serve using the .env.production ?
The php artisan serve help states that adding a --env parameter should make the trick, as you can see from the command result below
php artisan serve --help
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 Force ANSI output
--no-ansi Disable 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
but the command php artisan serve --env=production still loads the local database.
What am I doing wrong ?
After some tests I found a working solution in a Laracast Forum, giving credits to a Laravel.io post that consists into running the following command:
APP_ENV=production php artisan serve
This causes the .env.production to be loaded and used by the local server, as needed.
I post this here hoping it will be useful to someone in my same condition.
before i start, i need to say that i'm aware that this question is a beginner's one.
I've found this dashboard combination of Laravel and Vue.js that i wanted to play with, to then start developing a real web application. laravue
There's just a single question that is confusing me: while testing it on xampp with the commands "npm run watch" and "php artisan serve" i see myself obliged to npm run the project, every time i make a file change.
So what is the right way to check all the changes i make? By just refreshing the browser window.
Thank you for all the responses.
I've solved the problem by running "npm run watch" and "php artisan serve" on two separated command-line windows.
Was totally unaware of that and it's part of the learning curve.
Thank you, this is now solved.
npm run watch automatically builds your assets and then watch any save on the concerned files. Whenever a save happens, npm run watch rebuilds everything, but you won't be aware on your web browser except by refreshing.
P.S: Sometimes npm run watch does not work well, then use npm run watch-poll instead
https://laravel.com/docs/7.x/mix#running-mix
npm run watch or npm run watch-poll will automatically rebuild your assets but don't apply to the browser without manual refresh. Meaning you have to reload browser after compiling done.
Hot Module Replacement(HMR - or Hot Reloading) works same as npm run watch and apply changes to browser automatically, so you don't have to reload browser to see the changes.
Following this document, HRM works well with the fresh installation (latest code on master) as my test.
npm run hot result:
➜ npm run hot
> laravue#0.11.0 hot [src]
> cross-env NODE_ENV=development BABEL_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js
ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from http://localhost:8080/
ℹ 「wds」: Content not from webpack is served from [src]/public
ℹ 「wds」: 404s will fallback to /index.html
php artisan serve result:
➜ php artisan serve
Laravel development server started: http://127.0.0.1:8000
And browser:
I have created(installed composer create-project laravel/laravel basicwebsite) project named basicwebsite.
After that i run php artisan serve then it showed some URL then i got LARAVEL page in browser,fine.
(Accidentally, my system is shut down.)
To reopen the project ,in cmd prompt i just did as
php artisan serve
and the error occur is
I almost searched for solution in all websites(including stack) .All started with create project but not what to do after close and opened the project.
Thanks in advance.
Use php artisan config:clear command to clear cache. You should see
Configuration cache cleared
Use php artisan serve command to start the server.
I know this might sound really silly, but I'm kinda stuck and need help. I'm trying to use Laravel 5.3 and use Homestead as my IDE. I have previously worked on PHP using NetBeans and XAMPP, but the installation has always been a pain. I have no formal training and have learnt and used basic PHP on my own for my webpages.
I'm running a Windows 8-32Bit OS & here's what I've done so far:
I have downloaded Laravel using Composer.
I have installed Virtual Box & Vagrant.
I have installed Git Bash and ran vagrant box add laravel/homestead (Homestead.yaml was not found in my Homestead folder after running bash init.sh command. I downloaded it from Github and added there).
Set SSH Key.
Ran vagrant up in Homestead folder (the installation was complete).
Issues:
If I just type http://localhost:8000 in my browser, nothing happens. I have to run php artisan serve in the command prompt inside laravel directory and keep the prompt window open for the default Laravel 5 page to open.
If I type http://127.0.0.1:8000 in my browser, nothing happens at all.
So how do I use Homestead then for my development everyday ?
you can try
localhost/project-name/public
if you dont want to run php artisan serve
For previous versions of Laravel, you can simply download laravel with composer in the root folder of your apache server and type in http://localhost/public/ to see the "You've arrived" homepage.
I know I can use php artisan serve to view the Laravel5 default home page, but it is run on localhost:8000 and I heard that php artisan serve command should not be used in production due to the limit of connection and the bad performance. Is there a way I can see the default home page without using the php artisan serve command?
And it is really frustrating that Laravel is not including such simple thing in their installation documentation....
To run the service on another port you need to pass the port parameter with port numberusing this code on the cmd:
php artisan serve --port=80
To run on port 80, you might need administrator permission.
You may have to use sudo command for admin rights.
sudo php artisan serve --port=80