Work (13)

MySQL Slow Query Log

Why, oh why, is this so complicated?!

Well, it’s not… just a bit confusing when you don’t know where to look.

TL,DR: (Ubuntu 16.04, otherwise YMMV, read below)

Add the following to your active configuration file for mysql

slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 2

What could go wrong?

Wrong configuration file:

on Ubuntu 16.04 the file can be in /etc/mysql/my.cnf or /etc/mysql/conf.d/mysql.cnf or even /etc/mysql/mysql.conf.d/mysqld.cnf

to find which one is “active”, run: mysqld --verbose --help |grep -A 1 "Default options"

the result is something like the following:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

if you open /etc/mysql/my.cnf, you will find at the bottom:
!includedir /etc/mysql/conf.d/

That’s where the actual files are stored.

Wrong variable names:

If you follow different tutorials on the Internet you will find configurations that mention:
DO NOT use that, it’s deprecated.
the new name of the variable is `slow_query_log_file` for the actual log file, and YOU SHOULD have `slow_query_log` as a boolean variable (ON, 1, or just mentioned in the file as per the code above).


Tail the /var/log/mysql/error.log in a separate terminal, see what’s failing. Example:

[Warning] option 'slow_query_log': boolean value '/var/log/mysql/mysql-slow.log' wasn't recognized. Set to OFF.
Obviously the variable is set wrongly to the filename. They are now 2 separate variables.

Similar Posts:

http ri mu

Similar Posts:

Now reading #Web Development with #Django Cookbook published…

Now reading #Web Development with #Django Cookbook published by #Packt:

Similar Posts:

find of the day Django Crispy Forms Forms…

find of the day:
Django Crispy Forms: Forms have never been this crispy

Similar Posts:

fix of the day Drupal stores extra php…

fix of the day:
Drupal stores extra php configuration (like memory_limit) in sites/default/settings.php
Drush is your friend!

Similar Posts:

Tweaking GitLab Setup


GitLab is your own GitHub and more (or less). They have pretty good introduction on the home page, so I won’t repeat that here.

The recommended installation method for GitLab is using the Omnibus package. Head to the downloads page and follow the instructions. You should have a GitLab setup in no time, who needs GitHub! oh well, many many people…

Now to the tweaks.


If you’re like me trying to hide the ports on your server from the bots and prying eyes, they you would have SSH on a different port and your other services all bound to localhost and facing the Internet bravely from behind a proxy server. I use Apache on my personal server, it’s pretty robust and gets the job done.

So let’s say SSH is on port 2022, and apache is taking firm hold on ports 80 and 443. So GitLab’s NGINX should take port 8088.

And the domain you’re using for gitlab is not the machine’s hostname, so hostname is ‘’ and gitlab’s URL is ‘’


Edit the “/etc/gitlab/gitlab.rb” file with the following changes/additions:

gitlab_rails['gitlab_host'] = ''
gitlab_rails['gitlab_ssh_host'] = ''
gitlab_rails['gitlab_port'] = 8088
gitlab_rails['gitlab_email_from'] = ''
gitlab_rails['gitlab_support_email'] = ''
gitlab_rails['gitlab_shell_ssh_port'] = 2022
external_url = ''

Then run gitlab-ctl reconfigure and see how it goes from there.

If things seem to be too complicated, you can always get a subscription option with full support from the GitLab folks. Or hire me to fix it for you!

Similar Posts:

Quickly Start a Django Project

There are many things I like to do when starting a django project. I started to compile those in a script I’m using. The gist is linked below.

New Django

# Author: Abdallah Deeb 
# Requirements: python, pip, virtualenv, virutalenvwrapper, git
# Edit the following 2 lines
if [ -n "$2" ]
if [ -n "$1" ]

source `which` 

echo "Starting a new Django project: $PROJECTNAME"
# Make a virtualenv
mkvirtualenv $PROJECTNAME

# Install latest django and start the project/app
pip install django startproject $PROJECTNAME

# conf is much nicer than projname
replace $PROJECTNAME conf -- conf/ conf/ conf/
chmod +x

# Initialize and use git
git init
git add .
git commit -a -m 'initial commit'

and the raw gist download

Similar Posts:

Drush in Jail Shell

I am not a drupal expert.
We got a request from a customer today asking to install drush in a jailed shell so that the user would only be able to run drush, but use it to do everything. Or at least this is how I understood the task.

Installing drush on CentOS (as root):

yum install php-pear
pear channel-discover
pear install drush/drush

Do I need jailkit?
Here’s how to install jailkit:

yum install gcc make
wget -c
tar xf jailkit-*.tar.bz2
cd jailkit-*
make install

The jailkit configuration files are in /etc/jailkit/

Jailing drush is in fact about jailing php-cli (or just php depending on your distro).

Turns out no scripts are needed (other than jailkit). I added the following to /etc/jailkit/jk_init.ini

comment = PHP and libs
paths = php
users = root, www-data, phpjtest
groups = root, www-data

comment = Drupal Shell
paths = /usr/bin/drush, /usr/share/drush, /etc/drush
includesections = php

And ran:

mkdir /srv/jail
chown root:root /srv/jail
chmod 0755 /srv/jail
jk_init -j /srv/jail jk_lsh
jk_init -j /srv/jail drush
adduser phpjtest
jk_jailuser -v -m -j /srv/jail phpjtest

Now to setup the drush alias:

mkdir ~/.drush/ # if not already there
vi ~/.drush/aliases.drushrc.php

with the following contents:

  'root' => '/var/www/',
  'remote-host' => '',
  'remote-user' => 'phpjtest',

Next, set up a passwordless login to the remote server using:

# this is done on the client side (home pc)
ssh-keygen -t rsa

And you should be able to run drush commands from the local machine using:
drush @remote1 status

Going to test this shortly…

Similar Posts:

Install Maven Script

Just a quick install script. Use it:

wget | bash

and here’s the gist of it

Similar Posts:

Table ‘mysql.servers’ doesn’t exist

That’s a bit confusing, but mainly all you need to do is:

Or if there’s a password on the admin account:
mysql_upgrade -u admin -p

Similar Posts: