Unable to run node application along side of php - php

I'm facing two basic problem which i'm unable to rectify
1) I've a subdomain(with virtual host) with https enabled via letsencrypt, now that subdomain works great with ssl when i visit sub.domain.com and browser shows green sign
Now when i type sub.domain.com:8080 it serves my node application but as soon as i change it to https:// browser say unable to connect which is beyond my imagination how this happening.
2) When first method didn't work, I jumped to second method, on my root domain domain.com inside html folder i placed node application with url like domain.com/nodeapp now when i visit this url, it shows folder structurer with various files and folder, now as soon as i turn the port number on domain.com/nodeapp:8080/ browser shows 404 note i'm already running a php application on my root domain so it might conflict with it, but how can I solve this, We have one module which has to be in node, and we are unable to find the perfect solution.

I suppose your php application is served by an Apache web server, right? It has an extension which does the https encryption, if it is configured correctly (what letsencrypt normally does).
Your Node.js application is configured to listen on port 8080, but doesn't handle encryption automatically. Also, Letsencrypt doesn't configure it (yet) for you.
Have a look at this article how to configure encryption for Node.js by yourself.

Related

Statically serve internal (apache server) NodeJS api open on a custom port and forward it to the public url

Introduction
I have a university-managed server, that does not give students access to open ports for internet traffic, but students could still open ports (like 4040 for their NodeJS applications for internal access).
Each student's account has a public_html folder (similar to /var/www/), which serves all files in public_html on this URL (using an Apache server) statically (or rendered by PHP):
http://mi-linux.wlv.ac.uk/~studentid/
Problem
However, in my case, I want to expose an API for external testing using postman and adding it to a React application. The problem is, it uses NodeJS and express, and creates its own server on port 4040.
I could access the API by using the curl command from ssh internally like:
studentid#csl-student:~$ curl http://localhost:4040
{"message": "Hey! The backend is working. Explore routes from the code"}
Now, since students cannot allow open posts for HTTP traffic, one could simply not access my NodeJS API from outside the server (which I have to).
Things I looked up
I searched extensively on topics like how to statically serve a nodejs application, to how to forward ports from 8080 (https port) to 4040 (my NodeJS port), but most of them require sudo access, and some of them simply don't work.
Solution I propose
I think I still could access my public_html folder, that is statically served, and could render PHP. I know that I could create a index.html (or index.php) file that would fetch http://localhost:4040 internally, and simply forward the result, since the API port is open internally, and the index.html file could be served externally.
What the file could do
While loading the file using
http://mi-linux.wlv.ac.uk/~studentid/index.html
The file could load the response from localhost:4040 internally on the server itself (since the API is accessible internally), then send the result along with the status codes and headers.
However, my API has several routes, and I could not manage to hard code each route. There must be a more efficient way of doing this.
What I'm looking for
I would be really thankful if one could direct me to a package already made for the purpose of forwarding static files with responses pre-loaded from an internal API.
Or I could have a php script that could do all the forwarding that I need and make the API public.
PS: I know this should be asked on Server Fault, but since I think this could be done by using a script or something, I asked it here.
A workaround for this would be to host your NodeJs code on a third part platform, say Heroku.
And create a PHP script that acts as a middleware proxy and does curl requests to your Heroku-Hosted-NodeJs API endpoint.
Are the Apache's plugins mod_rewrite and mod_proxy enabled on the server?
If so, maybe you could use ProxyReverse with mod_rewrite's P flag inside a .htaccess file as described in this post:
RewriteEngine On
RewriteRule ^/node/(.*)$
http://localhost:4040/$1 [L,P]
ProxyPassReverse /node http://localhost:4040
(I can't test it right now, so my answer is purely speculative, sorry.)
Another option, in case that the server conf cannot be modified, could be use mod_headers and Location, but I'm not sure if it will be transparent:
Header edit Location ^http://internal\.example\.com/(.*) http://example.com/$1

Video Streaming using SSL on Alibaba ECS

I have an ECS instance on Alibaba using LetsEncrypt for SSL configuration but i have an issue with PHP Video Streaming that is not working when SSL is used where Video Link gives 404 when the streaming begins but It works fine on http.
This is the used package for streaming: http://codesamplez.com/programming/php-html5-video-streaming-tutorial
And also this Package i already used and worked fine on another servers on https
Can anyone advice what should i do?
Sometimes users have the issue that all pages get 404 errors when SSL is activated. The cause may be differ from user to user and server to server. I have also faced this issue, try to do the following to get it resolved.
1) Re-save the permalinks, Re-saving makes sure the WordPress rewrite
rules get flushed. (If you are using WordPress)
2) If you have .htaccess files in your media directories, remove them, or adapt them to the https domain.
3) Check port bindings, sometimes binding may also cause this. i.e (There is no binding for https)

How do I execute PHP on a cPanel server?

