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:

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 Change timezone Source: 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: 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 CDN with WP Offload Media

add_filter(‘as3cf_get_attachment_url’, function($url) { // Regex matches both http and https. $url = ‘’ . 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 netmask 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:

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 # Replace sudo mv sources.list /etc/apt/ Fix files/folder 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 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: Create file {app-name}.location.main-before.rocket.conf