vzctl set <CTID> --hostname <newhostname> --save
MySQL: fixing ‘MySQL server has gone away (error 2006)’ error
If you try to import / restore some big MySQL database you may have encountered such error:
MySQL server has gone away (error 2006)
To fix it you would need to increase wait_timeout and max_allowed_packet:
wait_timeout = 6000 max_allowed_packet = 128M
It should fix the problem.
Postfix: how to disable local delivery
if you need to send emails from your Postfix server using MX records instead of local delivery you should leave the following line empty:
mydestination = $myhostname, localhost.$mydomain, localhost
in /etc/postfix/main.cf.
This way:
mydestination =
And restart the server:
/etc/init.d/postfix restart
Change a partiotion label
If for some reasons you need to change a partition name and you don’t neeed to re-format the partiotion you can use e2label :
e2label /dev/sdb1 <LABEL>
And that’s it.
How to minify HTML files
To provide best website performance it makes sense to minify static HTML files. There several ways to do that. One of the most easiest is to use django-htmlmin. To install run:
python-pip install django-htmlmin
To minify run:
pyminify index.html > index_minified.html
It would make sense to tar/zip files before you minify them.
You can also use it as a library for Flask and, obviously, Django. Check the documentation to get the details.
How to get RAW HTTP request in PHP for debugging
Here’s a quick way to log raw HTTP requests in PHP:
$env = print_r($_SERVER, TRUE);
$req = print_r($_REQUEST, TRUE);
$fp = fopen('/tmp/request.log', 'a');
fwrite($fp, $env);
fwrite($fp, $req);
where $env is environment parameters values and $req is request content. Handy.
How to fix ‘ImportError: No module named setuptools’ error on Ubuntu
If you get this error while trying to install some Python package it simply means that you don’t have setuptools module. To install it run:
sudo apt-get install python-setuptools
Now you can proceed.
Fixing “/etc/init.d/iptables: line 268: restorecon: command not found” on Centos
Here’s a problem:
[root@it2 /]# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables: /etc/init.d/iptables: line 268: restorecon: command not found [FAILED] [root@it2 /]#
And here’s the solution:
yum install policycoreutils
Trac: removing ticket
trac-admin <trac_env> ticket remove <ticket_id>
An example:
[trac@zorro trac]$ trac-admin ./ ticket remove 201 Ticket #201 and all associated data removed. [trac@zorro trac]$
Redis: “Can’t save in background: fork: Cannot allocate memory”
If you get this error
Can't save in background: fork: Cannot allocate memory
it means that your current database is bigger than memory you have. To fix the issue enable vm.overcommit_memory:
sysctl vm.overcommit_memory=1
To have if after reboot add this line to /etc/sysctl.conf:
vm.overcommit_memory=1