Git: search commits by author

To search commits by the author you can use the following command:

# git log --author="Taras Shkodenko"

where Taras Shkodenko example author name.

To get the list of all authors in a current Git repository use the useful command below:

# git shortlog -sne --all

Git: how to stash / unstash not commited changes

Git has a useful feature. You can stash not committed changes and then re-apply them. It helps you to restore the working directory and the index, to a clean working directory as it was before your not commited changes.

To stash your changes run a command below:

# git stash

To apply (unstash) your changes run a command below:

# git stash apply

To view list of stashes run a following command:

# git stash list

Read more about git stash on a documentation page.

Apache 2.4 virtual host config for a WordPress CMS

Example of a virtual host for web server Apache version 2.4 config to run a development copy of WordPress CMS:

<VirtualHost *:81>
    ServerName wpdev.test
    ServerAlias *.wpdev.test
    # Indexes + Directory Root.
    DirectoryIndex index.php index.html
    DocumentRoot "/Users/taras/wpdev/public_html"
    ErrorLog "/usr/local/var/log/httpd/wpdev.test/error.log"
    CustomLog "/usr/local/var/log/httpd/wpdev.test/access.log" common
    <FilesMatch \.php$>
        SetHandler "proxy:fcgi://"

    Options FollowSymLinks

PHP ?: ternary operator the Elvis operator

You can use ?: ternary operator in PHP then you need not empty value. Set value to a $action variable from $_POST[‘action’] parameter if it is not empty or use string default instead. It is shown in the example code below:

// Example usage for: Ternary Operator
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];

For more information see PHP documentation page for Ternary Operator.

In PHP 5.3, a shorter syntax for the ternary operator was introduced, which allows to leave out the middle part of the ternary operator for a quick shorthand evaluation. It is also called the Elvis operator sometimes because:

mysqldump: Got error: 1045: “Access denied for user … (using password: YES)” when using LOCK TABLES

Then I’ve developed MySQL backup script I’ve faced an error:

mysqldump: Got error: 1045: "Access denied for user '...'@'localhost' (using password: YES)" when using LOCK TABLES

which was fixed by adding


parameter to mysqldump command.

Also, if you dump InnoDB tables consider using the


parameter. As it is described in MySQL 5.7 documentation page.

Install multiple php versions on Ubuntu server

How to Install PHP 7.4 on Ubuntu.

All packages should be installed as a root administrator user.

Update Ubuntu Server Packages

Before we install anything new on a server, you should update your server packages:

# apt-get update && apt-get upgrade

Install PHP 7.4

Next, to install PHP 7.4 on Ubuntu 20.04, just run the following command:

# apt-get install php

To verify if PHP is installed, run the following command:

# php -v

Install PHP 7.4 modules (extensions)

These are the most common PHP 7.4 modules often used by php applications. You may need more or less, so check the requirements of the software you’re planning to use:

# apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml

How to install PHP 8.1 on Ubuntu 22.04 or 20.04

PHP 8.1 is the newest PHP version released on 25 Nov 2021. You can start using it now. These are the instructions on how to install it on Ubuntu 22.04 or Ubuntu 20.04 (or any other Ubuntu).

Add the PHP repository

To install PHP 8.0 you’ll need to use a third-party repository. We’ll use the repository by Ondřej Surý that we previously used.

First, make sure you have the following package installed so you can add repositories:

# apt-get install software-properties-common

Next, add the PHP repository from Ondřej:

# add-apt-repository ppa:ondrej/php

And finally, update your package list:

# apt-get update

Install PHP 8.1

After you’ve added the repository, you can install PHP 8.1 with the following command:

# apt-get install php8.1

This command will also install some additional packages:

  • libapache2-mod-php8.1
  • libpcre2-8-0
  • php8.1-cli
  • php8.1-common
  • php8.1-opcache
  • php8.1-readline
  • …and others.

And that’s it. To check if PHP 8.1 is installed on your server, run the following command:

# php -v

Install PHP 8.1 modules (extensions)

You may need additional packages and modules depending on your applications. The most commonly used modules can be installed with the following command:

# apt-get install php8.1-fpm php8.1-curl php8.1-dev php8.1-gd php8.1-mbstring php8.1-zip php8.1-mysql php8.1-xml

How to change the PHP version you’re using

If you have multiple PHP versions installed on your Ubuntu server, you can change what version is the default one.

To set PHP 8.1 as the default, run:

# update-alternatives --set php /usr/bin/php8.1