I have a LAMP application that works. I can deploy this in 15 minutes on a Linux server. I was handed a VPS to deploy it. All I get is WHM. I created an account and that got me a login to cPanel and to the box. cPanel ran some wizard that told me to put my "web source files" in /public_html There is an /cgi-bin inside of that. I cannot get any web assets to be visible from any of those folders. All I get is 404 not found. chmod 777. 404 not found.
My simple question is this: how could I get a simple hello world PHP script to run on a cPanel server? I've been building web pages since before we called them web pages. I do not need to know anything about PHP itself I want to know how to get the cPanel managed server to run PHP scripts. All the documentation I can find on cPanel assumes you've been using it forever. I just need some basic information. Where do I put my PHP code ?????
This is the way cPanel works. If you host your website on shared IP address (main IP address of your server), you cannot access your website using IP address directly. You will always redirect to "http://IP/cgi-sys/defaultwebpage.cgi URL.
To access your website without pointing our domain to your server, you can use temporary URL. By default, it is enabled on the cPanel server. You can access the temporary URL using the following URL:
http://IP/~cpanel_user
Please note that the temporary URL does not work under the following configuration:
If you have enabled mod_userdir tweak and didn't exclude default host
If your server is configured to use mod_ruid2
Hope this information will help you with future use.

Run PHP code on local MacOS Jekyll site, port 4000

I've build a Jekyll website on my localhost (MacOS Mavericks). The website is served at http://localhost:4000/website/ and everything regarding Jekyll is running just fine.
However, I now want to have a contact form in PHP that allows me to receive emails. I placed a contact.php file in the website/ folder and have the form POST to that file. On my remote web server, this is working perfectly. However, on the localhost, the PHP isn't parsed, and plain text is displayed on contact.php. However, PHP is parsed perfectly on localhost/contact.php.
How do I get my localhost (Apache? PHP?) to process PHP files on my local Mac http://localhost:4000/ (without breaking my Jekyll website that listens on the same :4000 port)?
You can't use the same port. The port determines the application endpoint that will handle the request on the IP address. The Jekyll server (WEBrick library) uses port 4000 as a default.
The typical way to handle this problem, is to use a "web service" to add dynamic functionality. For instance, the jekyll docs suggest using something like FormKeep, or SimpleForm.
What you're asking is to setup a "web service" yourself. To do this it would need to be on another port or another IP address. The "service" will simply act as an endpoint to accept and process your form post. In this case you could setup a webserver using Apache/PHP on a different port than Jekyll -- such as the standard port 80 -- then write a PHP script (e.g., webform.php) that in combination with the static form is setup to respond and process your form.
Note: It is possible to configure both Jekyll and Apache to respond to requests on port 4000. However, both applications (aka servers) can't be running at the same time. The ip:port combination determines which application an internet request is sent to.
I realize the post is old but this may help someone...
The answer by Mike Stewart is excellent and describes what needs to be done to accomplish the goal.
To add to that answer, here are the specifics of how I do this type of development on a Mac.
Configure CORS in Apache
Run the Jekyll site on default port 4000
Run MAMP stack on default port 8888
Code goes in MAMP's htdocs folder (htdocs/your_project)
PHP resides in a separete "php" or other folder inside the "your_project" folder
Jekyll watches the "your_project" folder and compiles to _site as normal
The CORS issues you'll experience can be resolved locally during development several ways. Here is a good resource for enabling CORS on Apache: http://enable-cors.org/server_apache.html
Once you have CORS configured you'll be able to make Ajax calls to the PHP on port 8888.
I'm running the PHP built-in web server alongside the Jekyll server. I opened a second Terminal window and navigated to the _site folder. The command is php -S localhost:8000 (or whatever port you want to use that is not 4000).
Note that I'm using viewing localhost:8000 in the browser, but having the Jekyll server running simultaneously is nice because Jekyll keeps the build updated as I make changes to the source code (refresh required).

Is there a way to get around a PHP application that checks the domain it's on?

I have acquired a PHP application that has a system class encoded with Ion Cube PHP Encoder.
I copied the files and moved them to a new server, a development one. The first thing that got me was the application was to only work on the domain it was on, so obviously not from localhost or any other server.
I'm guessing somewhere in the encoded code is a string comparison from a hardcoded string to where the site is running from.
I'm not looking to do anything illegal or against the software license - just I want to do all the development on a different server, and then push the files back to the original domain.
Basically, minimise downtime for the production site.
Is there any tricks I can do? Can I stuff with my hosts file to do it?
Thanks
Update
Forgot to mention that I have tried changing $_SERVER before the PHP checks. There is also a config file which asks for the URL. Leaving it on the old domain doesn't work, and changing it results in the invalid domain error.
It would depend on how exactly Ion Cube checks the host - if it uses hostname or equivalent then you would need to modify config on the server to think it has the same name as the production server, this is unlikely to be a good idea, but still maybe better than a developmestruction environment.
If it just checks the host HTTP header then you can just modify your hosts file back and forth
what operating system are you using ?
add the domain name to your host file as 127.0.0.1 (localhost)
e.g:
under linux
add this to file /etc/hosts
127.0.0.1 thedomainname.com
checkthis link to find other OS hosts file link text
this should make the apps running on your localhost to refer to it's self

Categories