This is a template to allow for client-side React single-page applications running on top of a PHP API server. A lot of domain hosting services only offer PHP, so this is a good way to develop a React application that works well with the PHP server.
Install PHP 7.x, nodejs (LTS release preferred), yarn 1.x on your computer.
In one terminal, run:
$ yarn start:server
In another terminal, run:
$ yarn start:client
$ yarn deploy
- The PHP server listens at port 4001 for any PHP-specific requests. At the moment, this includes:
/api
: any API calls/custom-php
: a test area for serving custom PHP
- Any additional custom PHP endpoints need to be manually added to
src/setupProxy.js
- The CRA dev server is served at port 3000 for the React development build.
When built, the React SPA files are located under the build/
directory. Before deploying, we move all files under the server/
directory into build/
, and deploy the build/
directory.
- Any links to parts of the tree that are outside the React Router tree need to be
<a>
anchors, since we need to reload the page and not simply set the URL. This shouldn't be a problem because elements outside of the React tree should be separate anyway.
- Customizable branch for deployment