<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Katz Ueno</title>
    <description>The latest articles on DEV Community by Katz Ueno (@katzueno).</description>
    <link>https://dev.to/katzueno</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F67969%2F0a411524-89bc-4702-a8bc-61d1e002a99b.jpg</url>
      <title>DEV Community: Katz Ueno</title>
      <link>https://dev.to/katzueno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/katzueno"/>
    <language>en</language>
    <item>
      <title>Concrete CMS + Cloudflare: How to fix logging out problem</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Fri, 19 May 2023 07:05:26 +0000</pubDate>
      <link>https://dev.to/katzueno/concrete-cms-cloudflare-45fa</link>
      <guid>https://dev.to/katzueno/concrete-cms-cloudflare-45fa</guid>
      <description>&lt;p&gt;You have a Concrete CMS website and using Cloudflare. When you enable DNS proxy of Cloudflare, your Concrete CMS website started to log out frequently and became uneditable.&lt;/p&gt;

&lt;h2&gt;
  
  
  The reason why you get logged out
&lt;/h2&gt;

&lt;p&gt;It's because Concrete CMS (Symfony framework) thinks you maybe compromised because your IP keeps changing.&lt;/p&gt;

&lt;p&gt;Concrete CMS is built with Symfony framework. Symfony framework has security measurement to monitor user's session and IP address.&lt;/p&gt;

&lt;p&gt;If user's IP address changes but the user session is the same, Symfony thinks that user session was hijacked and Symfony invalidates the session (log you out).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F164ewcczpyk9dzjcn3r1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F164ewcczpyk9dzjcn3r1.png" alt="Cloudflare in the middle of web server" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;When you enable Cloudflare's DNS proxy mode, your traffic start to go through Cloudflare servers, then reaches Concrete CMS server.&lt;/p&gt;

&lt;p&gt;Now, your Concrete CMS server see Cloudflare's IP as user's IP address instead of your IP address.&lt;/p&gt;

&lt;p&gt;Since Cloudflare has so many edge locations, you often access to different edges every time you access your site.&lt;/p&gt;

&lt;p&gt;Which means that Concrete CMS sees the same user is accessed from different IP request after request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symfony's trusted_proxy setting
&lt;/h2&gt;

&lt;p&gt;But here is a good news. Symfony is already providing the solution.&lt;/p&gt;

&lt;p&gt;You can set the range of Cloudflare's IP range.&lt;/p&gt;

&lt;p&gt;Once you set the proxy address, the PHP application start to respect X-Forwarded-For header.&lt;/p&gt;

&lt;p&gt;When the traffic go through Cloudflare, the Cloudflare embed the header called X-Forwarded-For which include the original user's IP address.&lt;/p&gt;

&lt;p&gt;For more detail info you can read Symfony documentation: &lt;a href="https://symfony.com/doc/current/deployment/proxies.html" rel="noopener noreferrer"&gt;How to Configure Symfony to Work behind a Load Balancer or a Reverse Proxy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will skip why Symfony does it but it's very important security measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to set-up Concrete CMS.
&lt;/h2&gt;

&lt;p&gt;Anyway, where is Cloudflare's IPs?&lt;/p&gt;

&lt;p&gt;Of course, Cloudflare provides its IP ranges at &lt;a href="https://www.cloudflare.com/ips/" rel="noopener noreferrer"&gt;their own IP page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You set these IP ranges to Concrete CMS.&lt;/p&gt;

&lt;p&gt;Concrete CMS of course has &lt;code&gt;Trusted Proxy&lt;/code&gt; config.&lt;/p&gt;

&lt;p&gt;It can set it up via dashboard or CLI add-on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dashboard way
&lt;/h3&gt;

&lt;p&gt;Here is the steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwitttfnqk1rorl711s9j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwitttfnqk1rorl711s9j.png" alt="Concrete CMS trusted proxy setting page" width="800" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disable Cloudflare DNS proxy for a moment&lt;/li&gt;
&lt;li&gt;Log-in to Concrete CMS as an admin&lt;/li&gt;
&lt;li&gt;Visit &lt;code&gt;System and Settings&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Go to &lt;code&gt;Permission and Access&lt;/code&gt; - &lt;code&gt;Trusted Proxy&lt;/code&gt; page&lt;/li&gt;
&lt;li&gt;Enter the Cloudflare's IP range in the text box and save&lt;/li&gt;
&lt;li&gt;Enable Cloudflare DNS proxy and test if it works.&lt;/li&gt;
&lt;li&gt;Come back to visit &lt;a href="https://www.cloudflare.com/ips/" rel="noopener noreferrer"&gt;Cloudflare's IP Range page&lt;/a&gt; and update the trusted proxies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Concrete CMS: Cloudflare Proxy add-on
&lt;/h3&gt;

&lt;p&gt;The above trusted proxy way is a bit troublesome since you may need to check periodically. (Although Cloudflare seems to update IP range once every other year or less frequent.)&lt;/p&gt;

&lt;p&gt;Good news is that Cloudflare offers simple text pages of IP ranges. ( &lt;a href="https://www.cloudflare.com/ips-v4" rel="noopener noreferrer"&gt;IPv4&lt;/a&gt; &amp;amp; &lt;a href="https://www.cloudflare.com/ips-v6" rel="noopener noreferrer"&gt;IPv6&lt;/a&gt; )&lt;/p&gt;

&lt;p&gt;Then Concrete CMS has an add-on to update the IP range via those page, called Cloudflare Proxy add-on.&lt;/p&gt;

