PHP
This page contains notes to be added to PHP development documentation. Read nginx with PHP to setup web host with php.
Install PHP
Common needed ports for php are;
$ sudo prt-get depinst php \ php-exif \ php-fpm \ php-ftp \ php-gd \ php-gettext \ php-mariadb \ php-mbstring \ php-pdo-mariadb \ php-pdo-pgsql \ php-postgresql \ php-sockets \ php-sqlite3 \ php-zip \ xdebug \ kcachegrind
Development
Setup php ini in development mode;
$ sudo cp /etc/php/php.ini-development /etc/php/php.ini
$ php --ini Configuration File (php.ini) Path: /etc/php Loaded Configuration File: /etc/php/php.ini Scan for additional .ini files in: /etc/php/conf.d Additional .ini files parsed: /etc/php/conf.d/exif.ini, /etc/php/conf.d/extensions.ini, /etc/php/conf.d/gd.ini, /etc/php/conf.d/mysql.ini, /etc/php/conf.d/pdo_pgsql.ini, /etc/php/conf.d/pgsql.ini, /etc/php/conf.d/xdebug.ini
To enable xdebug edit /etc/php/conf.d/xdebug.ini to
[xdebug] xdebug.remote_enable=1 xdebug.remote_connect_back=1 xdebug.remote_port=9000 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_autostart=true xdebug.profiler_enable=false xdebug.profiler_enable_trigger=true xdebug.profiler_enable_trigger_value=P76NMis5Itj9_j3Xawd7DX1i1uS2BmC7D8HsJls-rFA xdebug.profiler_output_dir=/tmp xdebug.profiler_output_name=phpprofile.%t-%u.%p-%H.%R.%cachegrind
By default profiler is off and is turned on using xdebug.profiler_enable_trigger_value to not overload the system profiling all requests. Create a personalized token for the trigger;
dd if=/dev/urandom bs=8 count=4 status=none | base64 | tr -d '=' | tr '+/' '-_'
Output files are saved on xdebug.profiler_output_dir and must be writable by user php is running as. Output file names can be changed using profiler_output_name.
To start profiling add XDEBUG_PROFILE with trigger value to GET or POST. Example;
$ w3m http://localhost/shop/?XDEBUG_PROFILE=P76NMis5Itj9_j3Xawd7DX1i1uS2BmC7D8HsJls-rFA
Files created can be open and viewed with kcachegrind.