How to use .htaccess to run all .html files as .php by using PHP handlers in Apache w/o CGI?

If you are not able to find the correct Handler, Simply create a .php file with the following contents:

<?php echo $_SERVER['REDIRECT_HANDLER']; ?>

and run/open this file in browser.

application httpd handler
example application handler

Use this output in .htaccess file

Create a .htaccess file at the root of your website(usually a folder named public_html or htdocs on linux servers) and add this line:

AddType [[THE OUTPUT FROM ABOVE FILE]] .html .htm

Example

AddType application/x-httpd-php70 .html .htm
AddType application/x-httpd-php72 .html .htm
AddType application/x-httpd-php .html .htm

If your are running PHP as CGI then try something like this:

AddHandler application/x-httpd-php .html .htm

Important Note:

If you see blank page or Notice: Undefined index: REDIRECT_HANDLER

Try default in .htaccess

AddHandler application/x-httpd-php .html

If you are godaddy user, try one of these settings:

Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
AddHandler x-httpd-php7 .php .html
AddHandler x-httpd-php5-cgi .html
AddHandler x-httpd-php7-cgi .html

Reference: https://stackoverflow.com/questions/4687208/using-htaccess-to-make-all-html-pages-to-run-as-php-files/49375772#49375772

How to setup / enable Directory index listing?

When a web browser is pointed to a directory on your website which does not have an index.html file in it, the files in that directory can be listed on a web page.

Directory Lister is a simple PHP script that lists the contents of any web-accessible directory and allows navigating therewithin. Simply upload Directory Lister to any directory and get immediate access to all files and sub-directories under that directory. Directory Lister is written in PHP and distributed under the MIT License.

http://www.directorylister.com

Directory Lister requires PHP 5.3+ to work properly. For more information on PHP, please visit http://www.php.net.

steps to set up directory listing:

  1. Open “public_html” and Upload “index.php” and “resources” folder.
  2. Now go to “resources” directory and rename “default.config.php” to “config.php”.
  3. Also, upload additional files to the same directory as index.php.
  4. All Done!!!

Enable / Disable directory index listing.

enable:

To have the web server produce a list of files for directories, use the below line in your .htaccess  (can be found in FTP -> public_html folder):

Options +Indexes

disable:

To have an error (403 – Forbidden) returned instead, use this line:

Options -Indexes

When enabled you can visit your website to see Directory listing.

Hope, this post was helpful.

Thank You.

How to edit default python version for a linux user?

Edit the bash profile and add an alias using the following code

$ nano ~/.bashrc

Put the following line of code in .bashrc file and alter the python3.6 path as per your new installation

alias python='/usr/local/bin/python3.6'

Use CTRL x to exit and save
After that you need to reload the source, so use the following command and you are good to go.

$ source ~/.bashrc

How to increase EBS storage block size on a running spot instance in AWS?

So, you created a aws group with a small ebs storage size and now that the site is in production, storage disk is full and it was mounted as root storage, now you are asking “MY AWS INSTANCE STORAGE IS FULL, WHAT TO DO?”
or “How do I increase the EBS volume size of a running instance?”

So, here is the simple solution:

There are two commands which will help you

$ lsblk

and

# df -h

So, initially if you login via SSH (using PUTTY or anything else) you will see something like this:

So, what you need to do is, you need to go to aws console and edit block size in EC2 management

Go to EBS > Volumes
Right Click the volume you need to expand and choose MODIFY VOLUME
Enter the new size you want for your block

Now run the command lsblk and df -h and you will notice the old size and new size under xvda and xvda1

Size available but not used

If you dont see the updated new size, please use init 6 or restart the instance using any other command

You now need to use utility growpart so use command


sudo apt install cloud-utils

If you are out of space, please remove any old files which are of no use anymore to free up some Mega Bytes
After that, simply use


sudo growpart /dev/xvda 1

and
sudo resize2fs /dev/xvda1
resize2fs command
lsblk after resize
df command after resize

Reference: 
https://stackoverflow.com/a/43251901/2229148


tk120404

Removing extra digits after decimal and leave only two decimal places

^(.*?\..?.?).*?$

your first match will leave the number with max 2 decimal digits.
So find with ^(.*?\..?.?).*?$ and replace with \1

Input

27485.0375
75777.9125
10785.0125
13822.5
26700
41194.375
9375
4354.225
11564.475
12430.1
3246.4875
11596.3375
22466.0375

Output:

27485.03
75777.91
10785.01
13822.5
26700
41194.37
9375
4354.22
11564.47
12430.1
3246.48
11596.33
22466.03

How to save Windows 10 Lockscreen wallpaper image in laptop?

Windows 10 lockscreen feature is called spotlight and you see new beautiful pictures on your window 10 when ever it is locked.
These pics are present in Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy folder and are not having correct extensions as these are raw images and probably microsoft doesnt want them to be indexed in your gallery.
So, the process is simple, open Command Prompt
For opening command prompt, press windows button and then type cmd and click/enter on first result