&lt;p&gt;It is CLI based add-on.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visit the github page

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/concretecms/cloudflare_proxy" rel="noopener noreferrer"&gt;https://github.com/concretecms/cloudflare_proxy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Download the zip file&lt;/li&gt;

&lt;li&gt;Rename the folder as &lt;code&gt;cloudflare_proxy&lt;/code&gt;
&lt;/li&gt;

&lt;li&gt;Run &lt;code&gt;composer install&lt;/code&gt; in the cloudflare_proxy&lt;/li&gt;

&lt;li&gt;Upload or deploy the package folder to Concrete CMS's packages folder&lt;/li&gt;

&lt;li&gt;Install the package via dashboard or CLI&lt;/li&gt;

&lt;li&gt;Set-up cron to run the following command periodically.&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to update the list
&lt;/h3&gt;

&lt;p&gt;The command to run is&lt;/p&gt;

&lt;p&gt;Concrete CMS v9&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[path/to/]concrete/bin/concrete cf:ip:update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Concrete CMS v8&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[path/to/]concrete/bin/concrete5 cf:ip:update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the package fetch the current IP range and update it.&lt;/p&gt;

&lt;p&gt;If you would like to see the current IP list&lt;/p&gt;

&lt;h3&gt;
  
  
  Find out the list
&lt;/h3&gt;

&lt;p&gt;Concrete CMS v9&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[path/to/]concrete/bin/concrete cf:ip:list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Concrete CMS v8&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[path/to/]concrete/bin/concrete5 cf:ip:list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Cron sample
&lt;/h3&gt;

&lt;p&gt;The following is the crontab sample. It is to run at 1am everyday. It is different if you setup at &lt;code&gt;/etc/crontab&lt;/code&gt; or systemd timer.&lt;/p&gt;

&lt;p&gt;You may need to set php path in cron.&lt;/p&gt;

&lt;p&gt;Concrete CMS V9 and later&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0  1  *  *  * (user) [path/to/]concrete/bin/concrete cf:ip:update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Concrete CMS V8&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0  1  *  *  * (user) [path/to/]concrete/bin/concrete5 cf:ip:update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anyway, this should solve the troublesomeness.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you cannot figure out Cloudflare proxy add-on, juat set-it up at trusted proxy page via dashboard.&lt;/p&gt;

&lt;p&gt;Cloudflare doesn't update the IP often, anywa.&lt;/p&gt;

&lt;p&gt;If your Concrete CMS doesn't accept public user login, you just need to update when the user starts to complain that they started to get logged out. That's when you need to check Cloudflare IP page and update the trusted proxy IP. :p&lt;/p&gt;

&lt;p&gt;By the way, this also applies to Concrete CMS environment with CloudFront and/or ELB. You will set-up IP range of those.&lt;/p&gt;

</description>
      <category>concretecms</category>
      <category>cloudflare</category>
      <category>symfony</category>
      <category>concrete5</category>
    </item>
    <item>
      <title>How to handle yarn's parse error</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Wed, 12 Oct 2022 02:45:22 +0000</pubDate>
      <link>https://dev.to/katzueno/how-to-handle-yarns-parse-error-3k3a</link>
      <guid>https://dev.to/katzueno/how-to-handle-yarns-parse-error-3k3a</guid>
      <description>&lt;p&gt;I've been struggling the unknown parse error while building &lt;a href="https://storybook.js.org/" rel="noopener noreferrer"&gt;storybook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I've been puzzled why it keeps happening.&lt;/p&gt;

&lt;p&gt;It turned out that cache may have been corrupted and resulted with the error.&lt;/p&gt;

&lt;p&gt;You could simply delete npm cache and &lt;code&gt;node_modules&lt;/code&gt; directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error sample
&lt;/h2&gt;

&lt;p&gt;I was experiencing the following error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ssh@example.com]$ NODE_OPTIONS=--max_old_space_size=4096 yarn build-storybook:coding
yarn run v1.22.19
$ BASE_PATH=/storybook build-storybook -o dist/storybook
info @storybook/vue3 v6.5.10
info 
info =&amp;gt; Cleaning outputDir: /var/www/html/dist/storybook
info =&amp;gt; Loading presets
info =&amp;gt; Compiling manager..
ERR! =&amp;gt; Failed to build the manager
ERR! Cannot parse records: Unexpected end of JSON input while parsing near ''
ERR! TypeError: previewBuilder.bail is not a function
ERR!     at /var/www/html/node_modules/@storybook/core-server/dist/cjs/build-static.js:219:26
ERR!     at processTicksAndRejections (node:internal/process/task_queues:96:5)
ERR!     at async Promise.all (index 0)
ERR!     at async buildStaticStandalone (/var/www/html/node_modules/@storybook/core-server/dist/cjs/build-static.js:218:28)
ERR!     at async buildStatic (/var/www/html/node_modules/@storybook/core-server/dist/cjs/build-static.js:254:5)
ERR!  TypeError: previewBuilder.bail is not a function
ERR!     at /var/www/html/node_modules/@storybook/core-server/dist/cjs/build-static.js:219:26
ERR!     at processTicksAndRejections (node:internal/process/task_queues:96:5)
ERR!     at async Promise.all (index 0)
ERR!     at async buildStaticStandalone (/var/www/html/node_modules/@storybook/core-server/dist/cjs/build-static.js:218:28)
ERR!     at async buildStatic (/var/www/html/node_modules/@storybook/core-server/dist/cjs/build-static.js:254:5)
info =&amp;gt; Loading presets
error Command failed with exit code 1.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, the main error says&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERR! Cannot parse records: Unexpected end of JSON input while parsing near ''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 1: Try to delete npm cache
&lt;/h2&gt;

