Change default PHP CLI configuration on RunCloud

Runcloud allows you to change the PHP Settings for each application from their Web Panel. But if you’re like me who heavily uses the PHP-CLI then changing config from Web Panel won’t help you. The PHP configs from their Web

Handful WP-CLI Tricks

Delete Posts based on search wp post delete $(wp post list –post_type=’post’ –s=’keyword here’ –format=ids) –force

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 Change timezone Source: https://askubuntu.com/a/594186 timedatectl set-timezone Asia/Kolkata # or use dpkg-reconfigure tzdata Change hostname To do this read: https://graspingtech.com/change-hostname-ubuntu-16-04/

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

LEMP stack in WSL

add-apt-repository ppa:nginx/stable add-apt-repository ppa:ondrej/php apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 add-apt-repository ‘deb [arch=amd64,arm64,i386,ppc64el] http://sgp1.mirrors.digitalocean.com/mariadb/repo/10.2/ubuntu xenial main’ apt update && apt upgrade -y apt install nginx-extras mariadb-server php7.3-fpm php7.3-pdo php7.3-mysql php7.3-zip php7.3-gd php7.3-mbstring php7.3-curl php7.3-xml phpdismod opcache service mysql start mysql_secure_installation

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 ) { // matches http and https both. $url = ‘https://cdn.statically.io/img/’. preg_replace( ‘#^https?://#’, ”, $url ) .”; return $url; }); More hooks: https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront-tweaks/blob/master/amazon-s3-and-cloudfront-tweaks.php

Add additional IP addresses to Ubuntu

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 Then add # Don’t greylist any domain. /.*/ Save and Exit, then enter commands: service postgrey restart service postfix restart Source: https://discourse.mailinabox.email/t/disable-greylisting-modify-whitelist/137/2   https://www.linuxbabe.com/mail-server/block-email-spam-check-header-body-with-postfix-spamassassin

Tweaking WSL (Windows Subsystem for Linux)

Use ‘exp’ command to open Windows Explorer Login as root in WSL then: touch /etc/profile.d/explorer.sh nano /etc/profile.d/explorer.sh Add the below lines to explorer.sh alias exp=”explorer.exe .” Now, reload settings using . ~/.profile . /etc/profile Done. Now whenever you type exp

Get 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