Windows : How to kill any process by using port number

First execute the below command using cmd –

netstat -a -o -n

To kill the process we need to check the PID of the process in the above output. Now just check the port number on which the process is running and then note down the PID.
Finally with the PID we can execute the following command to kill the process –

taskkill /F /PID 12345


Redirect Site to Maintenance Page when site is down

First of all, you have to create 2 files inside a site’s document root (mine is C:\xampp\htdocs\\web) :
1. maintenance.html – A file with the HTML code of the maintenance page.
2. maintenance.enable – An empty file that will activate the maintenance mode.
Create an empty file, named maintenance.enable, inside the site’s document root.

We’ll use it to turn the maintenance mode ON and OFF, without Apache restart.

So, if we need to TURN ON site’s redirection during maintenance, we create an empty maintenance.enable file.

And when we need to TURN OFF redirection after maintenance, we delete maintenance.enable file.

Redirect to Maintenance Page Using .htaccess ->

Place the following code in your site’s root .htaccess file at the starting  to redirect all visitors to the maintenance page :
<IfModule mod_rewrite.c>

#Following line should be added before any existing lines.
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123.456.789.000
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
Header Set Cache-Control “max-age=0, no-store”

Hope it works for you. 🙂

PHP Error : file_put_contents() Failed to open stream, invalid argument

If you are getting the following issue and document is not uploaded in your account  so this may be due to invalid path, incorrect file name or some special character in the full path.
Exception ->” [Symfony\Component\Debug\Exception\ContextErrorException]
Warning: file_put_contents(/tmp/echobox/1/4/SIGNED/auditTrail/63051764/Sample testing Local 19 1 17 3:33 PM eSSNu 2
017-01-19 02:03:19_audit.pdf): failed to open stream: Invalid argument
upload:documents documents”

Here , I can see  time-stamp is included in the file name which is not allowed in this function of file_put_contents() in php. Colon (:) is creating the main problem here. Actually the main reason is that we can’t create a text file having the colon in it’s name on windows.

Solution – Either don’t give the colon in the name or make a check to avoid this problem in the php code.


file_put_contents($path, $this->file);

$path= ‘C:/temp/test:12_check.txt’;
if (is_writable($path)) {
echo ‘The file is writable’;
} else {
echo ‘The file is not writable’;

It’ll say that file is not writable.

Common git commands that you must know

1) Downloads a repo to the local machine:                                git clone

2) Lists all new or modified files to be committed:                   git status

3) Snapshots the file in preparation for versioning:                  git add [file]

4) Records file snapshots permanently in version history:      git commit -m “[descriptive message]”

5) Uploads all local branch commits to Git:                               git push origin master

6) Update local repo with the latest commit:                            git pull

For working knowledge of git, you might want to refer below link:

If you are getting error at the first step, you need to add the key to your account from you git account as mentioned in below link.

Adding new ssh key

PHP based utility to do the re-encryption to migration application from PHP 5.5 to PHP 5.6

Context : The idea is to execute the php based utility which decrypts the column1 and column2 of table1 and table2 as well with crypt_key of size 12  and then encrypts the same column1 and column2 with crypt_key of size 24 in database. Now we can upgrade the app from PHP 5.5 to PHP 5.6. Followings are the steps which are needed to perform the desired task –

  1. Take the backup of application database. Please follow the below steps to take the backup –
    1. Go to Mysql installation bin directory (Mine is C:\Program Files\MySQL\MySQL Server 5.7\bin).
    2. Execute the below command and it’ll prompt for the database_password.
      1. C:\Program Files\MySQL\MySQL Server 5.7\bin> mysqldump -u database_user –password -h localhost database_name > C:\Users\tangupta\Desktop\AppDatabase_Backup.sql (Please change this path where you want to take backup)
        Enter password: ***********
      2. In case, you are not able to run the above command and getting the error like “mysqldump: Got error: 1045: Access denied for user ‘ODBC’@’localhost’ (using password: NO) when trying to connect”, Please check whether you had granted all the privilages on this database (local_app) in Mysql. if not , Please execute the below command on Mysql Command line client for the same –                       mysql> grant all privileges on db_name.* to ‘username’@’localhost’ identified by ‘password’;
  2. Execute the PHP script to decrypt and then encrypt the keys (column1 and column12 of table1 and table2 as well) in database. Please follow the below steps to execute the PHP script –
    1. Go to the path where script is saved (Mine is C:\xampp\htdocs)
    2. Execute the below command to do the same –
      1. C:\xampp\htdocs>php MigrationScript.php local_user local_pass local_dbname 012345678901 012345678901234567890123 C:\Users\tangupta\Desktop\DbMigrationScriptLogs.txt
        1. MigrationScript.php (Name of the PHP Script)
        2. (ServerName)
        3. local_user (database_user)
        4. local_pass (database_password)
        5. local_dbname (database_name)
        6. 012345678901 (Old 12 characters Encrypt Key as stored in PHP 5.5 chef recipe)
        7. 012345678901234567890123 (New 24 characters Encrypt Key as stored in PHP 5.6 chef recipe)
        8. C:\Users\tangupta\Desktop\DbMigrationScriptLogs.txt (path where you want to save the script logs)
          Note* – If you are not able to execute the script because of invalid character error, Please give the arguments in single quotes (Ex- ‘012345678901’). If there is some issue regarding database access with the user, please execute the query mentioned in step 1. (a. (ii.)).
      2. Now script will give ask user whether he/she wants to execute the script or not (Yes or No). If yes, script will continue to execute else it will halt the execution.
  3. Upgrade the App from PHP 5.5 to PHP 5.6.
  4. Update the crypt_key as per PHP5.6 statndard (Only keys of sizes 16, 24 or 32 supported) in the chef-recipe-bag.
  5. Deploy the application.
  6. In case there is any failure, Please rollback the database by using below steps-
    1. Go to Mysql Command line client.
    2. Execute the below command to restore from DB backup created at step 1 –
      1. mysql> source  C:\Users\tangupta\Desktop\AppDatabase_Backup.sql (Path where you took the db backup, please change this accordingly.)
    3. Downgrade the App from PHP 5.6 to PHP 5.5.
    4. Revert to the old 12 character encryt key in chef recipe and rebuild the app server.
  7. Finish.