&lt;p&gt;Simply, let's try to run npm cache clear command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm cache clean –force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 2: Try to delete &lt;code&gt;node_modules/.cache&lt;/code&gt; directory
&lt;/h2&gt;

&lt;p&gt;If STEP 1 doesn't work, just try to delete the &lt;code&gt;.cache&lt;/code&gt; directory manually.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 3: Try to delete &lt;code&gt;node_modules&lt;/code&gt; directory
&lt;/h2&gt;

&lt;p&gt;Perhaps, there may be some conflict, so maybe you want to delete the entire &lt;code&gt;node_modules&lt;/code&gt; directory and rebuild.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 4: Check installed node, npm, yarn versions
&lt;/h2&gt;

&lt;p&gt;If you have multiple environments such as local, co-workers, and servers, and some environment worked but not the others, you may need to check the installed version of each environment.&lt;/p&gt;

&lt;p&gt;After matching those, start over from STEP1.&lt;/p&gt;

&lt;p&gt;Good luck.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.danroo.com/web/post-666/" rel="noopener noreferrer"&gt;https://www.danroo.com/web/post-666/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/storybookjs/storybook/issues/4034#issuecomment-780694848" rel="noopener noreferrer"&gt;https://github.com/storybookjs/storybook/issues/4034#issuecomment-780694848&lt;/a&gt;&lt;/p&gt;

</description>
      <category>yarn</category>
      <category>debug</category>
    </item>
    <item>
      <title>Nginx Simple Cheatsheet</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Wed, 26 Jan 2022 07:00:18 +0000</pubDate>
      <link>https://dev.to/katzueno/nginx-cheatsheet-4e42</link>
      <guid>https://dev.to/katzueno/nginx-cheatsheet-4e42</guid>
      <description>&lt;p&gt;This is my own Nginx cheatsheet. Checked with CentOS6, 7 and Amazon Linux and Amazon Linux 2&lt;/p&gt;

&lt;p&gt;All commands are under assumption that you are root, or use with &lt;code&gt;sudo&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Start
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stop
&lt;/h2&gt;

&lt;p&gt;CentOS 6 &amp;amp; Amazon Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nginx -s stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CentOS 7 &amp;amp; Amazon Linux 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl stop nginx
service nginx stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Restart
&lt;/h2&gt;

&lt;p&gt;entOS 6 &amp;amp; Amazon Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/etc/init.d/nginx restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CentOS 7 &amp;amp; Amazon Linux 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl restart nginx
service nginx restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Register startup
&lt;/h2&gt;

&lt;p&gt;CentOS 7 &amp;amp; Amazon Linux 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl enable nginx
systemctl disable nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reload config
&lt;/h2&gt;

&lt;p&gt;CentOS6 &amp;amp; Amazon Linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nginx reload
service nginx reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CentOS7 &amp;amp; Amazon Linux 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl reload nginx
service nginx reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check config
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nginx -t
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  General location of config
&lt;/h2&gt;

&lt;p&gt;Main&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /etc/nginx/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Virtual hosts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /etc/nginx/conf.d/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>nginx</category>
      <category>centos</category>
      <category>amazonlinux</category>
    </item>
    <item>
      <title>How to disable web fonts</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Wed, 26 Jan 2022 06:03:42 +0000</pubDate>
      <link>https://dev.to/katzueno/how-to-disable-web-fonts-2njj</link>
      <guid>https://dev.to/katzueno/how-to-disable-web-fonts-2njj</guid>
      <description>&lt;p&gt;This is the quick tip to be able to disable all CSS fonts&lt;/p&gt;

&lt;p&gt;We had a website which contains a lot of line separator (U+2028) character.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Make a bookmark on bookmark bar (just add anything as dummy)

&lt;ul&gt;
&lt;li&gt;"Bookmark bar" is the bar that you see the list of icon right below the address bar&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Edit the newly created bookmark, replace the URL to the following javascript code &amp;amp; rename it to whatever you like&lt;/li&gt;
&lt;li&gt;Done&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Javascript
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;javascript:Array.prototype.forEach.call(document.getElementsByTagName("*"),
function(e){e.style.fontFamily ="Source Sans Pro"})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to use
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Visit a page&lt;/li&gt;
&lt;li&gt;Click the bookmark icon that you just made&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why need this
&lt;/h2&gt;

&lt;p&gt;If you are using modern web font, they treat line separator as space.&lt;/p&gt;

&lt;p&gt;However, we had a client whose customers maybe using older computer. They were viewing the page without web font. Then line separator are showing up as corrupted square letters.&lt;/p&gt;

&lt;p&gt;We need to remove those characters, but it's hard to locate unless we disable web font.&lt;/p&gt;

