Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

beyond's avatar

How to deploy separate react frontend app and laravel api backend?

have a separate react frontend app and separate laravel api app. In development I connect them and everything works fine by server the react with npm start and laravel artisan: serve separately. But now I want to move to production, please how do I position the react build file and laravel file on the server panel to enable my react access the api route in laravel? Please I really need help with this and looking forward to hearing from you soon. Thanks in advance.

0 likes
7 replies
Wakanda's avatar
Wakanda
Best Answer
Level 10

create a subdomain a place your api in the subdomain directory and the place your frontend in main directory public_html

2 likes
webpluspk's avatar

Hello Mr. Loyd,

I did the same but it gives me the following error:

"Access to XMLHttpRequest at 'http://premierbackend.webpluspk.com/login' from origin 'http://premier.webpluspk.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."

Although the application is perfectly working on local WAMP but when I uploaded it online, it gives me the above error.

Please guide.

beyond's avatar

I truly still need hep on how to place the laravel folder on my cPanel to be able to get the api to api route php and return the expected data or will just upload the folder there and starts working? I have tries this and the API doest not even connect. please help me with this. Lokking forward to hearing from you soon.

webpluspk's avatar

Same error I am facing. My API doesn't accept connection request from React frontend and give me CORS error.

chiragxd's avatar

For the CORS issue, it is quite simple for me What I did was to go to cors.php and added my subdomain to 'allowed_origins' and made supports_credentials true It worked for me

Please or to participate in this conversation.