Categories
PHP Server Software

PHP Profiling Time and Memory with OSX 10.10 and Xdebug

First you need to have installed Xdebug, to install Xdebug on Linux debian click here.

Configure XDEBUG for time specific profiling:

[code lang=”bash”]
mkdir /var/log/xdebug-profiling-output/
chmod -R 777 /var/log/xdebug-profiling-output/
nano /etc/php5/apache2/conf.d/xdebug.ini

xdebug.profiler_output_dir=/var/log/xdebug-profiling-output/
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
[/code]

These settings mean that time profiling outputs will be stored in /var/log/xdebug-profiling-output/, profiling will be disabled by default and only activated using trigger. Having profiling on as default is not recommended because it drains the system resources.

Now reboot Apache2:

[code lang=”bash”]
/etc/init.d/apache2 graceful
[/code]

To generate a profiling log, append ?XDEBUG_PROFILE=1 to your site-url, like this: http://www.mywebsite.com/index.php?XDEBUG_PROFILE=1

To be able to parse the output in OSX 10.10 you need Graphviz installed, install it using Homebrew by running:

[code lang=”bash”]
brew install qcachegrind
[/code]

Generate a log on your website and then remember the filename path. Copy it over to your OSX machine using:

[code lang=”bash”]
scp root@mywebsite.com:/var/log/xdebug-output/cachegrind.out.4852 ~/Downloads/
[/code]

Now open this file in the application qcachegrind to analyze the profiling. You can also analyze the Xdebug profiling output using Php Storms built-in Xdebug Profiler Snapshot analyzer if you have it.

Configure XDEBUG for memory specific profiling:

[code lang=”bash”]
mkdir /var/log/xdebug-trace-output/
chmod -R 777 /var/log/xdebug-trace-output/
nano /etc/php5/apache2/conf.d/xdebug.ini

xdebug.auto_trace=0
xdebug.trace_enable_trigger=1
xdebug.trace_output_dir=/var/log/xdebug-trace-output/
xdebug.collect_params=0
xdebug.trace_format=1
xdebug.show_mem_delta=1
xdebug.collect_assignments=1
[/code]

These settings means that memory profiling will be disabled by default to save resources, profiling logs will be generated in the folder /var/log/xdebug-trace-output/.

Now reboot Apache2

[code lang=”bash”]
/etc/init.d/apache2 graceful
[/code]

To generate a profiling log, append ?XDEBUG_TRACE=1 to your site-url, like this: http://www.mywebsite.com/index.php?XDEBUG_TRACE=1

Check generate filename and copy trace log from remote host to OSX.

[code lang=”bash”]
scp root@mywebsite.com:/var/log/xdebug-trace-output/trace.2043925204.xt ~/Downloads/
[/code]

Now you can open the log in text-editor.

Categories
Server

Install Xdebug on Linux Debian

First you need the follow packages installed:
* php5-dev
* php-pear
* make

Install them by running:

[code lang=”bash”]
apt-get update
apt-get install php5-dev php-pear make
[/code]

Then to install xdebug type:

[code lang=”bash”]
pecl install xdebug
[/code]

Now, DON’T add anything to php.ini but do this instead:

[code lang=”bash”]
find / -name “xdebug.so”
[/code]

Copy the location of xdebug.so.

Start editing a new file like this:

[code lang=”bash”]
nano /etc/php5/conf.d/xdebug.ini
[/code]

Enter your configuration, usually something like this:

[code lang=”bash”]
zend_extension=”LOCATION OF XDEBUG.SO ABOVE”

[debug]
xdebug.remote_enable=1
xdebug.remote_host=YOUR IP ADDRESS
xdebug.remote_port=9000
xdebug.remote_mode=”req”
xdebug.idekey=”YOUR IDE KEY”
xdebug.remote_autostart=0
xdebug.remote_handler=”dbgp”
xdebug.remote_connect_back=0
xdebug.extended_info=1
xdebug.remote_log=/var/log/xdebug.remote_log.log
[/code]

Now restart apache2 by running

[code lang=”bash”]
/etc/init.d/apache2 restart
[/code]

You can see if your xdebug is loaded in PHP by looking after xdebug in this output:

[code lang=”php”]
phpinfo();
[/code]

Also in terminal you can do this:

[code lang=”bash”]
php -i | grep xdebug
[/code]

Now to start a debug session your go to your site and append query string like this:
?XDEBUG_SESSION_START=YOUR_IDE_KEY

And to end a debug session you do this:
?XDEBUG_SESSION_STOP=YOUR_IDE_KEY

Read more about XDEBUG here.

Categories
Server

Setup Youtrack Stand-alone on Linux Debian

Install java (version 7 minimum) by executing:
[code lang=”bash”]
apt-get update
apt-get install openjdk-7-jre
apt-get install openjdk-7-jdk
[/code]

Check your java version by running
[code lang=”bash”]java -version
[/code]

If your default version is not 7 or higher change by running and selecting another version as default.
[code lang=”bash”]
update-alternatives –config java
[/code]

Download YouTrack Stand-alone from JetBrains. Or download by using console:

[code lang=”bash”]
mkdir /var/web/youtrack
wget http://download.jetbrains.com/charisma/youtrack-5.1.2.jar /var/web/youtrack/youtrack-5.1.2.jar
[/code]

Make a new init script like this
[code lang=”bash”]
nano /etc/init.d/youtrack
[/code]

[code lang=”bash”]
#!/bin/bash

### BEGIN INIT INFO
# Provides:          youtrack
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts YouTrack.
# Description:       Starts YouTrack tracking system.
### END INIT INFO

java -Xmx1g -XX:MaxPermSize=1g -Djava.awt.headless=true -jar /var/web/youtrack/youtrack-5.1.2.jar 8088 &
[/code]

Modify permissions like this
[code lang=”bash”]
chmod -R 755 /etc/init.d/youtrack
[/code]

Then install your init-script by running:
[code lang=”bash”]
insserv /etc/init.d/youtrack
[/code]

YouTrack server will now launch every time system boots and is accessed on port 8088. Notice this guide is for Youtrack 5.1.2 so if you download a newer version just change the path in the init script.

To launch YouTrack for this first-time do this:
[code lang=”bash”]
/etc/init.d/youtrack
[/code]

To integrate with Apache2 as a HTTPS site do this, otherwise you are done.

Activate modules needed for SSL proxy.

[code lang=”bash”]
a2enmod ssl
a2enmod proxy
a2enmod proxy_http
a2enmod headers
[/code]

Add a Apache2 site by doing this:

[code lang=”bash”]
nano /etc/apache2/sites-available/default-ssl
[/code]

Add following to the file:

[code lang=”bash”]

SSLEngine on
SSLCertificateFile /etc/apache2/apache.pem

ServerAdmin admin@locahost
ServerName mydomain.com
DocumentRoot /var/web/youtrack/


SSLRequireSSL
Header edit Location ^http: https:

RequestHeader set X-Forwarded-Proto “https”

ProxyRequests Off
ProxyPass / http://mydomain.com:8088/
ProxyPassReverse / http://mydomain.com:8088/

ErrorLog /var/web/youtrack/error.log
LogLevel warn
CustomLog /var/web/youtrack/access.log combined


[/code]

Activate site by
[code lang=”bash”]
a2ensite default-ssl
[/code]

Restart Apache2 configuration
[code lang=”bash”]
/etc/init.d/apache2 graceful
[/code]

If all went good your YouTrack installation should be accessible at https://mydomain.com

Read more

Read more about install YouTrack stand-alone here.
Read more about install Java on Debian here.