&lt;p&gt;Thank you user10089632 of StackExchange!&lt;br&gt;
&lt;a href="https://superuser.com/questions/1209191/force-chrome-to-use-my-preferred-font-over-the-authors?newreg=20d74beb36514f629acc2f7222727626" rel="noopener noreferrer"&gt;https://superuser.com/questions/1209191/force-chrome-to-use-my-preferred-font-over-the-authors?newreg=20d74beb36514f629acc2f7222727626&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>chrome</category>
      <category>font</category>
    </item>
    <item>
      <title>Very Simple PHP Redirect</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Sun, 17 Oct 2021 11:53:21 +0000</pubDate>
      <link>https://dev.to/katzueno/very-simple-php-redirect-5cf6</link>
      <guid>https://dev.to/katzueno/very-simple-php-redirect-5cf6</guid>
      <description>&lt;p&gt;If you've moved (are planning to move) to new domain &amp;amp; you don't want to simply redirect to new domain.&lt;br&gt;
You want to tell your site visitors that your domain has changed.&lt;/p&gt;

&lt;p&gt;This simple PHP script shows very simple message that domain has changed for set amount of seconds, then redirected to the new domain.&lt;/p&gt;

&lt;p&gt;It is also render 301 status code. So Google will know your page was moved, too.&lt;/p&gt;

&lt;p&gt;It will fetch the current request URL, and redirect to the new domain with exact same URI.&lt;/p&gt;

&lt;p&gt;By the way, it has Japanese text, too :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/katzueno/simple-php-redirect" rel="noopener noreferrer"&gt;https://github.com/katzueno/simple-php-redirect&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This post was copied from Readme. If there is a newer version and newer description at GitHub readme, refer to GitHub's readme.&lt;/p&gt;
&lt;h2&gt;
  
  
  Requirement
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For Apache server, mod_rewrite module should be enabled, and allowing to use .htaccess

&lt;ul&gt;
&lt;li&gt;You could set it in Apache config.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;For Nginx server

&lt;ul&gt;
&lt;li&gt;PHP-FPM&lt;/li&gt;
&lt;li&gt;Ability to set nginx config&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  How to install
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Change the config values such as new domain to index.php to your desired state.&lt;/li&gt;
&lt;li&gt;Place (or upload) index.php script to your old domain's webroot and clear all other files&lt;/li&gt;
&lt;li&gt;Edit your apache config, .htaccess or Nginx config so that all request will go through this index.php&lt;/li&gt;
&lt;li&gt;Enjoy the rest&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Where to set
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;$newDomain&lt;/code&gt;: Enter the new domain name. Starts with &lt;code&gt;https://&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$siteNameEn&lt;/code&gt;: Site name in English.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$siteNameJa&lt;/code&gt;: Site name in Japanese.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$sec&lt;/code&gt;: Seconds to wait and redirect&lt;/p&gt;
&lt;h2&gt;
  
  
  Apache's .htaccess example
&lt;/h2&gt;

&lt;p&gt;Create .htaccess file (if your server is allowing it), and enter the following.&lt;br&gt;
If you want to place it under some directory, make sure to change &lt;code&gt;RewriteBase&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;IfModule mod_rewrite.c&amp;gt;
RewriteEngine On
RewriteBase / # if it's lives under subdirectory, add the directory accordingly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
&amp;lt;/IfModule&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Nginx config example
&lt;/h2&gt;

