How to get the true IP of the user with Load Balancer and LAMP?

Posted June 11, 2019 3.4k views
UbuntuApachePHPDigitalOceanLoad Balancing

I’m using Load Balancer and LAMP in my application.
But in a feature of my application it is necessary to get the true IP of who is accessing.
I tried with PHP in several ways like:




But none of these worked, I always get the Load Balancer IP. Can anybody help me?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hey there,

You’ll need to enable proxy protocol for the load balancer to forward the client IP.

If you continue having issues after enabling proxy protocol for your LB just let me know and I can offer additional advice based on the issue you are facing.

Ethan Fox
Developer Support Engineer II - DigitalOcean

  • Thanks for the answer. I use apache in a ubuntu 16.04 droplet. The version of my apache is 2.4.18 and to use the RemoteIPProxyProtocol I need version 2.4.31 or newer. I looked and I did not find how to upgrade, could you help me?