3

I am developing a website using Laravel as backend and Vue.js 2 as frontend. Now everytime i want to run my website I have to use 2 command:

php artisan serve

This will run the laravel server on port 8000

npm run dev

This will run the vue.js server on port 8080

Can I just run them on the same server (same port), with just one command only??

2
  • 1
    Not unless you tightly couple your vue code into laravel and use a watcher to rebuild the code instead. If you're using Laravel as strictly an API, then this is not possible. Commented Jun 21, 2018 at 14:32
  • 2
    No, you need two different ports for each server. But why do you need to run server for vue.js if you are using it for Laravel app? Commented Jun 21, 2018 at 14:35

1 Answer 1

3

If you use the Laravel app with Vue.js included in it, you don't need to run npm run dev.

In your case, you seem to have a decoupled frontend and backend. In that case, you don't really have the choice to host 2 different ports or hostname.

You can use the same port if you use a different domain. For example, you can use mydomain.com for the frontend and use api.mydomain.com for the backend/api.

Assuming you have a webpack frontend project, you can do npm run build, which will compile all your files to static html files in the dist folder. You then only need to point your host configuration file to this folder.

Sign up to request clarification or add additional context in comments.

3 Comments

I got it. Thank you for your help!
what do you mean by included? I have vue app in same folder as laravel project but still runing 2 servers - npm run serve and nginx for laravel.
If I remember correctly, at the time of writting this, Laravel would serve assets through the same server than Laravel. The assets would still be built with laravel-mix (webpack wrapper) but served through Laravel using muliple Laravel blade pages that includes the built assets (not an SPA). I think this approach may have changed or other options might have opened up since in the laravel ecosystem. In your case if you are running two seperate servers, that means you have an SPA which was not offered in Laravel at the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.