24

I'm looking to rewrite an old website using React.js for my frontend framework and PHP for the little backend stuff I may need.

The server I'm using is IIS with Apache, but I have little/no SSH access/ability to install stuff on the machine (i.e. npm, node, etc.), so I'm restricted to using PHP as a backend (so I can't build/compile my React JSX serverside). However, couldn't I simply just upload built/compiled my react files to the server?

I have seen this, but I'm not entirely sure that I need it?

Basically, my question is, is using these two together practical? Would I need any other tools to accomplish this? (The website is likely to be pretty small.)

2
  • 5
    Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. I would suggest that you find a development forum (perhaps quora?) to work out generalities. Then, when/if you have specific coding issues, come back to StackOverflow and we'll be glad to help. Commented Jul 10, 2015 at 20:42
  • i'm in a similar position in that my application is hosted on an apache server and i'm restricted to php. i would like to use php to perform simple tasks, e.g. submit a contact form. server side rendering is not currently my aim. is it possible serve an index.php file which is loading my application's bundled application and within that script, generate a form which has an action that runs a php script? Commented Jan 9, 2017 at 15:06

1 Answer 1

24

I've used PHP and React together briefly (and then moved on to isomorphic React). Running V8 with PHP is only useful if you need server-side rendering (for fast initial loading and easy SEO), but I've not tried it so I'm not sure whether it's stable/reliable enough. If you do not care about server-side rendering, then you can just build the React app and include it in your PHP view.

Basically, the PHP view would serve as a layout, with a React container element defined so that your React app can bootstrap with it.

You can also pre-fetch the initial data for the React app with PHP and somehow attach it to your PHP view. The simplest way would be to use a script block to assign the JSON-serialized data to a global variable. Another way would be to define element(s) and attach your JSON-serialized data as element attributes, to avoid globals. Either way, you'd have your Flux stores bootstrap with those initial data to avoid having to hit APIs before the app can load.

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

1 Comment

Check github.com/reactjs/react-php-v8js if you do want server side react rendering

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.