Htaccess file for WordPress websites

Create a .htaccess file on the root directory of your website. Then copy the content below on the .htaccess file: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / […]

How to Create Backups of MySQL via PHP

If you website is hosted on a web hosting like OVH, you should make sure to periodically backup your MySQL database as additional precaution, just in case the automated backup offered by the hosting provider fails. With OVH, for example, you can create cronjobs that execute PHP files located in your FTP home directory, here […]

Transfer files from a VPS to a FTP web hosting server

How to transfer files from a VPS to a FTP web hosting server? First login via SSH to your VPS. With “scp” you can transfer files from your VPS to the FTP server. Open the directory you want to copy to the other server, i.e: cd /home/user/wwwcd /home/user/www This command will copy files and folders […]

E: Sub-process /usr/bin/dpkg returned an error code (2)

If you get this error message while running apt-get install: dpkg: error: dpkg status database is locked by another process E: Sub-process /usr/bin/dpkg returned an error code (2)dpkg: error: dpkg status database is locked by another process E: Sub-process /usr/bin/dpkg returned an error code (2) Just type this to fix that error: dpkg –configure -adpkg […]

How to Validate JSON in PHP

Simple PHP function to validate JSON in PHP: function is_valid_json($string) { return !empty($string) && is_string($string) && is_array(json_decode($string, true)) && json_last_error() === 0; }function is_valid_json($string) { return !empty($string) && is_string($string) && is_array(json_decode($string, true)) && json_last_error() === 0; } Alternatively you can do like this (doing only one json_decode() call): $output = json_decode($string, true);   if (!is_array($output) […]

The program can’t start because VCRUNTIME140.DLL is missing

When opening an application in Windows OS you may encounter this error: The program can’t start because VCRUNTIME140.DLL is missing from your computerThe program can’t start because VCRUNTIME140.DLL is missing from your computer To fix this VCRUNTIME140.DLL error you just need to install: Microsoft Visual C++ 2015 Redistributable Update 3 RC

PHP CURL Download Remote URL to File

Simple PHP snippet to download a remote URL to a file: function curl_download_to_file( $url, $file ) { $fp = fopen($file, ‘w+’); $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, $url); curl_setopt ($curl, CURLOPT_TIMEOUT, 10); curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt ($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1"); curl_setopt ($curl, CURLOPT_HEADER, 0); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); […]

PHP Check if a file was modified more than 1 hour ago

Simple PHP snippet to check if a file was last modified more than 1 hour ago: if(time() – filemtime("/path/to/file") >= 1 * 3600) { echo "File was modified more than 1 hour ago"; }if(time() – filemtime("/path/to/file") >= 1 * 3600) { echo "File was modified more than 1 hour ago"; } Check if a file […]

Linux -bash: Input/output error or -bash: Read-only file system

If suddenly your Linux server show these messages: -bash: /usr/bin/who: Input/output error -bash: .bash_history: Read-only file system -bash: /bin/df: Input/output error-bash: /usr/bin/who: Input/output error -bash: .bash_history: Read-only file system -bash: /bin/df: Input/output error Ask your hosting company to check your server for hardware issues. most probably the hard-disk is broken/damaged.

Dropzone.js: Drag’n’Drop File Uploads with Image Previews

DropzoneJS is a modern and open source JavaScript library that provides drag’n’drop file uploads with image previews, showing nice progress bars. The main advatnage of DropzoneJS is that it doesn’t depend on any other library (like jQuery) and is highly customizable. The typical way of using DropzoneJS is by creating a form element with the […]