Archive for xampp

Debugging With Xdebug on xampp for linux

Posted in lamp with tags , on June 17, 2008 by Salimane Adjao Moustapha

Xdebug extension can be configure to show specific information about the stack traces and useful intuitive information error messages when one occurs coupled with interactive debugging. Error messages and stack traces can exactly reveal the cause of an error, while interactive debugging allows you to step through your code one instruction at a time, interrogate the type and values of program variables.

You can enable several Xdebug features to illuminate the state of your application when an error occurs: (This assumes that you have already installed and enabled xdebug on your lamp stack)

To reveal a stack trace whenever your program encounters an error, add the following in your php.ini where you enable xdebug.

xdebug.default_enable=On
xdebug.extended_info=1

to further reveal all variables in the top-most scope.

xdebug.show_local_vars=1

xdebug.var_display_max_children, xdebug.var_display_max_data, and xdebug.var_display_max_depth> are related settings to control the number of properties, the length of strings, and the nesting depth, respectively, of variables shown when xdebug.show_local_vars is in use.

You can find more information on the Xdebug Web site.

Installing Xdebug on xampp for linux

Posted in lamp with tags , on June 11, 2008 by Salimane Adjao Moustapha

As it’s commonly suggested, tweaking code while it still in development is foolhardy. If your code seems slow while it’s actually doing what it’s suppose to and right , the first is to measure its performance in actual values. It will just be a wasteful action to just try to tweak the code without these types of diagnostics.

A better measure that is accurate, sometimes that actually measure the time taken by a single line of code can be done using a code profiler. A profiler, typically implemented as an extension to the PHP runtime engine, records the delta between the start of a statement and its end, notes the delta between the start and end of a procedure, and captures the total time required to craft a response to an incoming request. With that, you can find the statement, loop, function, class, or library that is slowing down the application. A better profiler could also measure processes memory usage if process time is not the problem.

Xdebug is my preferred profiler for PHP, which also provides stack trace information to debug PHP applications. It generates datafile that can be viewed using KcacheGrind.

Building and installing Xdebug

I will be using a lamp stack based on xampp for linux installed on ubuntu hardy. I here assume you have already installed xampp for linux and put the bin folder in your environment path.

If you have not yet put the bin folder “/opt/lammp/bin” in your path, run at the command prompt

$ export PATH=/opt/lampp/bin:$PATH

if you would like to have that bin folder inserted in your path every time you login

edit the file .bashrc located in your home folder (ubuntu) for other distro it is .bashprofile

$ sudo gedit /hone/salimane/.bashrc

and add at the end of the file

export PATH=/opt/lampp/bin:$PATH

and save it

Download and unpack the tarball, and change to the subdirectory of the source code. Ensure that phpize and php-config are in your shell’s PATH, and prepare to build with phpize.

$ wget http://www.xdebug.org/files/xdebug-2.0.3.tgz

$ tar xzf xdebug-2.0.3.tgz

$ cd xdebug-2.0.3/

$ phpize

Configuring for:

PHP Api Version:         20041225

Zend Module Api No:      20060613

Zend Extension Api No:   220060519

$ ./configure

$ make

$ sudo make install

Installing shared extensions:     /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/

Notice the directory emitted in the last step. You’ll need it in the next step.

Configuring Xdebug

After the Xdebug extension is installed, you’re ready to enable and configure the extension.

First create a folder in your temp folder that will holds the data file generated by Xdebug

$sudo mkdir /opt/lampp/tmp/xdebug

$sudo chmod a+rwx -R /opt/lampp/tmp/xdebug

Open php.ini in a text editor, and add the following lines.

zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so

xdebug.profiler_output_dir = "/tmp/xdebug/"

xdebug.profiler_enable = On

The first line, zend_extension, loads the Xdebug extension. Notice the same directory as the one you noted before. The second line names the directory to place the profiler output. (the one you just created). The third line enables the profiler.

After adding the lines and verifying that your output directory is writable, restart your Web server.

http://localhost/xampp/

click on phpinfo()

Scroll down to the Zend logo, Xdebug should appear next to the logo if Xdebug has been properly loaded and configured.

Installing a LAMP Stack on Linux using XAMPP For Linux

Posted in lamp with tags , on June 2, 2008 by Salimane Adjao Moustapha

XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use – just download, extract and start. XAMPP is good if you’re new to a LAMP Stack from scratch or if you don’t want get involved in all the hassles with building it from scratch. It contains: Apache, MySQL, PHP & PEAR, Perl, ProFTPD, phpMyAdmin, OpenSSL, GD, Freetype2, libjpeg, libpng, gdbm, zlib, expat, Sablotron, libxml, Ming, Webalizer, pdf class, ncurses, mod_perl, FreeTDS, gettext, mcrypt, mhash, eAccelerator, SQLite and IMAP C-Client.

I’ll be using Ubuntu Hardy as my OS but basically the process would be the same for the other distros.
To build and deploy xdebug or memcached extensions, you will need the XAMPP distribution, including the XAMPP development files. You can download the XAMPP binaries and the XAMPP development files (required for building additional components) from XAMPP. You can also use wget to grab the software quickly:

$ wget 'http://nchc.dl.sourceforge.net/sourceforge/xampp/xampp-linux-1.6.6.tar.gz'
$ wget 'http://nchc.dl.sourceforge.net/sourceforge/xampp/xampp-linux-devel-1.6.6.tar.gz'

I will be installing the package into /opt. The same would go for the development files. Using /opt makes the rest of the build process much easier. I will be using the -C option to tar to extract the files directly into /opt, as follows:
you might create /opt folder if it doesn’t exist

$ sudo mkdir /opt
$ sudo tar xzf xampp-linux-1.6.6.tar.gz -C /opt
$ sudo tar xzf xampp-linux-devel-1.6.6.tar.gz -C /opt
$ ls -CF /opt/lampp
backup/ build/ error/ htdocs/ include/ lampp* libexec/ logs/ manual/ phpmyadmin/ RELEASENOTES share/ var/
bin/ cgi-bin/ etc/ icons/ info/ lib/ licenses/ man/ modules/ phpsqliteadmin/ sbin/ tmp/

The default document root is “/opt/lampp/htdocs/”. if you would like to change your document root folder to any other folder like in my case my home folder “/home/salimane/htdocs”, do the following :

$ mkdir /home/salimane/htdocs

Open your httpd.conf and change all occurences of “/opt/lampp/htdocs” to “/home/salimane/htdocs”

$ sudo gedit /opt/lampp/etc/httpd.conf

Copy all the folders and files in /opt/lamp/htdocs to /home/salimane/htdocs

$ sudo cp -R /opt/lampp/htdocs/* /home/salimane/htdocs/

That’s all. XAMPP is now installed below the /opt/lampp directory. To start XAMPP simply call this command:

$ sudo /opt/lampp/lampp start

You should now see something like this on your screen:

Starting XAMPP for Linux 1.6.6...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.

OK, that was easy but how can you check that everything really works? Just type in the following URL at your favourite web browser:
http://localhost or http://127.0.0.1
Now you should see the start page of XAMPP containing some links to check the status of the installed software and some small programming examples.

xamp for linux

File/Directory Purpose

/opt/lampp/bin/ The XAMPP commands home. /opt/lampp/bin/mysql calls for example the MySQL monitor.
/opt/lampp/htdocs/ The Apache DocumentRoot directory.
/opt/lampp/etc/httpd.conf The Apache configuration file.
/opt/lampp/etc/my.cnf The MySQL configuration file.
/opt/lampp/etc/php.ini The PHP configuration file.
/opt/lampp/etc/proftpd.conf The ProFTPD configuration file. (since 0.9.5)
/opt/lampp/phpmyadmin/config.inc.php The phpMyAdmin configuration file.

XAMPP Autostart at login

To make xampp automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown. With your prefered editor, gedit in my case :

$ sudo gedit /etc/init.d/lampp

Now paste in the following:

# Lampp auto-start
# author : Salimane Adjao Moustapha
# description: Auto-starts lampp
# processname: lampp
# pidfile: /var/run/lampp.pidcase $1 in
start)
/opt/lampp/lampp start
;;
stop)
/opt/lampp/lampp stop
;;
restart)
/opt/lampp/lampp stop
/opt/lampp/lampp start
;;
esac
exit 0

You’ll need to make the script executable by running the chmod command:

$ sudo chmod 755 /etc/init.d/lampp

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.

$ sudo ln -s /etc/init.d/lampp /etc/rc1.d/K99lampp
$ sudo ln -s /etc/init.d/lampp /etc/rc2.d/S99lampp

Uninstall

To uninstall XAMPP just type in this command:

$ sudo rm -rf /opt/lampp