Hybrid PHP and Node.js web applications

Hybrid PHP and Node.js web applications
https://medium.com/@MichalMecinski/hybrid-php-and-node-js-web-applications-7451b6a590bb

As im one of those guys that have a web application build in php with over 400 server actions already and some custom php in it… * (Disclaimer: this was done a few years ago with wappler started - to @JonL ) … so for me to redo everything will be a mission of note)

But I would be interested to use Nodejs to do 1 or 2 things in my application…eg real-time-data…

So this would be a great solution… if at all possible with Wappler…
@Teodor, @George please could you advise what would be the best solution if i want to take a few pages / server actions from my php model and make them Nodje.js?

  • Can i run it on my local machine with WAMP? and NodeJS at the same time?
  • Do I setup a NEW project to only handle the NodjeJS side of things… (* mostly for real time results) and still run php on the other pages
  • I really want to give nodejs a go… but i can’t drop the php site as its already so big…
  • So is this “hybrid” idea a reality for me as a Wappler user?

So can still keep my php site and only recreate 1 - 2 pages in nodjes and run them together on a server? a server that supports php and nodjs? Does it even work that way?

1 Like

Yes. But it’s not trivial. If you want to make them publicly accessible you will need to put a reverse proxy in front of both servers.

Seems the way to go.

It’s a nice project and you will learn something :slight_smile:

If by server you mean same machine host. Yes.

No.

No. PHP will be interpreted as an Apache module(standard setup) and Nodejs has it’s own server. As commented above if you are going to have both publicly available on port 80 you need to put a reverse proxy(nginx, traefik, etc) in front of them. If you are fine running nodejs server on another port(3000 is the default) because you are going to access it internally you could do it without a reverse proxy.

But I still recommend using a reverse proxy anyway.

1 Like

Thanks for the detailed reply… that is great!

1 Like

I guess the reality is… if I want real-time data… ill have to redo this complete project… ouchhhh…

It is worth it when its all done Mozzi. We just did the same and went from 90% PHP to full Docker/Node on multiple Projects. Its a journey of discovery and learning worth the effort and time. And I thank @JonL for this leap to Node (sincerely). Once done and dusted everything is very simple but your choices are ten fold for where you go from there. Not saying PHP holds you back… But Node is definitely the future (despite it being so new to us as a crew it has years in the game). Just my two Cents sir. :wink:

2 Likes

on that note… can the server actions be copied over…? or migrated or something… or will one have to redo all of them one by one…

I am not certain as I have never tried it, but if you were in a brand new node project and created a new server action and then opened your php projects server action and copied the JSON over and saved and refreshed the server action list, I would imagine it should be the same, however, I have never personally tried, just spitballing ideas.

1 Like

anway… i have a spare machine ill pull out of the cupboard… setup the latest version of Wappler beta 4… then start with the basics before i ask to many questions… let me learn the basics… :slight_smile: mmm for docker ? do i need windows 10 pro… or will the home version do… i think i saw something about docker not working in the home version… but that is ages ago… anyway. thanks so much… it will be a leap… but for the better… i guess… @JonL… ( i guess ill be joining the dark side now JonL … ahhahaha… another one getting converted… wonder what your telly is on this)

i was also thinking down those lines… but will still have to check every file

Am on bog standard Media Store grabbed copy of Windows 10 with Docker installed just fine. Very easy to set-up but be sure to follow each instruction to the letter, don’t jump any! You don’t need Docker to run Node though. But together they work great, and for the future moving a container over a stack is far easier, literally minutes to accomplish, where as we all know how difficult it can be with PHP sometimes, especially when many libraries have been installed on top by a Client/User!

As for using the same PHP actions in a Node Project am pretty sure it, unfortunately for now, is replication, one by one (ie you recreate them in the Node SC API directory). Life is made a little simpler by having two versions of Wappler running so copying and pasting between is a breeze, at least you can see the actions you’re replicating. Maybe @George could advise if there will ever be a conversion offered for PHP to Node? Maybe there is an alternative route to do this.

EDIT: When we undertook this we cleaned up so many actions that were a mess. Was a good ‘audit’ and excuse to update a whole host of things that had bugged me for a long time, those types of actions where it works but its complicated, we refined a lot of them during this process. So in some ways even if a conversion is possible looking through everything and seeing what you did is a good exercise for improvements to those types of actions.

thanks for the heads up Dave… ok first thing first… let me get that machine up and running with a clean copy of windows… then find the docker installation steps here somewhere on wappler community so that i dont miss any step as you say… as i wont be the first one. :slight_smile: : ) thanks for sharing the info… :slight_smile:

1 Like

Basically that. Remember to remove the start and end php tags.

Also some SC modules and formatters are not available for nodejs(i.e. argon2 crypto). Expect some manual tweaking. It should be minor though.

And as a disclaimer. Wappler doesn’t support this so support from the team on this matter is not to be taken for granted.

2 Likes

You currently do have to do this file by file but it is much quicker than building from scratch. Be aware that if you process files, the paths will usually be different and the location of the API files is different so you have to do a search/replace on the page SCs too. There is a FR here but it has been inactive for a while

Worth giving it a vote, though.

2 Likes

I have to comment on how great this community is once again! Can’t think of another forum where we could all have such a discussion without breaking down in to camps/tribes/fanboi arguments! Will say it again, we are all very lucky to have this place!

2 Likes

image

image

5 Likes