&lt;p&gt;I assume you know about Nginx server and its config.&lt;br&gt;
Add the following config in your nginx config.&lt;br&gt;
I assume you've set &lt;code&gt;~ \.php($|/)&lt;/code&gt; location to send it to php-fpm.&lt;br&gt;
Change location to sub-directory if you want just to place underneath, and &lt;code&gt;absolute_redirect&lt;/code&gt; must be turned off.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;location / {
    index index.php index.html index.htm;
    if (!-e $request_filename) {
        rewrite ^ /index.php last;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enjoy.&lt;/p&gt;

</description>
      <category>php</category>
      <category>devops</category>
    </item>
    <item>
      <title>How to delete .DS_Store, or some system files recursively</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Mon, 11 Oct 2021 03:50:21 +0000</pubDate>
      <link>https://dev.to/katzueno/how-to-delete-dsstore-or-some-system-files-recursively-1b5p</link>
      <guid>https://dev.to/katzueno/how-to-delete-dsstore-or-some-system-files-recursively-1b5p</guid>
      <description>&lt;p&gt;When you zip files in Mac OS or Windows, it sometime include system files that you don't see when you were working.&lt;/p&gt;

&lt;p&gt;When you unzip the files, you see them.&lt;/p&gt;

&lt;p&gt;You go nuts!&lt;/p&gt;

&lt;p&gt;Well, you probably set .gitignore to ignore those system files. It will probably be harmless.&lt;/p&gt;

&lt;p&gt;However, you just don't want to leave those junk.&lt;/p&gt;

&lt;p&gt;You will use &lt;code&gt;find&lt;/code&gt; command to delete them&lt;/p&gt;

&lt;p&gt;Originally posted on my blog&lt;br&gt;
&lt;a href="https://en.katzueno.com/2021/10/11/how-to-delete-ds_store-php-files-recursively/" rel="noopener noreferrer"&gt;https://en.katzueno.com/2021/10/11/how-to-delete-ds_store-php-files-recursively/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Delete &lt;code&gt;.DS_Store&lt;/code&gt; or &lt;code&gt;._*&lt;/code&gt; files
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd [Path/To/UnarivedFolder]
find . -name ".DS_Store" -delete; find . -name "._*" -delete
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;find&lt;/code&gt; command is very useful to delete some junk files systematically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delete .bak files
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd [Path/To/UnarivedFolder]
find . -name "*.bak" -delete
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  TIPS: Configure your Mac not to save .DS_Store files
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Start terminal
# Set default not to store .DS_Store file
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
# Force restart Finder
killall Finder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>unix</category>
      <category>shell</category>
      <category>find</category>
    </item>
    <item>
      <title>How to set proxy in PHP-FPM</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Fri, 08 Oct 2021 03:06:01 +0000</pubDate>
      <link>https://dev.to/katzueno/how-to-set-proxy-in-php-fpm-3dj6</link>
      <guid>https://dev.to/katzueno/how-to-set-proxy-in-php-fpm-3dj6</guid>
      <description>&lt;p&gt;One of our clients server lives inside of tight security VPC.&lt;/p&gt;

&lt;p&gt;Therefore, all of our EC2 web server must use HTTP_PROXY, HTTPS_PROXY.&lt;/p&gt;

&lt;p&gt;When I try to use Concrete CMS (formally concrete5) to fetch the latest language files from remote server, I've got the curl timeout error and couldn't update the language.&lt;/p&gt;

&lt;p&gt;So I need to set the proxy for PHP-FPM.&lt;/p&gt;

&lt;p&gt;If you use Apache's PHP module or CLI, PHP will use server's environment settings.&lt;/p&gt;

&lt;p&gt;However, for php-fpm you must also configure in php.d/&lt;a href="http://www.conf" rel="noopener noreferrer"&gt;www.conf&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Checked &amp;amp; tested with Amazon Linux 2 with PHP7.4 installed via amazon-linux-extra.&lt;/p&gt;

&lt;h2&gt;
  
  
  Condition
&lt;/h2&gt;

&lt;p&gt;For example, you have your proxy set for both http and https.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://10.0.0.1:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 1. Set environment globally
&lt;/h2&gt;

&lt;p&gt;Although php-fpm doesn't reference to server's global setting, you may still want to use PHP-CLI to run via SSH. So let's set it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo vi /etc/environment
export http_proxy="http://10.0.0.1:8080"
export https_proxy="http://10.0.0.1:8080"
export HTTP_PROXY="http://10.0.0.1:8080"
export HTTPS_PROXY="http://10.0.0.1:8080"
export no_proxy="127.0.0.1,localhost"
export NO_PROXY=$no_proxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some middleware may use lowercase or capitol variable, so let's set both.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 2. Set php-fpm environment
&lt;/h2&gt;

&lt;p&gt;Set it to your php-fpm config.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo vi /etc/php-fpm.d/www.conf
# Add the following two lines anywhere
env[HTTP_PROXY] = 10.0.0.1:8080
env[HTTPS_PROXY] = 10.0.0.1:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 3. Set php-fpm environment
&lt;/h2&gt;

&lt;p&gt;Then, reload php-fpm service&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service php-fpm reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 4. Test run
&lt;/h2&gt;

&lt;p&gt;I've prepared the sample PHP script.&lt;br&gt;
Change &lt;code&gt;$proxy&lt;/code&gt; variable to your proxy.&lt;br&gt;
And save it to your webroot.&lt;/p&gt;

&lt;p&gt;Get my sample PHP script here.&lt;br&gt;
&lt;a href="https://en.katzueno.com/2021/10/08/how-to-set-proxy-in-php-fpm/" rel="noopener noreferrer"&gt;https://en.katzueno.com/2021/10/08/how-to-set-proxy-in-php-fpm/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>phpfpm</category>
      <category>nginx</category>
      <category>proxy</category>
      <category>php</category>
    </item>
    <item>
      <title>How to filter S3 bucket to download millions of log files</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Wed, 06 Oct 2021 03:41:02 +0000</pubDate>
      <link>https://dev.to/katzueno/how-to-filter-s3-bucket-to-download-millions-of-log-files-jo0</link>
      <guid>https://dev.to/katzueno/how-to-filter-s3-bucket-to-download-millions-of-log-files-jo0</guid>
      <description>&lt;p&gt;I started to have more occasions to download log files which is stored on S3 bucket.&lt;/p&gt;

&lt;p&gt;I started to have more occasions to download log files which is stored on S3 bucket.&lt;/p&gt;

&lt;p&gt;Whether they are Nginx, or Apache log being aggregated from auto scaling group, OR CloudFront access log.&lt;/p&gt;

&lt;p&gt;Those files on S3 bucket are enormously huge number. It is impossible to browse through the management console.&lt;/p&gt;

&lt;p&gt;It's impossible to download all logs locally.&lt;/p&gt;

&lt;p&gt;Here is how I usually do it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try to narrow down the date and time
&lt;/h2&gt;

&lt;p&gt;Make sure that you minimize the date and time range of the log that you want to acquire.&lt;/p&gt;

&lt;p&gt;I have a good habit of trying to log what I've done with timestamp.&lt;/p&gt;

&lt;p&gt;For example, when you deploy some new code, you try to create a slack thread, and type comment at the each step of deployment. You don't need to be too precise. Slack has the time stamp automatically.&lt;/p&gt;

&lt;p&gt;You could use Google Spreadsheet or Notion to use they checkbox feature. It will record when you check the checkbox.&lt;/p&gt;

&lt;p&gt;We use the service called Backlog which is Japanese project management SaaS service which has the checkbox feature when we deploy the code to production or upgrade a CMS system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find a block of logs chronologically through S3 Management Console
&lt;/h2&gt;

&lt;p&gt;Log-in to your AWS Management Console and go into S3 page.&lt;/p&gt;

&lt;p&gt;Browse the S3 bucket.&lt;/p&gt;

&lt;p&gt;Try to find proper prefix.&lt;/p&gt;

&lt;p&gt;For example, the CloudFront log format is like the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[CloudFront ID].YYYY-MM-DD-##.[some ID].gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For CloudFront log, you should be able to get your CloudFront ID,  you could guess the date.&lt;/p&gt;

&lt;p&gt;However, it could still be large amount of log file for 1 entire day of access.&lt;/p&gt;

&lt;p&gt;You still want to find out which portion of &lt;code&gt;##&lt;/code&gt; (numbers) logs files you want to get.&lt;/p&gt;

&lt;p&gt;So you filter the S3 bucket by &lt;code&gt;[CloudFront ID].YYYY-MM-DD-&lt;/code&gt;, then from the result, you try to sort by time from the column.&lt;/p&gt;

&lt;p&gt;Then find out which &lt;code&gt;##&lt;/code&gt; of files you want to get.&lt;/p&gt;

&lt;p&gt;Let's say you now know you want all of &lt;code&gt;E0EEEEEEEEEEE0-10-05-05*&lt;/code&gt; log files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get IAM Access Key and Secret to access S3 bucket Log
&lt;/h2&gt;

&lt;p&gt;Issue IAM Access Key, or log-in to EC2 instances which has the IAM Role to access S3 bucket.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run &lt;code&gt;aws s3 cp&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Run the aws s3 cp command to fetch the log files to your local or remote EC2 instance.&lt;/p&gt;

&lt;p&gt;For aws s3 commands, you can only filter by path. You cannot use wildcard (*) in the &lt;code&gt;s3://&lt;/code&gt; URL. You neext to use &lt;code&gt;--exclude&lt;/code&gt; &lt;code&gt;--include&lt;/code&gt; options.&lt;/p&gt;

&lt;p&gt;First, you exclude all files, then you specify what pattern of object names you want to include.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3 cp s3://S3-Bucket-Name/Folder-if-any/ ./ --recursive --exclude "*" --include "[CloudFront ID].YYYY-MM-DD-05*" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From previous example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3 cp s3://S3-Bucket-Name/Folder-if-any/ ./ --recursive --exclude "*" --include "E0EEEEEEEEEEE0-10-05-05*" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, you should be able to download all of your desired log files.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>s3</category>
      <category>log</category>
    </item>
    <item>
      <title>Search UTF8mb4 text of MySQL in PHP</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Wed, 09 Jun 2021 05:06:23 +0000</pubDate>
      <link>https://dev.to/katzueno/search-utf8mb4-text-of-mysql-in-php-2io1</link>
      <guid>https://dev.to/katzueno/search-utf8mb4-text-of-mysql-in-php-2io1</guid>
      <description>&lt;p&gt;MySQL has utf8 &amp;amp; utf8mb4 charcter collation.&lt;/p&gt;

&lt;p&gt;Although UTF8 is one encoding type, MySQL's (MariaDB) utf8 only allows to store upto 3-byte characters.&lt;/p&gt;

&lt;p&gt;Therefore, some new emojis and Japanese and Chinese characters are not able to store it unless you use utf8mb4.&lt;/p&gt;

&lt;p&gt;My CTO at concrete5 Japan, Inc and I came up with the solution to export mysqldump and search the txt in PHP.&lt;/p&gt;

&lt;p&gt;It was difficult to search the text only by using SQL.&lt;/p&gt;

&lt;h1&gt;
  
  
  Export MySQL Database with MySQLDump
&lt;/h1&gt;

&lt;p&gt;We used &lt;code&gt;--skip-extended-insert&lt;/code&gt; option so that each record has one line&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysqldump -h {$host} -u {$db_username} --password="{$db_password}" --default-character-set=utf8mb4 --single-transaction --skip-extended-insert {$db_name} {$db_tables} &amp;gt; {$SQL_FILENAME}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need forgot to change your DB collation to utf8mb4, and need to re-work on the existing data, you may want to mysqldump using &lt;code&gt;--replace --no-create-info&lt;/code&gt; options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysqldump -h {$host} -u {$db_username} --password="{$db_password}" --default-character-set=utf8mb4 --single-transaction --replace --no-create-info --skip-extended-insert {$db_name} {$db_tables} &amp;gt; {$SQL_FILENAME}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Search UTF8MB4 characters in PHP
&lt;/h1&gt;

&lt;p&gt;Save this as &lt;code&gt;textsearch.php&lt;/code&gt; and run it on your local or server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
$searchRegex = '/[\x{10000}-\x{10FFFF}]/iu';
$matches = [];

$handle = fopen("SQL_FILENAME", "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle);
        if (preg_match($searchRegex, $buffer)) {
            $matches[] = $buffer;
        }
        /*
        // If you want to print out which characters are really UTF8MB4, use this pref_match_all instead.
        if (preg_match_all($searchRegex, $buffer, $matchesChar)) {
            echo "Character(s): " . implode(',', $matchesChar[0]) . "\n";
            print_r($buffer);
        }
        */
    }
    fclose($handle);
} else {
    echo "nope! cant open it\n";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ php textsearch.php &amp;gt; {$result.sql}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will filter you the utf8mb4 SQL.&lt;/p&gt;

&lt;p&gt;Tested with PHP 7.4.20 with mbstring extension.&lt;/p&gt;

</description>
      <category>php</category>
      <category>mysql</category>
      <category>multibyte</category>
      <category>emoji</category>
    </item>
    <item>
      <title>How To Check mysqldump character-set</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Wed, 09 Jun 2021 04:52:52 +0000</pubDate>
      <link>https://dev.to/katzueno/how-to-check-mysqldump-character-set-19ae</link>
      <guid>https://dev.to/katzueno/how-to-check-mysqldump-character-set-19ae</guid>
      <description>&lt;p&gt;Learning from mistake.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mysqldump&lt;/code&gt; doesn't respect database's collation, but mysql client.&lt;/p&gt;

&lt;p&gt;Check your mysqldump default character set by typing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysqldump --help | grep default-character-set
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You always want to add &lt;code&gt;--default-character-set&lt;/code&gt; option&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysqldump -h {$host} -u {$db_username} --password="{$db_password}" --default-character-set=utf8mb4 --single-transaction {$db_name} &amp;gt; {$SQL_file_name}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--single-transition&lt;/code&gt; option is my preferences for the database which mainly uses InnoDB&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>mariadb</category>
      <category>mysqldump</category>
      <category>utf8</category>
    </item>
    <item>
      <title>Auto git deploy php script</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Thu, 08 Aug 2019 01:33:16 +0000</pubDate>
      <link>https://dev.to/katzueno/auto-git-deploy-php-script-2djc</link>
      <guid>https://dev.to/katzueno/auto-git-deploy-php-script-2djc</guid>
      <description>&lt;p&gt;I've made a sample PHP script to auto deploy git using webhook feature which GitHub, Bitbucket and other servives provide.&lt;/p&gt;

&lt;p&gt;Please read the comments inside of deployments.php for the option and how to set-it up.&lt;/p&gt;

&lt;p&gt;This deployment script requires certain level of git and server knowledge.&lt;/p&gt;

&lt;p&gt;This script is intended for single server use.&lt;/p&gt;

&lt;p&gt;Please check it out and test drive, and send me issue or PR to improve the script.&lt;/p&gt;

&lt;h1&gt;
  
  
  GitHub Repo
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://github.com/katzueno/git-Webhooks-Auto-Deploy-PHP-Script" rel="noopener noreferrer"&gt;https://github.com/katzueno/git-Webhooks-Auto-Deploy-PHP-Script&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How to set it up
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Set up git
&lt;/h2&gt;

&lt;p&gt;Prepare your git repo&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Set-up server
&lt;/h2&gt;

&lt;p&gt;It is highly recommended to prepare two different domain or subdomains within the same server.&lt;br&gt;
Set-up where you set git deployment script and public area where your actual git deployment.&lt;/p&gt;

&lt;p&gt;You must make sure git deploy script is protected with basic auth and SSL.&lt;/p&gt;

&lt;p&gt;Obtain all necessary information such as server paths.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Git clone to the server
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Regular way
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Login via SSH&lt;/li&gt;
&lt;li&gt;cd to the path&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git clone [GIT PATH]&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Make sure you git clone as the same user as web server. If you're using shared host, you may not have to worry about.&lt;/li&gt;
&lt;li&gt;e.g.,) &lt;code&gt;sudo -u (nginx|apache) git clong [GIT PATH]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Make sure that /.git directory is NOT publicly visible to the web.

&lt;ul&gt;
&lt;li&gt;Apache: add this line to .htaccess: &lt;code&gt;RedirectMatch 404 /\.git&lt;/code&gt; (mod_rewrite is required)&lt;/li&gt;
&lt;li&gt;Nginx: add this line to your Nginx config &lt;code&gt;location ~ /\.git { return 404; }&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Separate Git Directory and Work Directory (more secure)
&lt;/h3&gt;

&lt;p&gt;Is is very secure way of place git repository outside of publicly visible www root.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Login via SSH&lt;/li&gt;
&lt;li&gt;cd to the path&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git clone --mirror [GIT PATH]&lt;/code&gt; to the directory&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GIT_WORK_TREE=[www_path] git checkout -f [your desired branch]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  3. Set your config &amp;amp; upload the file
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Set all necessary config setting inside of deployement.php

&lt;ul&gt;
&lt;li&gt;Read carefully from line 1-45. You won't need to change below &lt;code&gt;Main Section&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Upload your &lt;code&gt;deployment.php&lt;/code&gt; to where you stage your script

&lt;ul&gt;
&lt;li&gt;Make sure to upload in secure area.&lt;/li&gt;
&lt;li&gt;You may rename filename.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  4. Set-up a webhook and test drive
&lt;/h2&gt;

&lt;p&gt;Your web hook URL will be like this.&lt;br&gt;
Set it up as webhook of GitHub, Bitbucket, Gitlab or whatever other git services which supports webhook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://[Basic Auth ID]:[Basic Auth Pass]@example.com/deployments.php?key=YourSecretKeyHere
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and enjoy the rest of auto deployment.&lt;/p&gt;

</description>
      <category>git</category>
      <category>deployment</category>
      <category>webhook</category>
      <category>github</category>
    </item>
    <item>
      <title>Setting up Let's Encrypt on CentOS7 (Amazon Linux 2)</title>
      <dc:creator>Katz Ueno</dc:creator>
      <pubDate>Thu, 08 Aug 2019 01:17:28 +0000</pubDate>
      <link>https://dev.to/katzueno/setting-up-let-s-encrypt-on-amazon-linux-2-57l7</link>
      <guid>https://dev.to/katzueno/setting-up-let-s-encrypt-on-amazon-linux-2-57l7</guid>
      <description>&lt;p&gt;This notes explains how to install Let's Encrypt onto Amazon Linux 2 (Running a &lt;br&gt;
PHP+MySQL CMS, concrete5).&lt;/p&gt;

