I have a situation that my VPS has run out of CPU because of my website. How to confirm which PHP file is running by Apache? So I can solve this problem.

I tried the commands of lsof -p, ps -f, strace -p, but no one help me because all the comming out are apache files, such as /usr/local/zend/apache2/bin/httpd, /usr/local/zend/apache2/modules/mod_unique_id.so.

enter image description here

enter image description here

  • Did you try this as sudo? – MariusMatutiae Dec 14 '15 at 12:08
  • How? I don't think it will give me any help. – prince Dec 14 '15 at 12:12
  • It helps you if you are doing lsof -p pidof apache2 or some such thing. – MariusMatutiae Dec 14 '15 at 12:34

Use sudo only if necessary. List all processes, and then tell grep to output only the lines having the word php.

sudo ps aux | grep php

Read the output as per the following heading


If you are trying to get the full path to the running Apache PHP module, do this.

The PHP file used by Apache should be named libphp5.so. So you can run this lsof command via sudo:

sudo lsof | grep libphp5.so

Which should return a whole pile of results with pretty much all of them showing the full path to libphp5.so which should be something like this if you are on an Ubuntu/Debian system:


If you are trying to monitor your Apache server to figure out what file might be choking it, do this.

That said, it’s unclear to me from your question what you mean by “How to confirm which PHP file is running in Apache?” since rereading that makes me think that perhaps you are trying to figure out what PHP script is choking your server and not what PHP module Apache is loading? Because the actual PHP module Apache loads simple is just the PHP parser Apache uses. But a PHP script you are running via that setup is a whole different thing.

The problem is that the way Apache works is the contents/files are parsed on demand. So you need to run a tool that will monitor Apache requests in real time to get the info you are looking for in that case. There are a few ways you can do this from the command line.

Using Apache Top to monitor an Apache web server.

First, you can install and run Apache Top which is similar to the standard Linux/Unix top but for Apache processes. For example, here is a nice/simple way to monitor a web server’s log files in realtime with Apache Top:

apachetop -r 2 -f /var/log/apache2/access.log

The -r 2 will refresh the output every 2 seconds and the -f /var/log/apache2/access.log tells apache-top to report on info from the provided Apache log. In that example it’s loading the default Apache log file from an Ubuntu/Debian setup, but you should change that full file path to match your actual Apache log file location.

Using ELinks to monitor an Apache web server.

Another method I use to monitor Apache on a server is using ELinks and the default Apache status URL like this:

elinks http://localhost/server-status?refresh=1

ELinks is basically just a text-based web browser. So if you run that from the command line, it will just load the URL passed to it and if you notice that URL includes the refresh=1 parameter which basically just tells the server-status to refresh itself every second.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.