PHP Troubleshooting

From Wiki
Jump to: navigation, search

Debug HTTP requests using strace

Many times applications do not log any useful data to the apache logs and the only option to see what is going on is to strace the entire HTTP request. To do this you can start PHP using the built in web server which can then be straced to monitor process behavior.

$ cd ~/public_html
$ php -S localhost:8000

Doing this from a screen session is recommended.

After the server process is started you can submit http requests using any standard web client (curl, wget, a browser, etc.)

For example, submit a request using the 'Googlebot' user agent.

curl -v -A 'Googlebot/2.1' 'http://localhost:8000/nebraska/Chapter53/53-208'

The second option is to modify the code to create pid file.

if ( $_SERVER['REMOTE_ADDR'] == '<your IP here>' ) {
      $file = 'pid.log';
      $current = getmypid();
      file_put_contents($file, $current);

After submitting a request you can strace the PID.

strace -F -s512 -Tt -o out -p `cat pid.log`

Fixing PHP permissions

This script should change all of the files on each account to the proper permissions so that PHP doesn't error out.


for user in `ls /var/cpanel/users`; do
	chown ${user}:${user} /home/${user}/public_html
	chmod 755 /home/${user}/public_html
	find /home/${user}/public_html -group nobody -print0 | xargs -0 chgrp ${user}
	find /home/${user}/public_html -type f -print0 | xargs -0 chmod 644
	find /home/${user}/public_html -type d -print0 | xargs -0 chmod 755