&lt;p&gt;I've tested on Amazon Linux 2. But it will probably works on any CentOS7 and RHLE7.&lt;/p&gt;
&lt;h1&gt;
  
  
  Step 0: Initial Set-up
&lt;/h1&gt;

&lt;p&gt;Run my concrete5 Ansible script to set-up basic web server.&lt;br&gt;
&lt;a href="https://github.com/concrete5cojp/ansible-c5-ma" rel="noopener noreferrer"&gt;https://github.com/concrete5cojp/ansible-c5-ma&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This script will install all necessary repo and middleware to run a PHP web application.&lt;/p&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;p&gt;Install epel repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, make sure you finish configuring 80 port config and availabl already.&lt;/p&gt;

&lt;h1&gt;
  
  
  Using auto configuration
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Step 1: Install Certbot
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo yum install certbot python2-certbot-nginx # Nginx server
$ sudo yum install certbot python2-certbot-apache # Apache server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Install Let's Encrypt Certificatte
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Set-up cron to auto-renew
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo vi /etc/crontab
# Let's Encrypt Renewal - Nginx
39 11,23  *  *  * root /usr/bin/certbot renew --no-self-upgrade --renew-hook "systemctl restart nginx"
# Let's Encrypt Renewal - Apache
39 11,23  *  *  * root /usr/bin/certbot renew --no-self-upgrade --renew-hook "service httpd restart"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Manual Method
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Issue an certificate for the domain
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo certbot certonly \
     --manual \
     --manual-public-ip-logging-ok \
     -d EXAMPLE.com \
     -d *.EXAMPLE.com \
     -m nospam@EXAMPLE.com \
     --agree-tos \
     --debug
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get the full paths of key&lt;/p&gt;

