Enable two versions of PHP with Apache on Centos 7

I had Apache server running with PHP 5.6 using mod_php but needed PHP 7.3 for a particular application.

In order to have both installed at the same time I wanted to continue to use PHP 5.6 for all sites but only enable PHP 7.3 for a particular VirtualHost. To do this I continued to use mod_php for v5.6 and installed PHP-FPM for v7.3.

With the “remi” repo activated install “php73” (you should also install whatever other PHP 7.3 extensions you want):

yum install php73-php php73-php-fpm

Once installed you need to start the FPM server:

systemctl start php73-php-fpm
systemctl enable php73-php-fpm

In the configuration file for the VirtualHost that you wish to use v7.3

<VirtualHost>
  ......
  <FilesMatch \.php$>
  SetHandler "proxy:fcgi://127.0.0.1:9000"
  </FilesMatch>
<VirtualHost>

After updating the configuration file you’ll need to restart Apache:

systemctl restart httpd

Finally, if you need to run v7.3 of PHP from the command line enable it for the current session with:

scl enable php73 bash

or to enable for all sessions create an autoload file for bash in /etc/profile.d/php73.sh with the following content:

#!/bin/bash
source /opt/remi/php73/enable
export X_SCLS="`scl enable php73 'echo $X_SCLS'`"

Plesk 11 SSL certificates

I can never remember how to update SSL certificates on Plesk 11 from the command line.

To install a certificate (as ‘root’) use the following command:

/usr/local/psa/bin/ipmanage -u 180.235.134.238 -ssl_certificate NAME_OF_CERTIFICATE 

The names of the certificates can be obtained with:

/usr/local/psa/bin/ipmanage -s

From the web UI, use the following steps for installing SSL certificates:

1. Add your SSL certificate to the server using:
   Tools & Settings >> SSL Certificates
2. Follow the steps below:
   Tools & Resources >> IP Addresses
   2.1. Click the the IP: ???.???.???.???
   2.2. Change SSL certificate name from the drop down list (Select recently you have added).
   2.3. Click Ok button. 

Hope that helps someone.

Side-by-side editing of files in VIM

It you want to edit two files side-by-side in vi/vim then you can do it by using the -O option, as in this example:

# vim -O foo.txt bar.txt

I could never remember the option needed so thought I should note it here.

By the way, when you have finished, use :qa to quit all files being edited. If you just use :q you will have to type it to close each file. Also, use Ctrl+W, Ctrl+W to switch between the open files.

Sorting and comparing in vi / vim / vimdiff

I regularly use vimdiff to compare files on a local server with a remote server via SFTP. I keep forgetting how to get VI to refesh the view when one of the files has changed on the filesysem. It’s simply done with
:diffupdate
When comparing, if the order of lines in the file doesn’t matter and you think that they are similar except for the order, you can also use the built-in command:
:sort
to sort the lines. Mark the lines you want to sort first with visual marking mode (V) and then apply the sort.

Convert seconds to HH:MM:SS format in Excel

I need to know how to do this today but couldn’t find an easy copy and paste answer, so I had to make one myself.

Other solutions I have seen use the TIME function will work so long as the number of hours is less than 24, once they are higher then it will fail as it’s actually using a date format and just showing the time portion of it (and date formats cannot have more than 23 hours in a day). E.g. 86401 seconds (a day plus one second) will show “00:00:01″.

The way around it is to use a bit of maths (floor and mod) and build the hours, minutes and seconds up with concatenation. For example, in a new Excel document set the following cells:

A1=86401

A2=CONCATENATE(TEXT(FLOOR.MATH(A1/60/60),”00″),”:”, TEXT(FLOOR.MATH(MOD(A1,60*60)/60),”00″),”:”, TEXT(FLOOR.MATH(MOD(A1,60)),”00″))

(Note, the formula for A2 above should all be on one line.)

This will give a value of “24:00:01” which is what I needed.

Note, I’m purposely formatting the H, M and S values with two digits, but if the number of hours is larger than 99 then it will expand to three or more figures.

Hope someone finds this useful!

Directory listings from “dir” in Windows in wrong codepage

When trying to output a directory listing using
dir /b /s > files.txt
I had a problem where the accented characters were appearing incorrectly.

The solution (found in this answer on stackoverflow.com) was to change the codepage of the terminal before running the command with
chcp 1252
(in this case it changes it to the Western Europe codepage which is what I needed, other characters may require other codepages).

Running multiple versions of Skype on Windows 10

I like to keep my personal and work Skype accounts separate, and also have a “support” account as well, so I like to have multiple versions of Skype running on my work computer. Since upgrading to Windows 10 I am unable to use the “Launcher for Skype” software to have multiple copies running. The only way I found to accomplish what I needed was to use an old version of Skype and launch it on startup with a batch file.

In order to set this up you need to do the following:

  1. Install Skype 7.15 or lower (this isn’t that easy to find, you’ll need to search for this on sites which archive old versions of software)
  2. Create a batch file “C:\Users\%username%\Skype.bat” with the Skype usernames and passwords you user to login to each account. See a sample batch file below
  3. Create a shortcut in “C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup” which opens Skype.bat in a minimized window. If you give the shortcut a Skype icon it won’t even look like a script is running on startup.

Contents of Skype.bat (repeat the last 4 lines for each new account you wish to run, replacing XXXX with your username and YYYY with your password):

@echo off
echo Starting Skype: XXXX...
start "Skype: XXXX" "C:\Program Files (x86)\Skype\Phone\Skype.exe" /secondary /username:XXXX /password:YYYY
echo Connecting as: XXXX...
timeout 20

Windows Server 2012 wasn’t deleting old backups

Today I realised that our Windows 2012 backups were not working because we had run out of space on the backup disk. Windows Server Backup should automatically delete the oldest backups but for some reason it wasn’t doing this. (From what I read this may be due to corrupt snapshots.)

The solution seems to be to try to manually delete the oldest backup. This can be done by first giving the backup drive a drive letter (in this case E:) and then running:
vssadmin delete shadows /for=x: /oldest

However, this didn’t work for me as I received the error:

Error: Snapshots were found, but they were outside of your allowed context. Try removing them with the backup application which created them.

To fix this problem you need to view and delete them manually.

From the command prompt:

diskshadow
list shadows all
delete shadows set {id of shadow to be deleted if selective deletion is to be performed}

OR

delete shadows all {if all shadows are to be deleted}

This information was found on this site: https://support.software.dell.com/appassure/kb/121604

Process PayPal Express Checkout for third parties

Today I needed to find out how to process PayPal Express Checkout transactions for third parties. PayPal allows merchants to give permissions to other merchants to perform transactions on their behalf, without having to hand over their private API username, password and signature. While we have implemented Express Checkout for ourselves, I couldn’t find out how to perform the transaction on behalf of another merchant until I found this useful post.

To quote from the link above:

Yes, you specify an alternate “SUBJECT” of the transaction.

Normally your SetExpressCheckout request looks something like:

METHOD=&VERSION=&PWD=&USER=&SIGNATURE=&...

Now it will look like this:

METHOD=&VERSION=&PWD=&USER=&SIGNATURE=&SUBJECT=...

Payee_PayPal_Account is the email address/username the user uses to log in.

(Note that email address/username is NOT the API username of the account.)

Thanks Jeremy!