Fix CMD output when using shell_exec() from PHP

/** * Fix weird output encoding. */ function run_command($command) { $string = shell_exec($command); $string = mb_convert_encoding($string, ‘UTF-8’, ‘UTF-16LE’); return $string; } Source: https://www.reddit.com/r/PHPhelp/comments/de27u8/why_output_of_shell_exec_is_different/f2uwy7s

Linux touch command for Windows

Create touch.cmd with the following content and it to ENV Path. @echo off setlocal enableextensions disabledelayedexpansion (for %%a in (%*) do if exist “%%~a” ( pushd “%%~dpa” && ( copy /b “%%~nxa”+,, & popd ) ) else ( type nul

Things to do after deploying a Ubuntu server

Disable ipv6 Create /etc/sysctl.d/60-ipv6-disable.conf with the following contents: net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 Run service procps restart If Ubuntu 18.04 then view https://ip-life.net/disable-ipv6-on-ubuntu-18-04/ Change timezone Source: https://askubuntu.com/a/594186 timedatectl set-timezone Asia/Kolkata # or use dpkg-reconfigure tzdata Change hostname

Tweaking OneSignal WordPress Plugin

/** * Send push based on last active time (Intelligent Delivery). */ add_filter( ‘onesignal_send_notification’, function( $fields ) { $fields[‘delayed_option’] = ‘last-active’; return $fields; }); /** * Always set notification unchecked in post editor. */ add_filter( ‘onesignal_meta_box_send_notification_checkbox_state’, ‘__return_false’ ); /** *

Tweaking cURL

Enter %APPDATA% in Run. Then create file _curlrc with the following content insecure

Tweaking WordPress

/** * Logged in for 1 year. */ add_filter( ‘auth_cookie_expiration’, function() { return YEAR_IN_SECONDS; });

Clear cache in WP Rocket when post permalink (slug) changes

To learn more about the issue: https://github.com/wp-media/wp-rocket/issues/1936 Fix: // Fires before an existing post is updated in the database. add_action( ‘pre_post_update’, function( $post_ID, $data ) { // Compare slug, if changed clear cache. if ( get_post_field( ‘post_name’, $post_ID ) !=

Use statically.io CDN with WP Offload Media

add_filter(‘as3cf_get_attachment_url’, function($url) { // Regex matches both http and https. $url = ‘https://cdn.statically.io/img/’ . preg_replace(‘#^https?://#’, ”, $url); return $url; }); More hooks of WP Offload Media can be found on amazon-s3-and-cloudfront-tweaks.php

Add additional IP addresses to Ubuntu 16.04

Login as root then enter command nano /etc/network/interfaces If have something like this on that file iface enp1s0f0 inet static address 123.124.125.40 netmask 255.255.255.0 gateway 123.444.123.1 Then to add additional ips, have it like this iface enp1s0f0 inet static address

Tweaking Mail-in-a-Box

Disable Greylisting Disabling Greylisting helps to receive emails without any delay. touch /etc/postgrey/whitelist_clients.local nano /etc/postgrey/whitelist_clients.local Add contents: # Don’t greylist any domain. /.*/ Save and Exit, then: service postgrey restart service postfix restart Source: https://discourse.mailinabox.email/t/disable-greylisting-modify-whitelist/137/2

Tweaking WSL (Windows Subsystem for Linux)

Change apt mirrors (India only) # Create backup first sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup # Download modified sources.list wget https://gist.githubusercontent.com/Dibbyo456/e395373796ffba5005aa5e771ad7da1b/raw/e6e0865a788929cb17b7d60b4863e8dd6f3f8026/sources.list # Replace sudo mv sources.list /etc/apt/ Fix files/folder permissions https://www.turek.dev/post/fix-wsl-file-permissions/ Add some useful aliases cd && touch .bash_aliases add below lines

Get all system IPv4 addresses as array in PHP

/** * Get system ipv4 addresses. * Works on Linux only. * @return [array] */ function getSystemIPs() { $ips = shell_exec(‘hostname -I’); $ips = preg_split(‘/\s+/’, $ips, -1, PREG_SPLIT_NO_EMPTY); foreach ($ips as $ip) { if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE |

Use Rocket-Nginx under RunCloud

Login as root then enter following commands. cd /etc/nginx-rc git clone https://github.com/satellitewp/rocket-nginx.git cd rocket-nginx cp rocket-nginx.ini.disabled rocket-nginx.ini php rocket-parser.php As of version 2.1.1 there is a typo in the rocket-nginx.ini , change media_header to medias_header My template: https://gist.github.com/Dibbyo456/2b08a4ff74665ccc40e0985b8f22292a Create file {app-name}.location.main-before.rocket.conf