12
Debugging LAMP Apps on Linux/UNIX Using Open Source Tools Jess Portnoy Kaltura, Inc [email protected] July 13, 2014 Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 1 / 12

Debugging LAMP Apps on Linux/UNIX Using Open Source Tools - Jess Portnot - OSCON 2014 Presentation

Embed Size (px)

DESCRIPTION

OSCON 2014 tutorial workshop lead by Jess Portnoy (@jess_port01) covering the use of various useful debugging tools, both general and specific to web apps. It focuses on PHP based apps but vast parts of it are useful for other commonly used open sourced, interpreted languages. Covering tools such as 1. GDB [for debugging the PHP engine and extensions, written in C/C++] 2. Xdebug [for debugging PHP code] 3. Shell utilities for better inspection of error and access logs such as ccze, efficient use of grep,sed. 4. Tracing processes with strace and more. The session also featured several, real life examples such as: 1. A PHP extension causing seg faults 2. Reviewing Apache access and error logs to discover bad VHost configurations and rewrite rules 3. Various badly set PHP directives causing malfunctions 4. Debugging PHP code using Xdebug Participants took part in the debugging process, and were asked to make suggestions as to how to advance and be prompted to share cases they’ve had, solved or did solve.

Citation preview

Debugging LAMP Apps on Linux/UNIX Using OpenSource Tools

Jess Portnoy

Kaltura, Inc

[email protected]

July 13, 2014

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 1 / 12

Abstract

The purpose of this tutorial is to train web developers working on aLinux/UNIX ENV on production, development ENVs, or both.

Often, developers, while proficient in say, PHP, lack UNIX systemknowledge and therefore come across a brick wall when debuggingproduction issues.

A big portion of the time, because the development ENV is different thanproduction.

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 2 / 12

Deployment day

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 3 / 12

Tools used for this session (All open source)

strace - System call trace

Build tools - GCC, make, libtool

telnet - client for the TELNET protocol

netstat - Print network connections, routing tables, interfacestatistics, masquerade connections, and multicast memberships

nmap - Network exploration tool and security / port scanner

netcat - TCP/IP and UDP swiss army knife

ldd - print shared library dependencies

PECL - PHP Extensive Community library

GDB - GNU Debugger

XDebug - Debugging and profiling tool for PHP

cURL - tool to transfer data from or to a server

VIM - VI improved

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 4 / 12

Real life fiascos

The infamous HTTP 500

One of the all time favorites.Dev cycle ended, QA ended [successfully, mind you!] Thing gets deployed...DevOp guy makes a request for the index page, just to test, you know...A very sad person [sometimes a group] comes into your office lookingVERY concerned.And to make it perfect? the reported problem - BLANK PAGE.

Cant́ connect to DB

Your new app is finally deployed on Production.On your single machine, with the little MySQL instance running on thesame box as all other components, all played perfectly.On the multi node cluster ENV - no such luck.

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 5 / 12

Real life fiascos - continued

Dynamic library loading hell

Your app is now using a new PHP extension.Being a professional who thinks one step ahead, you have informed yourDevOps that this new extension is needed and should be compiled forProduction.They DID compile it but.. er.. nobody checked it actually loads into thePHP engine.

The segfault joy

You and the DevOps team fixed the loading issue. You were all happy.But then, being a guy who thinks ahead, you figured it won’t hurt totrigger the peace of code that needs it.It did hurt - Apache now crashes.

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 6 / 12

Real life fiascos - continued

My Daemons refuse to talk to each other

Your Production Memcahed decided it dislikes your Apache who happensto be in a serious feud with your MySQL serverNetworking hell - how to troubleshoot?

Where in god’s name can I find the Apache config?

This is a very common issue.On your Dev ENV, you may run say, Debian GNU Linux, it is Dev so youdid not bother much with VHosts and separate customized logs and othersuch configurations.In Production however, it is a different deal.We’ll discuss a few simple ways to locate what you need.

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 7 / 12

Real life fiascos - continued

I am setting a PHP directive and it does not take

You ask Ops to increase it to 256M in php.ini, they do.You check using ini get(’memory limit’) value is still 128M.Why?!?!

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 8 / 12

Our ENV (All open source)

Now that we presented our trouble scenarios, let see what ENV we’ll befixing:

Linux CentOS 6.3, 64bit

Apache 2.2.15

MySQL 5.1.73

PHP 5.3.3

The Kaltura Video platform which also requires these components:- Memcached 1.4.4- Bunch of PHP extensions- FFMPEG 2.1.3- Sphinx 2.2.1

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 9 / 12

A word about security

Different settings between Prod. and Dev

The development process naturally requires things Production usuallydoesn’t and worse yet - can pose a security risk.Some examples:- The PHP display errors directive- The PHP expose php directive- Exposing Apache’s status module- Info about OS and Apache version:- ServerTokens On- ServerSignature OS- Verbosity of logs- Enabling directory indexes- Permissions!

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 10 / 12

References

http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zendExtension Writing: Introduction to PHP and Zend

Compiling PHP extensions with Zend Server - http://devzone.zend.com/1442Jess Portnoy

Setting up XDebug with VIM - https://github.com/joonty/vdebug

PHP.net security practices - http://php.net/manual/en/security.php

Kaltura - http://www.kaltura.org

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 11 / 12

The End && questions

Jess Portnoy (Kaltura, Inc) Debugging LAMP Apps on Linux/UNIX July 13, 2014 12 / 12