Warith AL Maawali

0 %
Warith AL Maawali
Driving cybersecurity excellence
Innovator behind Linux Kodachi
  • Residence:
    127.0.0.1
  • Uptime Binary:
    101110
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Visual basic
Gambas
PHP
Delphi
Bash
  • Cybersecurity
  • Generative AI
  • Cloud & Automation
  • Cryptocurrency

Migrating from php 5.6 to 7.3

01/11/2019

Upgrading digi77.com: From PHP 5.6 to 7.3

I finally decided to upgrade digi77.com from PHP version 5.6 to 7.3 to benefit from the latest security enhancements and speed improvements. While I don’t regret making this upgrade, I encountered a few issues along the way. I would like to share these experiences with you to help you resolve similar problems more easily if you face them.

wp-code-highlight plugin: 


Once I updated to PHP 7.3, WordPress crashed due to one of the plugins, wp-code-highlight. This plugin uses preg_replace with \e to convert a double quote " into \". Unfortunately, \e is deprecated in PHP 7. To solve this, you need to use an anonymous function to pass the matches to your function. By updating the code to use an anonymous function, the issue with the wp-code-highlight plugin can be resolved, ensuring compatibility with PHP 7.3.

The file which had to be changed is wp-code-highlight.php

The old function code was:
Please replace the word xre to pre I had to change it because I am using the same plugin on this post!

PHP
function wp_code_highlight_filter($content) {

	if(get_option('wp_code_highlight_line_numbers')=='enable'){

		$line_numbers=' linenums:1';

	}

	else{

		$line_numbers='';

	}

	return preg_replace("/<xre(.*?)>(.*?)<\/xre>/ise",

		"''.wch_stripslashes('$2').''", $content);

}
PHP

 
The new code function to make it work is to use preg_replace_callback. Here is how I implemented it:

First, you need to find the part of the code that uses preg_replace with \e. Then, replace it with preg_replace_callback, which allows you to pass an anonymous function to handle the matches.

Please replace the word xre with pre in your actual code. I had to change it because I am using the same plugin in this post!

PHP
function wp_code_highlight_filter($content) {
/*  Warith new code */
	return preg_replace_callback("/<xre(.*?)>(.*?)<\/xre>/is",function($m) { if(get_option('wp_code_highlight_line_numbers')=='enable'){ $line_numbers=' linenums:1'; } else{ 	$line_numbers=''; }; return ''.wch_stripslashes($m[2]).''; },$content);

}
PHP

 
That made WordPress work smoothly again with PHP 7.3.
 


Mcrypt function:

The other issue I faced was that the Stealthwalker VPN software uses mcrypt on the server side to decrypt login details, and this encryption function was removed from PHP 7. To resolve this issue, I used the following commands on CentOS:

ShellScript
# Install epel-release repo if you do not already have it installed
yum install epel-release
# Install libmycrpt and libmcrypt-devel rpms needed for the PHP extensions.
# Update all Pecl php versions.
yum install libmcrypt libmcrypt-devel
Update all Pecl php versions.
for version in $(ls /opt/cpanel|grep ea-php); do /opt/cpanel/${version}/root/usr/bin/pecl channel-update pecl.php.net; done
# Install Mcrypt PHP extensions via Pecl for PHP72 and PHP73
/opt/cpanel/ea-php72/root/usr/bin/pecl install channel://pecl.php.net/mcrypt-1.0.1
/opt/cpanel/ea-php73/root/usr/bin/pecl install channel://pecl.php.net/mcrypt-1.0.2
# Restart Apache/Litespeed to make the new PHP extensions active.
service httpd restart
# Basically you are done by now but to check for the mcrypt extensions showing. credits goes to whattheserver.com
for phpver in $(ls -1 /opt/cpanel/ |grep ea-php | sed 's/ea-php//g') ; do echo "PHP $phpver" ; /opt/cpanel/ea-php$phpver/root/usr/bin/php -m |grep -E 'mcrypt'; done
ShellScript

 


 

Posted in Tech Blog
© 2024 Warith AL Maawali. All Rights Reserved.
Stay Secure, Stay Assured.