PHP - Amazon Elastic Beanstalk - Get private IP address - php

I am hosting a web app in Amazon Elastic Beanstalk (EB). The web app is written in php. EB also uses Elastic Load Balancer (ELB). The web app implements a websocket with the client.
Here is what I have done so far:
I know I have to listen to the private ip, not 127.0.0.1 of the instance for this to work
implemented a listener in load balancer to connect to the instance port
opened inbound and outbound traffic for the port in security groups.
If the EB deployment goes for horizontal scaling (increase the number of instances), will the private ips of the scaled instances remain same (please explain)? If not, and I believe so, how do I get the private ip address of the current instance that is serving the client?
So far its working perfectly without any problem, but there's only one instance running. I tried listing the clients and I can get the private ips with the list but I don't know how to identify the instance that is currently serving the file.
Please help me.

This will do the trick:
<?php $ip = shell_exec('hostname -i'); ?>
important: this works only for the linux environment. For windows, hostname -i is not valid. You can refer to https://superuser.com/questions/382265/ for further ideas.

Related

Connecting to Docker Container Network from the Client Side

I have two containers, a php server serving a laravel application and a spring boot application running a websocket server. My architecture was to connect the two containers using Docker Networking and have the Laravel container port published to the outside. The laravel application is pretty much all front end, and on one page is a chat room using websocket. I tried to connect the chat room to the Spring Boot websocket container name (Docker network) but I feel like because this request is coming from the client this is not possible? I am using the container name (domain name) as a URL on the javascript file that is being served by the php server. Would the only way to make this work is publish the Spring Boot port as well on a public server and replace the websocket url with a public url?
Additional info like docker-compose or commands you are running would also be helpful.
But from what I see, the issue probably is that the requests are coming from the client which means that they can't access the actual service since it's not available publicly...
You should probably make that service available as well by mapping the necessary ports to your host machine or create some proxy server to pass the requests to the websocket

How to get data from a device connected in a local network to my application

I am trying to get data from a device which is connected in the local network.
The device listens to 192.168.1.2:10000
For example we can call the function getItems() on the windows computer in the network and we get all the items.
Now I want to do this in my cloud application (php). So I want that example.com/getItems get the items from the device.
I am a noob at networking, so I hope someone can give some advice how to handle this.
at least you need to open your local firewall and expose the Port 10000 and NAT it to you local 192.168.1.2:10000 to the public internet.
If there are no further IPv6 restrictions and you have a static IPv6 address you can reach that it from the cloud php.
If you have a typical private internet access, consider to use a dynDNS or similar service to reach you changing IP by a static FQDN.

connect to mysql using php vpn

I have a php script that accesses a mysql database. It lives on a server that has been migrated to aws (amazon web services). This server hosts a website that used to live on a physical server part of a private network.
The databases are still on that private network. I need to connect to a mysql database that is on a server with no public ip address. There is a vpn set up for this network.
I would like to ssh or vpn to the network from the aws server.
This is just to query something once a day.
I tried exec('ssh -f -L 3307:PrivateMYSQLServer:3306 USER#VPNADDRESS') but could not get it to work.
Is there a one liner that I can insert into the php script?
thanks
You’ll have to set up the server in which your script runs to connect back to your network via your VPN client.
Alternatively, you can set up a site to site VPN between your data center and AWS.
If you have a correctly configured site-to-site VPN (and routing tables, security groups, etc.), one end in your VPC and the other end in your private on premises network, then you don't need to create an SSH tunnel. Just connect to your database and run the query.

PHP server on PC

I want to make a php application and it must host in a computer and open from many branches of my schools using web.
I installed XAMPP on my pc server, and if i try to open the application in the same LAN network it works, but if i change the network it is not working.
The browser say that ip 192.168.1.22 take large time to load and not open.
how can i config that problem please
You need to set up a static IP on your machine, then set your router to forward ports so that all requests that come to your router on a particular port would be forwarded to your machine. This should do for testing purposes, but if you want to host a website for example you will need to get a permanent static IP for your router, this usually costs money from your ISP(internet service provider).
192.168.1.22 is your local IP address, you cannot access it from a different network. You can get your external IP address for example using whatismyip.com. Also, if you are behind a router, you have to open and forward the port which is used by your web server to your machine.

Verify Apache availability behind Azure Balancer for each VM

Status:
2xA2 Azure VM with WAMP, behind Load Balancer
endpoint monitoring set
Question:
How do i check the Apache availability for each VM (as port 80 is now balanced and i cannot individually check a machine)?
I need to check the response via a php script to be able to automatically deploy further custom actions.
Is there a way to manually check (via php, or online service) a probe.html(or specific file for each machine) that reside on each machine, in any way?
If the two VMs exist on a private Azure VNET you could add a third machine to that VNET from which to perform the monitoring and then use the private IP address of each machine as your test endpoint.

Categories