yeah i know is 2 years older and just in case you want fire up nodejs with php in windows -i did in this way :
1.download PHP 8.1 (8.1.0alpha3) =VS16 x64 Non Thread Safe (2021-Jul-06 17:39:28) from https://windows.php.net/qa/
and unzip it in C:\x\php
2.put inside same location this php.ini more or less like this
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.enable_gc = On
zend.exception_ignore_args = On
zend.exception_string_param_max_len = 0
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
extension_dir = "c:\x\php\ext"
enable_dl = On
cgi.force_redirect = 1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
extension=bz2
extension=curl
extension=fileinfo
extension=gd
extension=mysqli
extension=openssl
extension=sqlite3
[CLI Server]
cli_server.color = On
[Pdo_mysql]
pdo_mysql.default_socket=
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
bcmath.scale = 0
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.cookie_samesite =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
zend.assertions = -1
tidy.clean_output = Off
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
ldap.max_links = -1
(i delete some stuff from it to be able to publish it here)
3.assuming on C:\n\ you have unzipped Windows Binary (.zip) got it from here https://nodejs.org/en/download/ and on your desktop you make a folder ..let say APP and inside you have runme.bat ,index.js ,favicon.ico and index.php :
runme.bat
c:\n\node.exe %CD%\index.js
pause
index.js
/*
these are codes from w3school and stackoverflow
'cause am not even beginer in node.js (but i am fluent in JavaScript and others
,also i am programming since 1992 , almost 100 000 houres of programming in several languages)
*/
const http = require('http');
const url = require('url');
var fs = require('fs');
serialize = function(obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
}
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
if (req.url === '/favicon.ico') {
fs.readFile(__dirname + req.url, function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
}
const queryObject = url.parse(req.url,true).query;
//console.log(`server 3 ` , queryObject);
process.env.QUERY_STRING=serialize(queryObject);
pathf=req.url.match('^[^?]*')[0].split('/').slice(1);
console.log(pathf);
const { exec } = require('child_process');
exec(`c:\\x\\php\\php-cgi.exe -c c:\\x\\php\\ %cd%\\index.php`, (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}stdout
res.end(stdout);
});
}).listen(80);
index.php
<?php
phpinfo();
//var_dump(get_defined_vars());
?>
so
after you run runme.bat
and in browser you have
http://localhost/index.php?stack=overflow&its=cool&and=fun
you will be able to run php 8.1 alpha 3 from nodejs ..
how you see inside index.js you have QUERY_STRING prepared for php and maybe others env vars are missing ...
[IMPORTANT] THE SAME PHP.INI CONFIG I USE TO BUILD A NGINX WINDOWS SERVER TO CHECK YESTERDAY MY FASTEST PHP FRAMEWORK IN THE WORLD
YOU ARE FREE TO IMPROVE IT IF YOU KNOW JAVASCRIPT PROGRAMMING AND TO BUILD A SERVE FILES SECTION BASED ON THIS and maybe you approach to nginx features and so you no need several servers on several ports and minimum should sqlite 3 work already (just in case you can build around some stuff for localhost )
you see that pause inside runme.bat? it's only in case while you develop something in javascript and something goes wrong and it's crush ..so you will be able to hit enter to close it after you see the errors there.