&lt;h2&gt;
  
  
  Set web server config
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Nginx Config
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    ssl_certificate         /etc/letsencrypt/live/EXAMPLE.com/fullchain.pem;
    ssl_certificate_key     /etc/letsencrypt/live/EXAMPLE.com/privkey.pem;
    include                 /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam             /etc/letsencrypt/ssl-dhparams.pem;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Apache Config
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SSLCertificateFile /etc/letsencrypt/live/DOMAIN/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/DOMAIN/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/DOMAIN/chain.pem
SSLCACertificateFile /etc/letsencrypt/live/DOMAIN/fullchain.pem

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Cron setting
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo vi /etc/crontab
# Let's Encrypt Renewal
39 11,23  *  *  * root /usr/bin/certbot renew --no-self-upgrade --renew-hook "service nginx reload -s"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  When you failed
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Clear all Let's Encrypt Setting
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo rm -R /opt/eff.org/certbot

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Make sure to set SSL on default-server (For Dynamic site with cache)
&lt;/h2&gt;

&lt;p&gt;Even if you only need SSL access to additional virtual host server, you may want to set SSL settings on your default-server, so that when people tried to access your server via IP, it will return blank request.&lt;/p&gt;

&lt;p&gt;It's important tactics to prevent cache poisoning if you use CMS such as WordPress or Concrete CMS.&lt;/p&gt;

