Archive for the 'development' Category

.php with PHP5 in Apache

Usually, when an Apache web server supports PHP4 and PHP5, the default configuration is .php scripts are handled with PHP4, and .php5 scripts with PHP5 . You can however specify that .php scripts should be handled with PHP5 instead.

To achieve that, you should modify the .htaccess file by adding the following:
AddHandler x-httpd-php5 .php
AddHandler x-httpd-php .php4

The new handling will apply to all .php scripts in the current directory and it’s sub-directories. PHP4 will looks for the .php4 extension in this case. Note that the second line is necessary, otherwise a handling conflict will occur.

MySQL error 2002

This solves the following MySQL error:
Got error: 2002: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) when trying to connect

You should try to investigate why this is happening. Still, a quick trick to fix it and can restore the missing sock is simply creating a symlink to the original one:
ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

MySQL database dump and restore

This operation is useful when you want to back up a MySQL database, and then move it’s content to another database. I usually do it using phpMyAdmin, but due to limitations on the file size, it’s just quicker to use the command line.

Dumping is the process of putting the database content to file. It can be done using the following command:
mysqldump -u[user] -p[password] [db-name] > dump.sql
replacing where appropriate the parameters [user], [password] and [db-name]; you should not use the brackets and watch the spaces.

To restore the content of the database from a dump file, use the following command:
mysql -u[user] -p[password] [db-name] < dump.sql

Troubleshoot: Error 1044
This solves the problem when getting the following error with $mysqldump$:
Got error: 1044: Access denied when using LOCK TABLES

The message is self explanatory. You have two solutions to solve the problem. You can either modify the database LOCK privileges (not explained here) or you could add --single-transaction flag to the mysqldump command as follows:
mysqldump -u[user] -p[password] [db-name] --single-transaction > dump.sql

Installing Eclipse Europa

Eclipse is a development platform for Java, C++ (or any other language throught the use of plugins), originally created by IBM (but later released as an open-source project). Eclipse Europa (v 3.3.1.1 at the time I’m writing this article) is not included yet in the Ubuntu source repositories, that means that you cannot install it *properly* through the Synaptic Package Manager or apt-get. Follow this simple tutorial for a smooth and clean installation:

Eclipse Europa

  1. Install the Java 5 runtimes (or later) in case they’re not there already. Run the following in the terminal:
    sudo apt-get install sun-java5-jre
    sudo apt-get install sun-java5-jdk
  2. Download the latest release of Eclipse Classic available on Eclipse Downloads
  3. Extract the downloaded file by running the following:
    tar xzf eclipse-SDK-3.3.1.1-linux-gtk.tar.gz
    sudo mv eclipse /opt/

    Take care of the permissions:
    sudo chmod -R +r /opt/eclipse
    sudo chmod +x /opt/eclipse/eclipse
  4. Create an executable in your path:
    sudo touch /usr/bin/eclipse
    sudo chmod 755 /usr/bin/eclipse
    sudoedit /usr/bin/eclipse

    Copy the following content and save the file:
    #!/bin/sh
    #export MOZILLA_FIVE_HOME="/usr/lib/mozilla/"
    export ECLIPSE_HOME="/opt/eclipse"
    $ECLIPSE_HOME/eclipse $*

    Let’s also make eclipse executable everywhere by creating a symlink:
    sudo ln -s /usr/bin/eclipse /bin/eclipse
  5. Create the menu icon
    sudoedit /usr/share/applications/eclipse.desktop
    Type in this content and save:
    [Desktop Entry]
    Encoding=UTF-8
    Name=Eclipse
    Comment=Eclipse IDE
    Exec=eclipse
    Icon=/opt/eclipse/icon.xpm
    Terminal=false
    Type=Application
    Categories=GNOME;Application;Development;
    StartupNotify=true
  6. Run for the first time
    eclipse -clean
    You can now start Eclipse by simply typing eclipse in the terminal or from the GNOME menu Applications -> Programming -> Eclipse

Troubleshoot

  • Error java.lang.ClassNotFoundException: org.eclipse.core.runtime.Plugin
    This happens if Eclipse is using GNU Java runtimes instead of the Sun one’s. To correct this problem, execute the following:
    update-java-alternatives -l
    sudo update-java-alternatives -s java-1.5.0-sun

Part of the tutorial is based on Ivar’s How to install Eclipse in Ubuntu.

Remove .svn folders

To remove .svn folders recursively, just execute the following in the directory tree root:
find . -name ".svn" -exec rm -rf {} \;

Change your MAC address

I don’t really care why you want to change your MAC address on Ubuntu, you’re probably trying to break into your neighbor’s internet connection again… I’m sure though this will come in handy at some point.

Big Mac Address

  1. First of all you need to figure out which connection you want to change your MAC address for (usually LAN is eth0 or and Wifi is eth1). If you’re not sure, type the following to find out:
    ifconfig
    Look for a similar line (which tells you what your mac address is for that particular connection):
    eth1 Link encap:Ethernet HWaddr 00:10:6A:01:FD:92
  2. Shut down the connection:
    sudo ifconfig down
  3. Set your new MAC address (replace eth1 and 00:11:22:33:44:55 by your connection and new MAC address respectively):
    sudo ifconfig eth1 hw ether 00:11:22:33:44:55
  4. Start the connection again:
    sudo ifconfig up
  5. You’re done! The drawback of this method is that it will only change temporarily your MAC address (changes will be undone once you reboot).

To make the MAC address change permanent, proceed as follows:

  1. Open the bootmisc.sh file with your favorite editor:
    sudo gedit /etc/init.d/bootmisc.sh
  2. Add the following at the end of the file:
    killall dhclient
    killall dhclient3
    ifconfig eth1 down
    ifconfig eth1 hw ether 00:11:22:33:44:55
    ifconfig eth1 up
    /sbin/dhclient
    /sbin/dhclient3
  3. Save. This will execute the process described earlier on start up.

Set up SVN with Apache2

SVN (Subversion) is a tool that allows you to keep track of the modifications you make to source code. Similar tool include CVS, OpenCVS, Vesta (full list). I’ll go in the details of setting up SVN on Apache2:

Subversion

  1. Make sure you have apache2 installed, if you don’t:
    sudo apt-get install apache2
  2. Install the libapache2-svn package:
    sudo apt-get install subversion libapache2-svn
  3. Edit /etc/apache2/mods-available/dav_svn.conf in your favorite editor and follow the instructions. If you want to keep it simple uncomment and modify at the following lines:
    • l.13: If you have a domain set up, change to <Location /<domain>/svn>. Otherwise (if you’re using svn just locally), keep it as <Location /svn>.
    • l.16: DAV svn
    • l.19: comment line
    • l.23: SVNParentPath /var/lib/svn/
    • l.54: </Location>

    Save and exit (requires sudo of course).

  4. Create the svn directory:
    sudo mkdir /var/lib/svn
    sudo mkdir /var/lib/svn/repo1
  5. Create the svn repository:
    svnadmin create /var/lib/svn/repo1
  6. Change permission of svn directory:
    sudo chown -R www-data /var/lib/svn/repo1
  7. Restart apache server:
    sudo /etc/init.d/apache2 restart
  8. You can know start using SVN. To checkout:
    svn co http://<domain>/svn/repo1 replacing domain by the domain name or localhost depending on your configuration.

Big part of the tutorial goes to Georges at Sematopia. All i did was some refactoring.