As i continue with my first ubuntu server, following the lamp installation tutorial at https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04-quickstart-es
i configured everything without much issue until i decided to create a different php script and upload it to the server.
the code is supposed to show your ip (here is the script)

<?php

function getUserIpAddr(){
    if(!empty($_SERVER['HTTP_CLIENT_IP'])){
        //ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
        //ip pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }else{
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

echo 'User Real IP - '.getUserIpAddr();

?>

but when i connect to it through a web browser like ‘server ip/file.php’ all i get is the 'User Real IP’ message without the actual interesting part wich is the ip, does this mean php isnt executing the code or what am i missing here

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.

×
1 answer

Hi @21729179,

It’s possible you are missing some PHP packages/extensions. Can you list what PHP extensions you have installed on your server? Additionally, the version is of importance as well. To list the extensions type in

apt list --installed php*

Regards,
KFSys

  • Hi @KFSys,
    Thanks for your reply, this are the listed extensions i have
    https://imgur.com/a/TUj6QH9
    thanks for the help

    • Hi @21729179,

      I do have a bit more, here is the output of the command

      php-common/now 2:76+ubuntu18.04.1+deb.sury.org+9 all php7.4/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 all 
      php7.4-bcmath/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 php7.4-bz2/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      php7.4-cli/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      php7.4-common/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      php7.4-gd/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      php7.4-intl/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      php7.4-json/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      php7.4-mbstring/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 
      php7.4-mysql/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      php7.4-opcache/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      php7.4-readline/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 
      php7.4-zip/now 7.4.10-1+ubuntu18.04.1+deb.sury.org+1 amd64 
      
      

      Anyway, if you go to the file and try to execute it from your SHELL/CLI, what do you get

      php file.php
      

      Do you see any output?

Submit an Answer