Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Linux Programming
  4. php that runs on Debian 11 and connects to another machine on the network.

php that runs on Debian 11 and connects to another machine on the network.

Scheduled Pinned Locked Moved Linux Programming
javascriptsysadminphplinuxhelp
6 Posts 3 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15796760
    wrote on last edited by
    #1

    I am developing a website that uses javascript, php and jQuery. One of the screens executes a php that connects to the IP of another PC that is on the same network as the PC with the web server. However, this PHP fails because it doesn't have access to the other PC. Both PCs have Debian 11 installed. Seeing that in any of them to ping the other, it is necessary to do it with sudo, I thought that the problem may be in that it is necessary to add the web user (www-data) to the netdev group, like so I have executed the command:

    $ sudo adduser www-data netdev

    Adding user `www-data' to group `netdev' ...
    Adding user www-data to group netdev
    Done.

    But the php is still unable to access the other PC. Should I configure something else? Any comment or suggestion is welcome.

    K U 2 Replies Last reply
    0
    • M Member_15796760

      I am developing a website that uses javascript, php and jQuery. One of the screens executes a php that connects to the IP of another PC that is on the same network as the PC with the web server. However, this PHP fails because it doesn't have access to the other PC. Both PCs have Debian 11 installed. Seeing that in any of them to ping the other, it is necessary to do it with sudo, I thought that the problem may be in that it is necessary to add the web user (www-data) to the netdev group, like so I have executed the command:

      $ sudo adduser www-data netdev

      Adding user `www-data' to group `netdev' ...
      Adding user www-data to group netdev
      Done.

      But the php is still unable to access the other PC. Should I configure something else? Any comment or suggestion is welcome.

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      Check the firewall settings on the destination PC. You may be blocking the port on the destination for incoming connections. There's an article that may help here: [IBM Documentation](https://www.ibm.com/docs/es/spectrum-scale/5.1.0?topic=firewall-examples-how-open-ports#:~:text=apply your changes.-,Ubuntu and Debian,-Issue the following)

      Member 15796760 wrote:

      Seeing that in any of them to ping the other, it is necessary to do it with sudo

      I'm not sure exactly what that means. You should be able to ping a (reachable) host without needing sudo. For example, assuming that you have your resolver and gateways correctly configured you should be able to

      ping 8.8.8.8
      ping google.com
      ping 192.168.100.100 # assuming you're on 192.168.100.0/24 subnet
      etc

      Keep Calm and Carry On

      M 1 Reply Last reply
      0
      • K k5054

        Check the firewall settings on the destination PC. You may be blocking the port on the destination for incoming connections. There's an article that may help here: [IBM Documentation](https://www.ibm.com/docs/es/spectrum-scale/5.1.0?topic=firewall-examples-how-open-ports#:~:text=apply your changes.-,Ubuntu and Debian,-Issue the following)

        Member 15796760 wrote:

        Seeing that in any of them to ping the other, it is necessary to do it with sudo

        I'm not sure exactly what that means. You should be able to ping a (reachable) host without needing sudo. For example, assuming that you have your resolver and gateways correctly configured you should be able to

        ping 8.8.8.8
        ping google.com
        ping 192.168.100.100 # assuming you're on 192.168.100.0/24 subnet
        etc

        Keep Calm and Carry On

        M Offline
        M Offline
        Member_15796760
        wrote on last edited by
        #3

        This is a php that runs on PC1 and calls another php on PC2, where the IP of PC1 and PC2 are known. The call made by the php on PC1 is as follows:

        $file_headers = @get_headers(http://'.$IpPC2.'/myweb/protected/scripts/copy_files.php?PARAM1&PARAM2.' ');

        How can I know which port would need to be opened on PC2?

        K 1 Reply Last reply
        0
        • M Member_15796760

          This is a php that runs on PC1 and calls another php on PC2, where the IP of PC1 and PC2 are known. The call made by the php on PC1 is as follows:

          $file_headers = @get_headers(http://'.$IpPC2.'/myweb/protected/scripts/copy_files.php?PARAM1&PARAM2.' ');

          How can I know which port would need to be opened on PC2?

          K Offline
          K Offline
          k5054
          wrote on last edited by
          #4

          Since you're using http then that would be port 80. If you've installed a web server on PC2, then you may already have port 80 open. You can check to make sure that the port is open using nc

          nc -z -w 1 IpPC2 80; echo $?

          $? is the return value of the last command, so if it's 0 then the connection was successful. Anything other than 0, and the connection failed. Make sure you've got a web server running on PC2. You can do that using netstat

          [k5054@localhost: ~$ sudo netstat -tlnp
          Active Internet connections (only servers)
          Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
          tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/init
          tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 623/sshd: /usr/sbin
          tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 659/cupsd
          tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 664/postgres
          tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1001/exim4
          tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 1422/sshd: k5054@pt
          tcp6 0 0 :::111 :::* LISTEN 1/init
          tcp6 0 0 :::22 :::* LISTEN 623/sshd: /usr/sbin
          tcp6 0 0 ::1:631 :::* LISTEN 659/cupsd
          tcp6 0 0 ::1:5432 :::* LISTEN 664/postgres
          tcp6 0 0 ::1:25 :::* LISTEN 1001/exim4
          tcp6 0 0 ::1:6010 :::* LISTEN 1422/sshd: k5054@pt

          You want to look for something listening on port 80 - which I do not have running in the above screen grab

          Keep Calm and Carry On

          M 1 Reply Last reply
          0
          • K k5054

            Since you're using http then that would be port 80. If you've installed a web server on PC2, then you may already have port 80 open. You can check to make sure that the port is open using nc

            nc -z -w 1 IpPC2 80; echo $?

            $? is the return value of the last command, so if it's 0 then the connection was successful. Anything other than 0, and the connection failed. Make sure you've got a web server running on PC2. You can do that using netstat

            [k5054@localhost: ~$ sudo netstat -tlnp
            Active Internet connections (only servers)
            Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
            tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/init
            tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 623/sshd: /usr/sbin
            tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 659/cupsd
            tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 664/postgres
            tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1001/exim4
            tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 1422/sshd: k5054@pt
            tcp6 0 0 :::111 :::* LISTEN 1/init
            tcp6 0 0 :::22 :::* LISTEN 623/sshd: /usr/sbin
            tcp6 0 0 ::1:631 :::* LISTEN 659/cupsd
            tcp6 0 0 ::1:5432 :::* LISTEN 664/postgres
            tcp6 0 0 ::1:25 :::* LISTEN 1001/exim4
            tcp6 0 0 ::1:6010 :::* LISTEN 1422/sshd: k5054@pt

            You want to look for something listening on port 80 - which I do not have running in the above screen grab

            Keep Calm and Carry On

            M Offline
            M Offline
            Member_15796760
            wrote on last edited by
            #5

            Thank you very much. With your instructions I have been able to verify that port 80 is open on PC2 and that Apache is listening on port 80.

            $ sudo netstat -tlnp
            Activate Internet connections (only servers)
            . . .
            tcp6 0 0 :::80 :::* LISTEN 967/apache2
            . . .

            Later I was able to find an error in a configuration file of PC1, which was the cause of the error.

            1 Reply Last reply
            0
            • M Member_15796760

              I am developing a website that uses javascript, php and jQuery. One of the screens executes a php that connects to the IP of another PC that is on the same network as the PC with the web server. However, this PHP fails because it doesn't have access to the other PC. Both PCs have Debian 11 installed. Seeing that in any of them to ping the other, it is necessary to do it with sudo, I thought that the problem may be in that it is necessary to add the web user (www-data) to the netdev group, like so I have executed the command:

              $ sudo adduser www-data netdev

              Adding user `www-data' to group `netdev' ...
              Adding user www-data to group netdev
              Done.

              But the php is still unable to access the other PC. Should I configure something else? Any comment or suggestion is welcome.

              U Offline
              U Offline
              unitedsol zain
              wrote on last edited by
              #6

              Adding the www-data user to the netdev group should give it the necessary permissions to access the network and ping other PCs on the same network. However, there are a few other things you can check to troubleshoot the issue:

              Make sure that the PHP script is running as the www-data user. You can check this by adding a line at the beginning of the script to output the current user (echo exec('whoami');)

              Check the permissions on the PHP script. The script needs to have execute permissions for the www-data user.

              Check the firewall settings on the PC that you are trying to access. Make sure that incoming connections on the necessary ports are allowed.

              Check your network settings. Make sure that the two PCs are on the same subnet and that they can communicate with each other.

              Check your PHP configuration. Make sure that the allow_url_fopen and allow_url_include settings are enabled in your php.ini file.

              Check the PHP error log to see if there are any error messages related to your script.

              If none of these steps help, you may need to provide more information about the specific error message or problem you're encountering.

              Additionally, It might be better to use a library like ssh2-php instead of direct access to the other PC. This will help you to connect to the other PC in a more secure way.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups