Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
mttjohnson / php_libxml_10mb_limit.txt
Created June 15, 2018 14:24
PHP XML 10MB Limit
Other people have run into this issue:
Warning: DOMDocumentFragment::appendXML(): Entity: line 1: parser error : CData section too big found in /magento/lib/internal/Magento/Framework/View/TemplateEngine/Xhtml/Template.php on line 60
https://github.com/magento/magento2/issues/4695
https://github.com/magento/magento2/issues/8084
Not saying they figured much out, but other people have been experiencing the issue as well.
The limit comes from the libxml library that PHP uses for XML processing:
http://php.net/manual/en/domdocument.loadxml.php#113676
@mttjohnson
mttjohnson / tail_logs_from_remote_systems
Created June 8, 2018 18:30
Tailing Logs From Remote Systems
ssh -tq user@host1 "tail -f /var/log/nginx/www.example.com-access.log | grep -i '/mypath.html'"
ssh -tq user@host1 "tail -f /var/log/nginx/www.example.com-access.log | grep -i '/mypath.html'"
ssh -tq user@host1 "tail -f /var/log/nginx/www.example.com-access.log | grep -i '/mypath.html'"
ssh -tq user@host1 "tail -f /var/log/nginx/www.example.com-access.log | grep -i '/mypath.html'"
@mttjohnson
mttjohnson / graphql_with_curl.sh
Created June 7, 2018 05:00
Making GraphQL Calls With Curl (for Magento 2)
# This example uses a GraphQL query meant for a Magento 2 (2.3 Alpha) endpoint
# Take a formatted GraphQL query and convert it to a JSON encoded string
GRAPHQL_QUERY=$(
echo '
{
products(
search: "Messenger"
filter: {
sku: {like: "24-MB%"}
@mttjohnson
mttjohnson / m2_atomic_config_deployment.sh
Created May 31, 2018 19:12
Magento 2 Atomic Config Changes
# Make a backup of the config
cp -a app/etc/env.php app/etc/env.php.bak
# Create new config file to use for replacement
cp -a app/etc/env.php app/etc/env.php.new
# Edit new config
vi app/etc/env.php.new
# Confirm syntax on file
@mttjohnson
mttjohnson / trace_mysql_conn_to_php_request.sh
Created May 25, 2018 01:31
Tracing a Long Running MySQL Connection to a PHP-FPM Process Request URI
# Find the request URI from a PHP-FPM process in a long running MySQL process
# Show MySQL processes to locate the connection you want to investigate
mysql -Be 'SHOW PROCESSLIST;'
# Id User Host db Command Time State Info Rows_sent Rows_examined
# 957890 myuser_prod 127.0.0.1:34452 mydbname_prod Sleep 0 NULL 158 632
# Find the client port from the mysql process list and save that to a variable
@mttjohnson
mttjohnson / chrome_dev_tool_filtering.txt
Created May 15, 2018 18:52
Chrome Developer Tools Filtering
# To filter network requests to only show requests to a specific domain and exclude urls with specific keywords
domain:www.example.com -static -media
# https://stackoverflow.com/questions/38524801/chrome-dev-tool-any-way-to-exclude-each-call-containing-a-string-with-regex
@mttjohnson
mttjohnson / replace_magento_crypt_key.sh
Last active August 11, 2020 20:59
Replace Magento crypt key
export NEW_CRYPT_KEY=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
php -r "
\$doc = new DOMDocument();
\$doc->load('app/etc/local.xml');
\$xpath = new DOMXPath(\$doc);
\$node = \$xpath->query('/config/global/crypt/key')->item(0);
\$oldtext = \$doc->createTextNode( \$node->textContent);
\$node->nodeValue = '${NEW_CRYPT_KEY}';
echo 'replacing ' . \$oldtext->wholeText . ' with ' . \$doc->createTextNode( \$node->textContent)->wholeText . \"\n\";
\$doc->save('app/etc/local.xml');
@mttjohnson
mttjohnson / local_public_dns_test.sh
Created April 19, 2018 19:50
Test if configuration expectations match local or public DNS results
# If local hosts files are routinely used it may be useful to have a script verify if the domain name
# is being overriden locally to a specific IP address, and if that IP should match what is publically
# being listed by public DNS servers.
# This is useful as a sanity check to make sure you have a local hosts file entry in place before running
# some operation, so that it doesn't hit the live site, and instead operates against the expected configured
# destination.
# It can also be used to abort if this operation is unsafe to run against the server when it is responding
# publically, and you only want the script to operate when the server is not live.
@mttjohnson
mttjohnson / system_audit.sh
Last active February 25, 2020 11:52
System Audit (last login)
# Show the full list of all recent login sessions
last
# Find the last time users logged into the system
lastlog
# Find the last time users logged into the system from wtmp files
for USER in `getent passwd | awk -F ":" '{print $1}'`
do
last -1 $USER | sed -e '/wtmp/d' -e '/^$/d'
@mttjohnson
mttjohnson / decrypting_ssl_tcpdump_curl_wireshark.sh
Created April 12, 2018 14:57
Decrypting HTTPS (SSL/TLS) with DH ciphers using tcpdump curl and wireshark
# Use this to capture packets on the web server side and then analyze in wireshark using
# curl as the HTTP client to log the pre master secret so that the packets can be
# decrypted and analyzed within wireshark
# This will work without exposing the server's private key and works with TLS 1.2 and DH ciphers
# During the handshake both client and server generate a new unique secret used to encrypt all
# communication that happens after the handshake. Curl can log that secret and wireshark can
# reference that log to decrypt packets captured by tcpdump.
# Tested with curl 7.59.0