&lt;p&gt;If you've got the following error in Nginx error log and keep failing to access SSL, you didn't set proper 443 config on your Nginx's default-server config.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;no "ssl_certificate" is defined in server listening on SSL port while SSL handshaking, client: ***.***.***.***, server: 0.0.0.0:443
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen       80 default_server;
    listen       [::]:80;
    listen       443 ssl http2 default_server;
    listen       [::]:443 ssl http2;

    server_name  EXAMPLE.com;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

    charset      utf-8;

    access_log   /var/log/nginx/dummy_access.log main;
    error_log    /var/log/nginx/dummy_error.log warn;

    root         /var/www/html;

    ssl_certificate         /etc/letsencrypt/live/EXAMPLE.com/fullchain.pem;
    ssl_certificate_key     /etc/letsencrypt/live/EXAMPLE.com/privkey.pem;
    include                 /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam             /etc/letsencrypt/ssl-dhparams.pem;


    location / {
        index  index.html;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How to delete unused and/or old certificates
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Show which certificates are installed &amp;amp; get the certificate names to delete
$ sudo certbot certificates

# Delete the certificate
$ sudo certbot delete --cert-name example.com-0001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Reference
&lt;/h1&gt;

&lt;p&gt;This one is good article.&lt;br&gt;
&lt;a href="http://nopipi.hatenablog.com/entry/2019/01/08/013654" rel="noopener noreferrer"&gt;http://nopipi.hatenablog.com/entry/2019/01/08/013654&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://higherhope.net/?p=2710" rel="noopener noreferrer"&gt;https://higherhope.net/?p=2710&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://qiita.com/HeRo/items/f9eb8d8a08d4d5b63ee9" rel="noopener noreferrer"&gt;https://qiita.com/HeRo/items/f9eb8d8a08d4d5b63ee9&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://qiita.com/MysteriousMonky/items/f26316447c1ff390ce21" rel="noopener noreferrer"&gt;https://qiita.com/MysteriousMonky/items/f26316447c1ff390ce21&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://worklog.be/archives/3352" rel="noopener noreferrer"&gt;https://worklog.be/archives/3352&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
