Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my php-app I need list of all ip connected on 80 port. i've chose this way:

<?php
     $ips = exec("netstat -an |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c", $info);
?>

But it dosen't work on my VPS FreeBSD server. When I start netstat -an notice appears and no connections in output:

netstat: kvm not available: /dev/mem: No such file or directory

I tried to add device mem to conf, but i have empty /usr/src/sys. I got to the point that I need rebuild core.))

netstat works correctly when user is root(from console).

I haven't problem like this on CentOS hosting platform.

Can anybody help me? Or maybe another way exists for resolving this task

share|improve this question

migrated from stackoverflow.com Apr 28 '13 at 22:04

This question came from our site for professional and enthusiast programmers.

    
This question belongs on serverfault.com – Marcel Korpel Apr 28 '13 at 13:33
    
I asked my question over there. When i get an answer i'll close it here – Andrei Zhamoida Apr 28 '13 at 13:57
    
Check the permissions on /usr/bin/netstat. It should belong to the user root and the group kmem, and it should have the setgid bit set. The device /dev/kmem should be readable by the kmem group. – Roland Smith Apr 28 '13 at 21:04
    
-r-xr-sr-x 1 root kmem 157616 Apr 28 18:51 /usr/bin/netstat For /dev/kmem and /dev/mem No such file or directory – Andrei Zhamoida Apr 29 '13 at 9:08

Do you have safe_mode enabled in php.ini?

Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.

I recommend you start digging through http://php.net/ for more information on this. This most probably has to do with sandboxing, chroot, jails or other similar concepts. Note that in jails not all nodes in /dev/ are available.

share|improve this answer

On FreeBSD uses the functions from the kvm libraray to read data from the running kernel. This requires access to the /dev/mem device.

Since you can run netstat normally as root, but not from PHP, I suspect that PHP is run in a jail. The /dev/mem device is usually not visible in a jail.

If PHP is indeed running in a jail, and you really want to expose /dev/mem in that jail, you should edit /etc/devfs.rules and create a new ruleset that adds /dev/mem, like this:

[devfsrules_xtrajail=6]
add include $devfsrules_hide_all
add include $devfsrules_unhide_basic
add include $devfsrules_unhide_login
add path 'mem' unhide

Make sure that you don't use a ruleset number <5 or one that is already defined.

When starting the jail, you should set the devfs_ruleset parameter to the number of the ruleset you created, in this case 6.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .