mysql and mysqldump –defaults-file without a password

MySQL has an amazing option called –defaults-file. It can be used to store credentials in configuration file as it shown in example below:


Make sure you did not store such configration files anywhere inside public_html accessible via HTTP or HTTPS on your website. It is real security breach. Do not do it. Consider to change –defaults-file ../some_secure_path_outside_www/ permissions as low as 600 only accessible to user to read/write it. Nobody other should have access to it. Store such files outside of any virtual host htdocs, www or public_html folders.

With such configation files you can skip authorization when using mysql, mysqldump commands.
Example commands are:
1. To make db backup you can run command like:

# mysqldump --defaults-file=../some_secure_path_outside_www/ db1 > db1.sql

2. To restore db from SQL dump file you can execute command below:

# mysql --defaults-file=../some_secure_path_outside_wwwpath/ db1 < db1.sql

You could also use my PHP cli scripts to generate such .cnf configuration files automatically from a popular CMS and frameworks at:

Example usage of command below:

# php get_create_my_cnf.php /home/taras/public_html >../some_secure_path_outside_www/

Please, also look at documentation for more details:

Yii2 Framework console built-in web server can’t start

If you can`t start built-in web server in Yii2 Framework on Windows with error message like Document root “…\console/web” does not exist. in advanced application template you should use the following commands:

1. For backend admin application:

yii.bat serve/index --docroot="backend/web/"

2. For frontend application:

yii.bat serve/index --docroot="frontend/web/"

For basic application template use command:

yii.bat serve/index --docroot="web/"

On Linux or MacOS use ./yii instead of yii.bat

Check PHP files syntax for list of files on Linux

To check all PHP files syntax in current folders including subfolders you can use command like:

# find . -type f -name "*.php" -exec php -l {} \; | grep -v 'No syntax errors'

If you want to check few files syntax you can add them to some file e.g. /tmp/check-php-files-syntax.list and then run command below:

# for file in `cat /tmp/check-php-files-syntax.list`; php -l ${file}; done

Git: create archive

As you may know Git has wonderful feature create archive of files in repository.

For example, you can create Bash script to automate making of Git archives:


ZIP_NAME="_git_archives/taras-`date +'%Y%m%d%H%M'`.zip"

cd ${GIT_DIR}
# make zip archive from current git HEAD branch
git archive HEAD --format=zip -o ${ZIP_NAME}
# delete some files from zip archive
zip -d ${ZIP_NAME} ./.gitignore
echo "Archive file ${ZIP_NAME} is:"
ls -alh ${ZIP_NAME}
echo "Archive content:"
unzip -l ${ZIP_NAME} |more

Also, you can use tar format instead of zip and then to gzip it.

# git archive --format=tar --prefix=git-1.0/ v1.0 | gzip >git-1.0.tar.gz

v1.0 – is tag name of release to archive
–prefix=git-1.0/ – adds folder git-1.0/ inside archive
–format=tar – use tar format

Git: list files between two commits

To display changes between two commits you need to know SHA sum of commit.
You can take it from

# git log

command output.

Example command output:

commit 5b75d2ecf30b2ee9b28ca1febf60fb96b4d8625c
Merge: 78ac4ff4 ccb47ced
Author: Author Name <>
Date:   Mon Feb 13 22:27:55 2017 +0000

    Commit description goes here...

commit 4b6197f19f8c196e246d6277059f1d784e635a67
Author: Author Name <>
Date:   Mon Feb 13 20:34:38 2017 +0600

    Another commit description goes here...

Then you can run command:

# git diff --name-only 4b6197f19f8c196e246d6277059f1d784e635a67 5b75d2ecf30b2ee9b28ca1febf60fb96b4d8625c

it will show you list of changed files.

Alternatively, you can also use command:

# git diff --name-only HEAD~7 HEAD~14

to see the difference between seventh and fourteenth latest commits.

Set up password protection for virtual host in nginx

To set up virtual host password protection in Nginx you can follow such steps:

1. Created .htpassword file outside web server foot folder using commands below:

# echo -n 'user:' >> /var/www/taras/data/.htpasswd
# openssl passwd -apr1 >> /var/www/taras/data/.htpasswd

Second command will ask you for a password.

2. Add the following lines to Nginx configuration file /etc/nginx/nginx.conf

auth_basic "Restricted Content";
auth_basic_user_file /var/www/taras/data/.htpasswd;

into virtual host definition section.

PHP Warning: Unknown: Unable to allocate memory for pool. in Unknown on line 0

To fix error below:

PHP Warning: Unknown: Unable to allocate memory for pool. in Unknown on line 0

You should increase APC opcode cache parameter apc.shm_size, which is set to 32M by default and restart web server Apache module if PHP is set to wokr like web server module.

One more thing, you can switch off APC module for some domain or virtual host you can add the following lines to your .htaccess configuration file:

<IfModule mod_php5.c>
php_flag apc.cache_by_default off

Example usage of custom fields and shortcode parameters in WordPress CMS

WordPress CMS has a lot of useful features e.g. shortcodes, custom fields.
Look at the code example below:

function my_slider( $atts ) {
	global $post;

	extract( shortcode_atts( array(	'slide_category' => 0 ), $atts, 'slide_category' ) );
	$args = array(
		'post_type'  => 'slide',
		'showposts'  => -1,
		'meta_query' => array(
				'key'   => 'slide_category',
				'value' => $slide_category,
	$qry = new WP_Query($args);


add_shortcode('mySlider', 'my_slider');

In example above it allows to output slides of exact category on page.
Possible slider shortcode usage can be:

[mySlider slide_category="1"]

Where mySlider is shortcode, slide_category is shortocode attribute which allows us to display flides of particular category.
To set slide_category – custom field should be added to each slide with slide category id.

WP-CLI: command line interface for WordPress CMS

If you have shell access to your hosting account and your web server is running WordPress websites under Linux you should check amazing command line utility wp-cli.

Some usage examples:
1. Upgrade WordPress CMS core:

# wp core update

2. List installed themes:

# wp theme list

Example output

$ wp theme list
| name           | status   | update | version |
| twentyfifteen  | inactive | none   | 1.7     |
| twentyfourteen | inactive | none   | 1.9     |
| twentysixteen  | active   | none   | 1.3     |

3. Update themes example (in case if update is available):

# wp theme update twentyfifteen twentysixteen

4. List installed plugins:

# wp plugin list

Example output:

$ wp plugin list
| name                           | status   | update | version |
| akismet                        | inactive | none   | 3.2     |
| adsense-plugin                 | inactive | none   | 1.42    |
| google-analyticator            | inactive | none   | |
| google-analytics-for-wordpress | active   | none   | 5.5.4   |
| google-analytics-dashboard     | inactive | none   | 2.1.1   |
| google-captcha                 | active   | none   | 1.27    |
| google-sitemap-generator       | inactive | none   | 4.0.8   |
| hello                          | inactive | none   | 1.6     |
| limit-login-attempts           | active   | none   | 1.7.1   |
| socialize                      | active   | none   | 2.3     |

5. Update plugins (if update is available) example command:

# wp plugin update akismet limit-login-attempts