PHP to Node conversion

Hi there @george

Is there any possibility of creating a new forum category called “PHP to Node”? I’d like to move my rather huge app to Node some time in the next year and I have lots of questions that will come up, and I’m guessing I’m not the only one… it would be amazing to have all the posts about this in one place, as they don’t quite fit into any of the other categories!

Best wishes,
Antony.

In terms of using app connect and server connect, it does not matter if you use php, asp.net or node. The UI is the same.
If you have any other questions, then please ask in the existing forums.

1 Like

Hi there @Teodor

I understand what you are saying… but I will have lots of questions about how to migrate an existing app from PHP to Node, and there isn’t a category for that!

There is no magical migration tool that converts your php code to node. You should create pretty much everything from scratch.
You cant “migrate” from one server model to another.

1 Like

To add to what @Teodor has said, you can copy all of your website’s static files (HTML, CSS, JS, images etc.) into a folder called public.

The PHP server actions could be transformed into NodeJS with a script, however, page templates would have to be recreated manually.

You’d also need modify the login/register functionality due to different hashing algorithms (I think)

Lastly, are you sure you want to move your app to NodeJS? This question might sound odd, but if you have a big app maybe it could be better use of your time to just stick with PHP :stuck_out_tongue:

2 Likes

:+1:

Converting server actions is easy, just needs a few lines removed but the remainder would be a slow manual process. I have done it one with a relatively small site, 100 pages or so), you can paste the page code over then optimise to layouts and content pages later but PHP includes are the big problem as they need to be manually converted to partials. A lot really depends of your initial structure

IMO if you are really wanting to do something this big it would be a good idea to start almost fresh on a more recent Wappler version 3.9.7 is very old now and while I respect this may work for you there has been a lot of improvements since then.

You may find there is even easier ways to do things now in certain areas for example global database connections (think that was wappler 4 could be wrong) this is just one of many examples not to mention things like the NodeJs date time updates that made things more universal.

As someone who was a staunch PHP advocate and having switched to Node we won’t be going back! Too many benefits to Node. One of the mightiest for us is Scheduled Events on the server side! There are dozens of benefits @Antony. Yes the workload in making the transition for large Projects can be lengthy but the reward is worth it when you are done. Bite the bullet. You can leave your PHP version up while you work on version II of your app in the background, all the time making vast improvements as you work through what you need to do. And update Wappler at the same time!! Man you are missing out on so much (just don’t update your stable Project, you have the choice in the Project Updater). Again we halted for a long time on 3.9.7 (definitely one of the most stable releases to date), BUT you need to move on or you’ll just get left in the dirt as Wappler accelerates. Hard to move on from what you know and trust but hey man, that is life! You have to get to the next corner to look around it and see whats coming.

Antony, can you define what you consider huge, i.e. number of Server actions/ pages. It is a very subjective term.

Hey everyone, thank you for the love I feel in your posts! :blue_heart:

This is all coming to mind as today I will begin the task of upgrading from 3.9.7 to 5.9.7, and PHP from 7.4 to 8.2, so my development focus shifts from features to framework upgrade.

@Hyperbytes, I have around 400 server actions… many are simple crud actions, but some have complex maths algorithms. There are also S3 actions and a bit of custom PHP.

I’m using cron in PHP to schedule actions at the moment…

I’m wondering about the technical possibilities of having half the back end in PHP and half in Node for a while too.

The front end of my app is a single index file with a cascade of around 40 PHP include files it loads at start-up. It works like a dream! So this would need to become partials I guess… but right now I know nothing more detailed than the word “partials”! Which makes me realise I will need to know more about Node, but I’m not quite sure what it is I will need to know!

I also have quite a lot of app flows and data stores on the front end…

I also want to plan the development of a mobile app with local data storage for when the user is off-line, and I’m sure the switch to node and the mobile app journey will effect each other in ways I currently don’t understand.

There are so many thoughts in my head about how to approach this, and I want to leave an easily searched legacy of this journey for others to follow.

At the moment I’m in an information gathering phase… hence appreciating the idea of a forum category where each aspects of this journey can be discussed in technical detail so I can create a realistic timescale for the project and leave a documentation trail for all those who follow to use. Using my experiences for the benefit of others is a massive part of what I have always wanted to bring to our wonderful community!

