Software Tips

  • I was getting "no space left on device error" when I tried to restart my php5-fpm process. The server was a Ubuntu Linux on Amazon AWS (small instance). df command said I had plenty of space, so there must be another problem:

  • I needed to disable InnoDB support on my tiny server to save memory. To achieve this, I first had to convert the storage engine of all tables in all databases.

    echo "show databases;" | mysql -uroot -p[your password] | grep -v "Database" | grep -v "information_schema" | grep -v "test" | grep -v "mysql" | grep -v "performance_schema" > mysql-dbs.txt

  • Create an EBS volume of prefered size. It must be in the same availability zone with your existing instance.

    Attach the volume to the instance

    Check the volume device id
        fdisk -l

    Partition the volume, in my case the device id was /dev/xvdf
        mkfs.ext3 /dev/xvdf

    Create mount point the new volume
        mkdir -p /media/disk1

    Mount it
        mount /dev/xvdf /media/disk1

    Create fstab entry for automatic mounting at boot time
        nano /etc/fstab

  • By default, MySQL treats all fields as case-insensitive. Here is how to change this behavior for some fields in a table or for a specific SELECT query:

    for table fields:
    If you set the field collation as utf8_binary instead of utf8_general_ci (or similar), that field will be case sensitive.

    for select queries:
    SELECT * FROM table_name WHERE BINARY field LIKE '%keyword%'

  • Installation of APC for PHP on Ubuntu is as simple as typing two lines of shell commands:

    sudo apt-get install php-apc
    sudo /etc/init.d/apache2 restart

  • Here are some quick steps for creating swap partition on Amazon AWS Micro Instance:

    dd if=/dev/zero of=/swapfile bs=1M count=1024

    mkswap /swapfile

    swapon /swapfile

    add the following to /etc/fstab to enable the swap on boot:

    /swapfile swap swap defaults 0 0


  • I had problems with displaying UTF-8 characters in my exported CSV files. Unlike LibreOffice Calc and Google Docs, this happened on only MS Excel. Here is a small hack:

    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . strlen($str) ."; ");
    header("Content-Disposition: attachment; filename=\"ourfilename.csv\"; ");
    header("Content-Type: application/");
    echo "\xEF\xBB\xBF"; // UTF-8 BOM
    echo $str;

  • Create root password for MySQL:
    mysqladmin -u root password NEWPASSWORD

    Update root password for MySQL:
    mysqladmin -u root -p'oldpassword' password NEWPASSWORD

  • If you would like to take periodic backups of your MySQL database, you can do it easily with cron:

    open crontab file:
    nano /etc/crontab

    add the following line at the end of file:
    */15 * * * *       root    /usr/bin/mysqldump -u<mysql_user> -p<mysql_password> <database_name> > <directory-to-save>-<file-prefix>`/bin/date +\%Y\%m\%d-\%H\%m`.sql
    (the above line orders cron to get your backup every 15 minutes)


  • sudo nano /etc/apt/sources.list

    we add the following lines to the end of file:
    deb sarge contrib
    deb sarge contrib

    sudo apt-key add jcameron-key.asc
    apt-get update

    sudo apt-get install webmin

    sudo /usr/share/webmin/ /etc/webmin root WEBMIN_PASSWORD