1

I am working on my first web-project and therefore have an Ubuntu machine with apache2. I am quite new to web development and have never deployed a website before. I am sorry if this question sounds stupid, but what is the best way to serve a website with ReactJS front and PHP back end from the same machine? I am searching the web for days now and tried lots of possible ways, but none of them seamed to have worked as expected.

My very simplified folder structure is currently:

github-test
 ┣ build
 ┃ ┣ static
 ┃ ┃ ┣ css
 ┃ ┃ ┗ js
 ┃ ┣ asset-manifest.json
 ┃ ┗ index.html
 ┣ public
 ┃ ┗ index.html
 ┣ src
 ┃ ┣ App.js
 ┃ ┣ index.js
 ┣ server
 ┃ ┣ classes
 ┃ ┃ ┣ ActionsContr.class.php
 ┃ ┃ ┣ DBh.class.php
 ┃ ┣ includes
 ┃ ┃ ┗ getUsers.inc.php
 ┣ asset-manifest.json
 ┣ package-lock.json
 ┣ package.json
 ┗ README.md

Within this structure my apache2 serves the whole directory with package.json leading to:

homepage: 'build'

for production. I currently use this folder structure and server configuration, to allow apache2 to serve my php code. Unfortunately this changes my IP to

xxx.xxx.xxx.xxx/build

which seams neither elegant nor safe to me.

My first folder structure was to have a /client and /server directory in my project folder, which lead to a still longer IP address. I tried moving the server directory into the build folder, but as this folder gets deleted with every production build, this can not be the best option.

I was also thinking of using two VirtualHosts, one for front, one for backend, but I just could not get it running.

Tell me if you need further information. Thanks

Edit I got it running, my mistake was, to enable the port for the backend in ufw and a typo in the path in the back end VirtualHost. In the end I used two seperate folders (one for back and one for front), created two VirtualHosts on ports 80 (front) and 8080 (back).

georgleb
  • 11
  • 2

0 Answers0