@mark1, I’m wondering if there are monthly meet-up topics to consider from all of these questions too…

A big fat Thank You :pray: to all of you who are bringing your time and care to this topic!

Antony.

400 SAs is not that big in the grand scale of things. You could convert them over in a matter of a few hours.
You coud replace all the cron jobs to node scheduler actions,again not a huge job, it’s just a copy/paste process with the json.
All those includes would all need to be changed over manually, that would be the biggest job.
Ironically the fact that it is a single page will make things easier as there is no need to move over to a layout/ content page architecture. Lastly and <?php directives and to be changed over to node equivalents or alternatives.
I really wouldn’t advise trying to run a php/node hybrid,technically it may be possible but highly inadvisable.

1 Like

Once Wappler is updated and the site converted you may them want to look at your data structures as new features like sub tables and multi joins may be able to streamline your data management code.

1 Like

@Antony,
Having gone through the conversion before with a similarly complex site, I can assure you that it isn’t as difficult as you probably think.

Because they are JSON-based and have the same structure irrespective of server model, most of the PHP SC action files can be copied as whole folders. Then just change the file extensions. You will need to then remove the opening section of the PHP files:

<?php
require('../../../dmxConnectLib/dmxConnect.php');
$app = new \lib\App();
$app->define(<<<'JSON'

and the closing part:

JSON
);
?>

The JSON for the vast majority, if not all, of API file steps are the same between server models - the main thing to look for that might need changing is where steps refer to a file path. There is a difference with the S3 file upload step for AWS - the response of ObjectURL is Location for Node but a find/replace should sort that.
All the front-end stuff (apart from the server-side data binding which is available through NodeJS) should be agnostic, once you have got the structure sorted for Partials vs PHP Include

2 Likes

We were actually planning a server model converter for some time now that will at least convert your server actions, as those are mostly identical indeed per server model. Maybe we should put a bit more priority on it :slight_smile:

But the rest of the site like the template pages and includes will still require a manual convert.

So there won’t be any magical tool indeed but the converter might save you at least some boring copy/paste convert and give you at least some head start.

6 Likes

The biggest problem are the PHP includes, and NodeJS templates are not yet the perfect solution as they lack support for nested includes:

This means you have to re-think templates instead of copying the majority of the includes from PHP.

That was one of the things I noticed when I migrated from Laravel (a PHP framework) to Wappler NodeJS, Wappler has in inferior templating engine despite NodeJS being preferred by many advanced users

Hey @apple, so are you saying that if I have in my PHP:

index.php  - includes level1.php
level1.php - includes level2.php

So an include tree like this:

       index.php
           |
       level1.php
           |
       level2.php

Then in Node, I can’t include level2 in my level1 file as it is a template file and templates can’t include templates?

This would definitely be an issue for me… I’m not sure how many levels my includes go to in my PHP design as I’ve never had to worry about it!

And are you saying that native Node allows this but the Wappler implementation doesn’t? And if so, can I just hack something at the code level to allow it?

Is this still an issue since my app is just a single page?

Maybe I need to play around with templates in a trial node design to get my head around this!

It seems I now got confused as heck, because it seems EJS (the templating engine Wappler team chose for NodeJS) does supports includes, which are called “partials” in Wappler. So, your design could be like this:
index.ejs -> includes partial level1.ejs > includes partial level2.js

However, in that feature request topic, I wrote this:

So, you might get away with using partials, although the development experience might not be the best. It’s been a while since I touched this subject, so I don’t remember a lot of intricacies. I know for example in my user dashboard, I’m including the dashboard sidebar partial on every page, instead of just using a “user_dashboard” template as base that would automatically include everything I need

Pinging @JonL in case he has any comments to add

1 Like

How about this for a thought, PHP and Node can co-exist with the aid of an Apache or Nginx proxy server as can be seen here: NGINX as Reverse Proxy for Node or Angular application | DigitalOcean

The details on how to go about such a combination within Wappler would need to be worked out. Maybe @George or @Teodor can help out.

You could start converting a certain section of the site and gradually work through it. Maybe keep the backend as PHP?