OR Press Windows + R and then type cmd followed by Enter key.
After you see command prompt’s black screen,, copy and paste the following code in it and that is it.
You can find the lock screen pictures inside you “My Pictures” > “Lockscreenwallpapers” Folder.

mkdir "%userprofile%\Pictures\Lockscreenwallpapers"
copy "%userprofile%\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\*" "%userprofile%\Pictures\Lockscreenwallpapers\"
C:
cd "%userprofile%\Pictures\Lockscreenwallpapers\"
ren *.* *.jpg
exit
 

How to add colon separated hours in PHP using explode function twice?

Problem Statement

Tracking hours for multiple days are available in HH:MM:SS format separated by tab element. Add all the time to show total hours worked/tracked.

<?php
$a="03:23:28	03:58:54	00:00:00	03:10:49	02:17:33	03:56:38	02:18:23	06:15:42	00:00:00	00:00:00	06:04:51	07:41:09	03:23:15	06:12:59	03:51:27	00:00:00	04:30:06	05:00:23	00:00:00	04:34:25	05:17:02	01:36:21	00:00:00	03:53:20	06:30:52	06:21:47	04:54:16	03:22:28	03:10:35	00:00:00	06:37:11	02:14:22	03:06:49	03:05:44	02:35:54	04:03:22	00:00:00
";
#$a="04:05:21	06:25:39	03:02:36	04:01:17	03:03:21	02:00:36	04:21:54	04:21:35	00:00:00	00:00:00	03:39:21	04:19:17	03:08:14	01:44:48	03:28:11	00:00:00	03:05:53	03:05:34	00:00:00	02:09:17	05:01:13	01:02:20	00:00:00	04:30:51	06:03:49	06:36:35	02:14:01	03:06:38	04:02:09	00:00:00	02:34:29	03:36:30	05:10:17	06:46:19	07:48:08	09:13:34	00:00:00
#";
$a="07:28:49	10:24:33	03:02:36	07:12:06	05:20:54	05:57:14	06:40:17	10:37:17	00:00:00	00:00:00	09:44:12	12:00:26	06:31:29	07:57:47	07:19:38	00:00:00	07:35:59	08:05:57	00:00:00	06:43:42	10:18:15	02:38:41	00:00:00	08:24:11	12:34:41	12:58:22	07:08:17	06:29:06	07:12:44	00:00:00	09:11:40	05:50:52	08:17:06	09:52:03	10:24:02	13:16:56	00:00:00
";
$f=explode("\t",$a);
$th=$tm=$ts=0;
foreach($f as $ele){
	
	$ht=explode(":",$ele);
	$hours=intval($ht[0]);
	$minutes=intval($ht[1]);
	$seconds=intval($ht[2]);
	$th+=$hours;
	$tm+=$minutes;
	$ts+=$seconds;
}
$mm=intval($ts/60);
$ts=$ts%60;
$tm+=$mm;
$hh=intval($tm/60);
$tm=$tm%60;
$th+=$hh;

echo "$th:$tm:$ts";
?>

Extracting names from given list of URLs (using regex)

let us extract name form the URL
https://www.google.com/name?=rajiv
paste the URL in the notepad and press crtl+f , and select ‘regular expressions ‘ from search mode

find in notepad

now, enter the regex in the find tab to fetch names
.*?\?=(\w+)$

Now, the selected name will be fetched form regex as (\1).

it can work on numerous links like:-

https://www.google.com/name?=rajiv/
http://www.example.com/asdas?=borde/id=?
http://www.example.com/asdasd?=bordex
http://www.example.com/name?=bordet
http://www.example.com/asdasd?=border
http://www.example.com/jsciloji?=bordeeeee
http://www.example.com/name?=bordee
http://www.example.com/name?=bordeeeeeee
http://www.example.com/09328e?=bordeeee
http://www.example.com/name?=borde
http://www.example.com/lpaosd?=borde

And only the part after first “?=” will be fetched

MySQL error 1449: The user specified as a definer does not exist

Why this error happens?

Most of the times, reason is that your database dump through command line or PhpMyAdmin or even other libraries can have SQL’s Definer statements. Now, as per MySQL’s Official Documentation:

The DEFINER clause specifies the MySQL account to be used when checking access privileges at routine execution time for routines that have the SQL SECURITY DEFINER characteristic.

MySQL Reference Manual v8.0

Solution: MySQL mysqldump create a safe backup to ensure no corruption

Use the following command to create backup of your mysql database. Put the command in terminal

mysqldump -hHOST -uUSERNAME -p DATABASE_NAME | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > BACKUP_NAME.sql

With gzip compression > backup

mysqldump -hHOST -uUSERNAME -p DATABASE_NAME | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | gzip > BACKUP_NAME.sql

Reference: https://stackoverflow.com/a/9447215/2229148