Tips & Tricks

E: Could not get lock /var/lib/dpkg/lock-frontend – … [Fix]

I’m hosting a few websites for some friends and clients which most of them are running on Ubuntu.

Once or twice a month I always go read logs remove cache and pull the patch if any.

The most common commands to pull those security updates I run are:

$ apt-get update
$ apt-get upgrade
$ apt-get dist-upgrade.

Sometimes I was distracted by my son or some chores so that I ended up losing the connection as I always use SSH.

Most of the time I got the error like this:

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

The easy fix is to remove the lock files that the dist-upgrade command has produced.

$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/cache/apt/archives/lock
$ sudo rm /var/lib/dpkg/lock*

Then reconfigure the packages. Run in terminal:

sudo dpkg --configure -a
sudo apt update

Then the problem should have been fixed!

Tips & Tricks

Set Date/Time Automatically from Google on Ubuntu 18

I’ve once had a problem on one of my Ubuntu 18 servers on timing not syncing from the internet.

Use the following command:

sudo date -s "$(wget -qSO- --max-redirect=0 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
Tips & Tricks

Copy the SSH Key from Macbook Pro

As an enthusiastic developer, there are times when I need to collaborate with other people on projects that hosted in a central repository such as GitHub, Bit Bucket, or Gitlab.

Without the need to always type in the password on push, I need to add my SSH Key to that repository the enable it to recognize my development machine. In my case, I use mac.

Generating the key

In case you’re on a brand new Macbook and which has not yet generated a key before. To generate, open the terminal and run the following command:

ssh-keygen -t rsa -b 4096

Hit enter to accept the default location. Then once it prompts you to enter a passphrase, enter it or leave it blank to never require a passphrase on committing to the remote repository.

The next step is to copy the key and use it at your repository’s account profile.

Copying the key

Open the terminal and run the following command:

pbcopy < ~/.ssh/
Tips & Tricks

Using rsync to Upload Large Files to the Remote Server

I once met a situation when I could not upload a large compressed css file to the remote server via any ftp softwares either FileZilla or Cyber Duck.

I could not figure out why even I’d tried to increase timeout setting, reduce the number of connection, etc. still it ends up the same.

Then I decided to transfer the file via SCP. But it was too slow as SCP always verifies its credentials at every connection established.

The other possible method is to use rsync upon this recommendation.

The syntax is simple:

rsync -avzh style.css vkhost@

Where /home/vkhost is the destination directory to have my style.css file moved to. It was done in just a blink of an eye for the file over 175kb.

Using rsync to Upload Large Files to the Remote Server
Tips & Tricks

Fixed: Corrupt SQL file contains unicode characters

I happened to have my backup sql file which contains Unicode characters broken. This happened when I had just bought a new version of Mamp Pro to install in my Mac. It comes with the latest PHP and a lot of exiting features!

I then re-installed my database of one project that contains Unicode characters. Unfortunately, it shows strange characters like below:

It’s a double converted character. To fix it, simply:

  1. Convert back to latin1
  2. Convert to binary
  3. Convert to utf8

So, go to the SQL tab of the phpMyAdmin, and run the following command:

alter table table_name modify field_name VARCHAR(2000) character set latin1;
alter table table_name modify field_name blob;
alter table table_name modify field_name VARCHAR(2000) character set utf8;

Then the unicode character will be back.

Tips & Tricks

Using Bootstrap 4.3.1 and Error Occurs When Triggering compass watch

Playing around with Twitter Bootstrap 4.3.1 is fun!

Initially, when triggering the compass watch from my terminal the error occurs like below:

error sass/bootstrap/bootstrap.scss (Line 4 of sass/bootstrap/_root.scss: Invalid CSS after "...lor}: #{$value}": expected "{", was ";")

The fix is simple. First, reinstall sass and compass to the latest version:

gem uninstall sass
gem uninstall compass
gem install sass
gem install compass

Then go to the _root.scss file in your bootstrap folder, and change the following codes:

@each $color, $value in $colors {
--#{$color}: #{$value};
@each $color, $value in $theme-colors {
--#{$color}: #{$value};
@each $bp, $value in $grid-breakpoints {
--breakpoint-#{$bp}: #{$value};


@each $color, $value in $colors {
#{--#{$color}}: #{$value};
@each $color, $value in $theme-colors {
#{--#{$color}}: #{$value};
@each $bp, $value in $grid-breakpoints {
#{--breakpoint-#{$bp}}: #{$value};

Run compass watch again and the error goes away. Cheers!

Tips & Tricks

Delete content of a file using Truncate

There are times when we need to remove content from a file from our server space. Especially, those unwanted log content which are produced on the fly by your codes on purpose.

To my experience, some logs that are already checked should be deleted to save server space.

Note that when the log file exceeds the maximum file size defined in the configuration, it created another new one and rename the previous one to be something like,, and so on.

To remove those backup logs, just excecute the command


To delete the content of the file, run the following command:

truncate -s 0

Upgrade PHP to 7.2 on Vesta CP

This morning I’m working on upgrading my Vesta CP to use PHP 7.2 as from the newly released WordPress 5.1 suggestion.

1. Add PHP Repository to my Debian

In my case, my Ubuntu operating system does not have PHP Repository yet. I then install it by running the following command:

sudo apt-get install software-properties-common

Then go add the PHP repository by running the following command:

sudo add-apt-repository ppa:ondrej/php

After that I need to make sure this repository is available on my call. I then run the following command:

sudo apt-get update

2. Install PHP 7.2

Now everything needed is available on the server. Installing PHP 7.2 by running:

sudo apt-get install php7.2

3. Tell Apache to use PHP 7.2

The Apache server is still using the previous version of PHP unless I disable the previous one and enable the 7.2 version.

To disable the previous PHP version, in my case, PHP 5, run:

sudo a2dismod php5 

To enable the newest version of the installed PHP, run:

sudo a2enmod php7.2

To get the change affected, restart the apache server:

sudo service apache2 restart

4. Installing Extensions

There are extensions that might be needed to replace the deprecated ones or required by PHP 7.2. The following extensions are some that may fix your need:

sudo apt-get install php7.2-common libapache2-mod-php2.1 php2.1-cgi php7.2-cli php7.2-phpdbg php7.2-fpm libphp7.2-embed php7.2-dev php7.2-curl php7.2-gd php7.2-imap php7.2-interbase php7.2-intl php7.2-ldap php7.2-mcrypt php7.2-readline php7.2-odbc php7.2-pgsql php7.2-pspell php7.2-recode php7.2-tidy php7.2-xmlrpc php7.2-json php-all-dev php7.2-sybase php7.2-sqlite3 php7.2-mysql php7.2-opcache php7.2-bz2 libapache2-mod-php7.2 php7.2-mbstring php7.2-pdo php7.2-dom phpize7.2

To get these extensions up and running, restart the apache:

sudo service apache2 restart

5. Fixing Errors After Upgrading to 7.2

In my case, I got an error saying “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”

As per it says, the MySQL extension is missing. To fix, go install it:

sudo apt-get install php-mysql

Then restart Apache:

sudo service apache2 restart

I also met the CURL error too when hitting save a post on WordPress. To fix, simply install the CURL extension and restart apache

Install CURL extension:

sudo apt-get install php7.2-curl

Restart Apache:

sudo service apache2 restart

Install Image Magic

sudo apt-get install php-imagick

Restart Apache:

sudo service apache2 restart

6. Known unsupported WordPress plugins

There are a few PHP warning errors of some WordPress plugins after upgrading PHP to version 7.2.

In this time of writing, those plugins are:

  1. All Push Notifications
  2. Facebook Instant Articles
  3. JetPack

Read more tips on migrating from PHP 5 to PHP 7 part 1 and Part 2

Tips & Tricks

Setup Static IP on Ubuntu 18.04 Server

I was playing around with setting up my own Ubuntu server for an intranet system to use within the company.

Everything works out of the box, almost like Windows ;). The thing that I think would be very much useful in the future is to set a static IP so that even if the server is moved or changed within the network, everyone can still access to the it without changing the IP.

To do so, go to /etc/netplan and you’ll find a file called 50-cloud-init.yaml (the file name might be different in your server). Edit it to match the following setting:

#This file is generated from information provided by
#the datasource. Changes to it will not persist across an instance.
#To disable cloud-init's network configuration capabilities, write a file
#/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
#network: {config: disabled}

renderer: networkd
addresses: []
dhcp4: no
optional: true
addresses: []
addresses: []
dhcp4: true
version: 2

Save and type the following command: suo netplan --debug apply

Tips & Tricks

Change VestaCP admin Password

There are times when you are not able to log back in to the VestaCP as of your admin account. However, you still can login using normal user accounts. To fix this, try the following solution:

  1. Log in to the server via SSH
  2. run the following command: $v-change-user-password USER NEWPASSWORD // where USER is admin and NEWPASSWORD is the password you want
  3. Login back to your VestaCP pannel using the username: admin and password: YOUR NEW PASSWORD