Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74020

What's the easiest way to run a php (.html or .php) file from nodejs?

$
0
0

This is more of an open-ended question so I can get a top-down look on how to accomplish what I'm trying to do. I've been trying for a while to just run a simple php file when I redirect to a port that my nodejs server is serving. Nodejs is one of my weaker languages, so I'm open to seeing if there is an easier way to do this without nodejs.

Here's my situation:

I am in a php file called "lobby.php," which redirects to an index.html file via nodejs. In that index.html file, I need to run some php to simply get a session variable. Simply putting php in that index.html file doesn't work, so I have turned to trying to get my server to interpret html files as php files. I have wanted this for a while, and I feel like this is the simplest way for ME to do it. For some reason, index.php files are still NOT interpretted as php files. The php is just commented out automatically with this. This is my .htaccess code:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_value SMTP "localhost"
   php_value smtp_port 25
   php_flag display_errors Off
   php_value max_execution_time 300
   php_value max_input_time 600
   php_value max_input_vars 10000
   php_value memory_limit 256M
   php_value post_max_size 8M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
   php_value upload_max_filesize 256M
   php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
   php_value SMTP "localhost"
   php_value smtp_port 25
   php_flag display_errors Off
   php_value max_execution_time 300
   php_value max_input_time 600
   php_value max_input_vars 10000
   php_value memory_limit 256M
   php_value post_max_size 8M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php70"
   php_value upload_max_filesize 256M
   php_flag zlib.output_compression Off
</IfModule>
AddType text/html .shtml .shtm .htm .html
AddHandler server-parsed .shtml .shtm .htm .html 
Options Indexes FollowSymLinks Includes
# Uncomment the version of PHP you have on your server
# Only one of the following  can be uncommented
#AddHandler application/x-httpd-imh-php56 .html
#AddHandler application/x-httpd-imh-php70 .html
#AddHandler application/x-httpd-imh-php71 .html
#AddHandler application/x-httpd-imh-php72 .html
AddHandler application/x-httpd-ea-php70 .html
# END cPanel-generated php ini directives, do not edit

#RewriteEngine On
#RewriteRule ^ http://mathtutortime.com:3000/ [P,L]

Notice the "AddHandler application/x-httpd-ea-php70 .html" From what I understand, this should have done it. If any of you have any ideas on how to fix this further, please let me know.

Next, if this isn't a viable option, and I'm doing everything that I should be doing there, I have looked into rendering my php via a separate express app (or node server) on nodejs, instead of doing something like:

let fileToServe = 'index.php';
res.sendFile(__dirname + '/' + fileToServe);

since it doesn't look like node can render php at all. If I need to perform this the nodejs way, please can someone explain the simplest way I might do this? All ideas appreciated. Thank you.

Update:

I found that my server is actually interpreting php files correctly. I think the issue is that nodejs is the one redirecting, so my server is not getting the chance the overrwrite the php in the html, and so it's not reinterpretted. Looks like the node php compilation is the only way.


Viewing all articles
Browse latest Browse all 74020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>