debugging lamp apps on linux/unix using open source tools - jess portnot - oscon 2014 presentation

Click here to load reader

Post on 19-Aug-2014

103 views

Category:

Engineering

5 download

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.

TRANSCRIPT

  • 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
  • Abstract The purpose of this tutorial is to train web developers working on a Linux/UNIX ENV on production, development ENVs, or both. Often, developers, while procient in say, PHP, lack UNIX system knowledge and therefore come across a brick wall when debugging production issues. A big portion of the time, because the development ENV is dierent than production. 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, interface statistics, 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 proling 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 ascos 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 oce looking VERY concerned. And to make it perfect? the reported problem - BLANK PAGE. Cant connect to DB Your new app is nally deployed on Production. On your single machine, with the little MySQL instance running on the same 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 ascos - 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 your DevOps that this new extension is needed and should be compiled for Production. They DID compile it but.. er.. nobody checked it actually loads into the PHP engine. The segfault joy You and the DevOps team xed the loading issue. You were all happy. But then, being a guy who thinks ahead, you gured it wont hurt to trigger 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 ascos - continued My Daemons refuse to talk to each other Your Production Memcahed decided it dislikes your Apache who happens to be in a serious feud with your MySQL server Networking hell - how to troubleshoot? Where in gods name can I nd the Apache cong? This is a very common issue. On your Dev ENV, you may run say, Debian GNU Linux, it is Dev so you did not bother much with VHosts and separate customized logs and other such congurations. In Production however, it is a dierent deal. Well 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 ascos - 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 well be xing: 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 Dierent settings between Prod. and Dev The development process naturally requires things Production usually doesnt and worse yet - can pose a security risk. Some examples: - The PHP display errors directive - The PHP expose php directive - Exposing Apaches 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- zend Extension Writing: Introduction to PHP and Zend Compiling PHP extensions with Zend Server - http://devzone.zend.com/1442 Jess 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