Search code examples
wordpresssymfonyreactjsvirtualhostlamp

Need To Run Symfony + ReactJS & WordPress Together


For our project we decided for a Symfony app and a WordPress blog. It basically runs an entire installation of WordPress as a subdirectory called /blog inside the /web folder of Symfony.

We setup a quick coming soon page on www.example.com/ (Symfony Route: /) and kept running WordPress blog on www.example.com/blog/

Details about that setup on my question about WordPress as a Symfony subdirectory: WordPress As A Symfony (Symfony3) Subdirectory

Over the course of development we let Symfony power the REST API and developed the application frontend with ReactJS. I am very unsure about the deployment. How will this work?

Note: I can't display WordPress as a React frontend and WordPress REST API because over 200 posts are now designed using a page builder provided by the theme (Lesson learned).

What options do I have?


Solution

  • You have to create a minified version of the React app and load it from a twig template. If you are using any react router, you will have to deal with the base url of your panel to make the urls be valid.

    For instance, if you develop with a local server: localhost:3000/my/fancy/panel

    in production can happen that this url becomes

    www.yourdomain.com/users/panel/my/fancy/panel

    You you have to configure your router and routes to prefix /users/panel in production environment.

    In my case I inject that base url in the tpl or twig and the app doesn't need to care about the environment.

    Your app needs to display the Wordpress posts?