This article summarizes how to set up xdebug for Apache 2.

Use apt-get to install xdebug from the package repositories. This will also enable xdebug for command line php.

sudo apt-get install php5-xdebug
$ php -v
PHP 5.5.3-1ubuntu2 (cli) (built: Oct  9 2013 14:49:12)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

Additionally, I had to manually configure the time zone (sudo vim /etc/php5/apache2/php.ini):

[Date]
date.timezone = Europe/Berlin

By default, xdebug is not set for remote debugging. You need to activate it (run sudo vim /etc/php5/apache2/conf.d/20-xdebug.ini):

zend_extension=/usr/lib/php5/20121212/xdebug.so
xdebug.remote_enable = 1

After you’re done with the configuration, restart Apache server:

sudo service apache2 restart

Testing in shell

In order to test your installation run the following command:

php -r "phpinfo();phpinfo(INFO_MODULES);" | less

Afterwards, search for xdebug by typing “/xdebug”.

Testing in browser

Place a file phpinfo.php in your web server’s directory and add the following content (set appropriate rights to execute it!):

<html>    
    <body>
    <?php
    // Show all information, defaults to INFO_ALL
    phpinfo();
    // Show just the module information. phpinfo(8) yields identical results.
    phpinfo(INFO_MODULES);
    ?>
    </body>
</html>

Open up the corresponding URL (e.g. http://localhost/phpinfo.php) and search for xdebug.

Netbeans

For use with Netbeans, you need to correct the debugging session ID. Open the xdebug.ini file:

sudo vim /etc/php5/apache2/conf.d/20-xdebug.ini

Then, add the following line. Make sure, the ID is literally the same as in the Netbeans preferencese:

xdebug.idekey="netbeans-xdebug"

References

  • [1] Installing xdebug for PHP5 on Ubuntu
  • [2] Wizard that generates installation instructions for xdebug (not specific to Ubuntu)

The update from Ubuntu 13.04 to 13.10 failed for me with the error message:

Your python install is corrupted. Please fix the /usr/bin/python symlink.

The reason was that I used update-alternatives to manage my two Python versions (2.7 and 3.3). The following solved the issue for me:

sudo update-alternatives --remove-all python
sudo ln -sf /usr/bin/python2.7 /usr/bin/python

(The expected version can be found out via: python /usr/share/python/pyversions.py -i)

References

  • [1] One of many forum entries that describes this solution

When we encounter strange, unexplainable problems with text files, hidden characters may be reason. This article describes several possibilities to tackle line-ending and whitespace problems.

Correcting mixed line endings

If a file has mixed line endings, the standard tool flip may help you:

echo -e "unix\nmicro\r\n" > test.txt
file test.txt
#result: test.txt: ASCII text, with CRLF, LF line terminators

A check with file reveals that the file test.txt has mixed line endings. Flip unifies the line endings to Unix (-u) or Windows (-m) standard:

flip -u test.txt
file test.txt # result: test.txt: ASCII text

flip -m test.txt
file test.txt # result: test.txt: ASCII text, with CRLF line terminators

Examining files

vim can show whitespace characters, if you enable the option list. In command mode, execute the following to show whitespaces like tabs or line endings. Unfortunately, the editor does not differentiate between different types of line endings.

:set list

Use :set nolist to return to normal view. With :set ff the program identifies the line ending standard.

If you need to get a detailed picture of the whitespace characters in your document, the octal file viewer od may be helpful, it displays the file as octal values and (interpreted) ASCII characters:

echo -e "item1\titem2\titem3\r\nline2 (unix)\n" > test.txt
od -c test.txt

The results looks as follows:

000000  69  74  65  6d  31  09  69  74  65  6d  32  09  69  74  65  6d
         i   t   e   m   1  \t   i   t   e   m   2  \t   i   t   e   m
000010  33  0d  0a  6c  69  6e  65  32  20  28  75  6e  69  78  29  0a
         3  \r  \n   l   i   n   e   2       (   u   n   i   x   )  \n
000020  0a
        \n
000021

Using cat -v text.txt, you can see bogus (non-Unix) line endings  being marked with a special symbol: ^M

item1   item2   item3^M
line2 (unix)

Show one’s own/other’s groups

groups
groups LOGIN

Show all groups on the system (with group id):

cat /etc/group | less

Create new group

groupadd GROUP

Add user to group

usermod -G GROUP -a USER

Assign a specific home directory and shell to a user

usermod -s /bin/bash USER
usermod -d /tmp USER

If the user shall only be allowed to do SCP/SFTP transfers, then an appropriate login shell is scponly.

 

 

 

Some image processing programs expect the file extension to be in lower case. Many digital cameras, however, tend to use an uppercase extension (JPG in case of the Panasonic TZ-31).

The following Bash one-liner renames all JPG files in the current folder to have the lowercase jpg extension afterwards. The ${…} expression is called parameter expansion, which is quite a powerful mechanism:

for file in *.JPG; do  mv $file "${file%.*}.jpg"; done

Links

  • [1] Manpage of the Bash (see Section on Parameter Expansion)
  • [2] Parameter Expansion explained on bash-hackers.org

If you ever wondered, what the rc in all the startup files for Unix application means, here is the answer:

The rc stands for run commands.

This conventional pattern in file names is believed to originate in the 1960s from the runcom facility at MIT. See also this quote coming from Brian Kernighan and Dennis Ritchie:

“There was a facility that would execute a bunch of commands stored in a file; it was called runcom for “run commands”, and the file began to be called “a runcom”. rc in Unix is a fossil from that usage.”

Links

  • [1] Wikipedia (EN): Run commands

When being at my workplace at home, I like to use an external monitor instead of the laptop display (Acer TravelMate 5730G). I did not always want to open up the display control in Kubuntu in order to change between between primary (laptop) and secondary (external monitor) device. I came up with two small scripts which perform the switching in both directions. One is shown below, the other one is analogous.

xrandr --output LVDS --crtc 0 --auto --output VGA-0 --auto
sleep 0.5
xrandr --output LVDS --crtc 0 --auto --output VGA-0 --off

This effectively switches on both displays and then disables VGA-0. You can find out about your connectors’ names by running xrandr without arguments or xrandr –verbose which also gives you the CRTC number (supported controllers) which needs to be set manually sometimes (see line CRTCS in the verbose output).

However, recently I noticed there is a more reliable tool called disper which has been developped for facilitating the monitor management with Nvidia graphics cards. Yet, it also works perfectly for my ATI mobile Radeon HD 3650 graphics chip.

The package can be installed from the regular Ubuntu repositories:

sudo apt-get install disper

Afterwards you may easily switch monitors with one short command as the help (disper –help)  suggests:

-l, --list          list the attached displays
-s, --single        only enable the primary display
-S, --secondary     only enable the secondary display

The primary (secondary) display is the first (second) display returned by –list. On my machine, neither cloning (–clone) nor extending the display (–extend) work properly, unfortunately.

Links

  • [1] Short intro on disper in the ubuntuusers Wiki (German)